SDLNet_CheckSockets
Name
SDLNet_CheckSockets -- check all sockets in the socket set for activity.
Synopsis
#include "SDL_net.h" int SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout);
set is the socket set to check.
timeout is the maximum amount of time to wait (in milliseconds). 0 means no waiting. -1 means to wait over 49 days! (think about it)
Description
SDLNet_CheckSockets check all sockets in the socket set for activity. If a non-zero timeout is given then this function will wait for activity, or else it will wait for timeout milliseconds.
Note: "activity" also includes disconnections and other errors, which would be determined by a failed read/write attempt.
Return Value
Returns the number of sockets with activity. -1 is returned on errors, and you may not get a meaningful error message. -1 is also returned for an empty set (nothing to check).
Example
// Wait for up to 1 second for network activity
//SDLNet_SocketSet set;
int numready;
numready = SDLNet_CheckSockets(set, 1000);
if (numready == -1) {
printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
//most of the time this is a system error, where perror might help you.
perror("SDLNet_CheckSockets");
}
else if (numready) {
printf("There are %d sockets with activity!\n", numready);
// check all sockets with SDLNet_SocketReady and handle the active ones.
}
See Also
SDLNet_SocketReady, SDLNet_AddSocket, SDLNet_DelSocket, SDLNet_AllocSocketSet, SDLNet_SocketSet, UDPsocket, TCPsocket
