Hi there!
Attached is a patch that contains the changes to SDL_net to get the sources
compiling with a C++ compiler(g++).
It mostly gets around syntactic differences between C and C++ via some #ifdefs.
Further some casts are removed that are dubious to a C++ compiler(e.g. in
SDLnetTCP.c) in favor of a declaration of sock_len with the proper type from
the beginning. But I’m not sure that my #ifdef logic captures the behaviour of
the accept() system call on all systems supported by SDL_net.
Happy Sunday, Flo.
-------------- next part --------------
Index: SDLnetTCP.c===================================================================
— SDLnetTCP.c (revision 5119)
+++ SDLnetTCP.c (working copy)
@@ -817,8 +817,16 @@
{
TCPsocket sock;
struct sockaddr_in sock_addr;
- int sock_alen;
+#ifdef USE_GUSI_SOCKETS
-
unsigned int sock_alen;
+#endif
+#ifdef WIN32 -
int sock_alen;
+#else -
socklen_t sock_alen; /default to some POSIX behaviour/
+#endif -
/* Only server sockets can accept */
if ( ! server->sflag ) {
SDLNet_SetError(“Only server sockets can accept()”);
@@ -835,12 +843,7 @@/* Accept a new TCP connection on a server socket */
sock_alen = sizeof(sock_addr);
- sock->channel = accept(server->channel, (struct sockaddr *)&sock_addr,
-#ifdef USE_GUSI_SOCKETS -
(unsigned int *)&sock_alen);
-#else
-
&sock_alen);
-#endif
- sock->channel = accept(server->channel, (struct sockaddr *)&sock_addr, &sock_alen);
if ( sock->channel == INVALID_SOCKET ) {
SDLNet_SetError(“accept() failed”);
goto error_return;
Index: SDLnetUDP.c
===================================================================
— SDLnetUDP.c (revision 5119)
+++ SDLnetUDP.c (working copy)
@@ -443,7 +443,11 @@
*/
int SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address)
{
- struct UDP_channel *binding;
+#ifdef __cplusplus
-
struct _UDPsocket::UDP_channel *binding;
+#else -
struct UDP_channel *binding;
+#endifif ( channel == -1 ) {
for ( channel=0; channel < SDLNET_MAX_UDPCHANNELS; ++channel ) {
@@ -509,7 +513,11 @@
int SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets)
{
int numsent, i, j;
- struct UDP_channel *binding;
+#ifdef __cplusplus
- struct _UDPsocket::UDP_channel *binding;
+#else - struct UDP_channel *binding;
+#endif
int status;
#ifndef MACOS_OPENTRANSPORT
int sock_len;
@@ -690,13 +698,24 @@
extern int SDLNet_UDP_RecvV(UDPsocket sock, UDPpacket **packets)
{
int numrecv, i, j;
- struct UDP_channel *binding;
+#ifdef __cplusplus
- struct _UDPsocket::UDP_channel *binding;
+#else - struct UDP_channel *binding;
+#endif
#ifdef MACOS_OPENTRANSPORT
TUnitData OTpacket;
OTFlags flags;
InetAddress address;
#else
- int sock_len;
+#ifdef USE_GUSI_SOCKETS
- unsigned int sock_len;
+#endif
+#ifdef WIN32 - int sock_len;
+#else - socklen_t sock_len; /default to some POSIX behaviour/
+#endif
struct sockaddr_in sock_addr;
#endif
@@ -732,12 +751,7 @@
sock_len = sizeof(sock_addr);
packet->status = recvfrom(sock->channel,
packet->data, packet->maxlen, 0,
-
(struct sockaddr *)&sock_addr,
-#ifdef USE_GUSI_SOCKETS
-
(unsigned int *)&sock_len);
-#else
-
&sock_len);
-#endif
-
(struct sockaddr *)&sock_addr, &sock_len); if ( packet->status >= 0 ) { packet->len = packet->status; packet->address.host = sock_addr.sin_addr.s_addr;
Index: SDL_net.h
— SDL_net.h (revision 5119)
+++ SDL_net.h (working copy)
@@ -269,7 +269,7 @@
typedef struct _SDLNet_SocketSet *SDLNet_SocketSet;
/* Any network socket can be safely cast to this socket type */
-typedef struct {
+typedef struct SDLNet_GenericSocket_{
int ready;
} *SDLNet_GenericSocket;