X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=radiant%2Fsockets.cpp;h=cf5d2dd7588a7cf3c1f44b4a9a0c7f437fd8dc3c;hp=d2a27d7e01848315d92ff3aaf407a0ac3128f850;hb=9dfae1c9b270ee369c6362903a9205b30751b95f;hpb=0a6d5683b0cfa1a0bd7ef64bada105dbe4ddd6e1 diff --git a/radiant/sockets.cpp b/radiant/sockets.cpp index d2a27d7e..cf5d2dd7 100644 --- a/radiant/sockets.cpp +++ b/radiant/sockets.cpp @@ -4,7 +4,9 @@ #if GDEF_OS_WINDOWS #include #elif GDEF_OS_POSIX + #include + const int SOCKET_ERROR = -1; #else #error "unsupported platform" @@ -14,32 +16,32 @@ const int SOCKET_ERROR = -1; #include #endif -int Net_Wait( socket_t *sock, long sec, long usec ){ +int Net_Wait(socket_t *sock, long sec, long usec) +{ // used for select() #if GDEF_OS_WINDOWS - TIMEVAL tout = { sec, usec }; + TIMEVAL tout = { sec, usec }; #endif #if GDEF_OS_POSIX - timeval tout; - tout.tv_sec = sec; - tout.tv_usec = usec; + timeval tout; + tout.tv_sec = sec; + tout.tv_usec = usec; #endif - // select() will identify if the socket needs an update - // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated - fd_set readfds; - FD_ZERO( &readfds ); - FD_SET( ( (unsigned int)sock->socket ), &readfds ); - // from select man page: - // n is the highest-numbered descriptor in any of the three sets, plus 1 - // (no use on windows) - switch ( select( sock->socket + 1, &readfds, 0, 0, &tout ) ) - { - case SOCKET_ERROR: - return -1; - case 0: - return 0; - default: - return 1; - } + // select() will identify if the socket needs an update + // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(((unsigned int) sock->socket), &readfds); + // from select man page: + // n is the highest-numbered descriptor in any of the three sets, plus 1 + // (no use on windows) + switch (select(sock->socket + 1, &readfds, 0, 0, &tout)) { + case SOCKET_ERROR: + return -1; + case 0: + return 0; + default: + return 1; + } }