3ed80a1fac
Use macros to wrap SDL_Log* functions with the "application" category.
31 lines
817 B
C
31 lines
817 B
C
#include "netutil.h"
|
|
|
|
#include <SDL2/SDL_net.h>
|
|
|
|
#include "log.h"
|
|
|
|
// contrary to SDLNet_TCP_Send and SDLNet_TCP_Recv, SDLNet_TCP_Accept is non-blocking
|
|
// so we need to block before calling it
|
|
TCPsocket server_socket_accept(TCPsocket server_socket, Uint32 timeout_ms) {
|
|
SDLNet_SocketSet set = SDLNet_AllocSocketSet(1);
|
|
if (!set) {
|
|
LOGC("Could not allocate socket set");
|
|
return NULL;
|
|
}
|
|
|
|
if (SDLNet_TCP_AddSocket(set, server_socket) == -1) {
|
|
LOGC("Could not add socket to set");
|
|
SDLNet_FreeSocketSet(set);
|
|
return NULL;
|
|
}
|
|
|
|
if (SDLNet_CheckSockets(set, timeout_ms) != 1) {
|
|
LOGE("No connection to accept");
|
|
SDLNet_FreeSocketSet(set);
|
|
return NULL;
|
|
}
|
|
|
|
SDLNet_FreeSocketSet(set);
|
|
|
|
return SDLNet_TCP_Accept(server_socket);
|
|
}
|