///////////////////// // Wait until the socket contains some data or is writeable // TODO: remove this function, don't use it! void NetworkSocket::WaitForSocketReadOrWrite(int timeout) { if(!isOpen()) { errors << "WaitForSocketReadOrWrite: socket closed" << endl; return; } NLint group = nlGroupCreate(); nlGroupAddSocket(group, m_socket->sock); NLsocket s; if (timeout < 0) { // Infinite timeout while (true) { if (nlPollGroup(group, NL_READ_STATUS, &s, 1, 0)) break; if (nlPollGroup(group, NL_WRITE_STATUS, &s, 1, 0)) break; SDL_Delay(2); } } else if (timeout > 0) { // Blocking, with a timeout Uint32 start = SDL_GetTicks(); while (SDL_GetTicks() - start <= (Uint32)timeout) { if (nlPollGroup(group, NL_READ_STATUS, &s, 1, 0)) break; if (nlPollGroup(group, NL_WRITE_STATUS, &s, 1, 0)) break; SDL_Delay(2); } } nlGroupDestroy(group); }
bool NetworkSocket::isDataAvailable() { NLint group = nlGroupCreate(); nlGroupAddSocket( group, m_socket->sock ); NLsocket sock_out[2]; int ret = nlPollGroup( group, NL_READ_STATUS, sock_out, 1, 0 ); nlGroupDestroy(group); return ret > 0; }
////////////////////// // Wait until the socket contains some data to read // TODO: remove this function, don't use it! void NetworkSocket::WaitForSocketRead(int timeout) { if(!isOpen()) { errors << "WaitForSocketRead: socket closed" << endl; return; } NLint group = nlGroupCreate(); nlGroupAddSocket(group, m_socket->sock); NLsocket s; nlPollGroup(group, NL_READ_STATUS, &s, 1, (NLint)timeout); nlGroupDestroy(group); }
void nlGroupShutdown(void) { if(groups != NULL) { NLint i; for(i=0;i<NL_MAX_GROUPS;i++) { if(groups[i] != NULL) { (void)nlGroupDestroy(i + NL_FIRST_GROUP); } } free(groups); groups = NULL; } (void)nlMutexDestroy(&grouplock); }
void loopback_Shutdown(void) { nlGroupDestroy(loopgroup); }
~SharedData() { nlGroupDestroy(nlGroup); nlGroup = NL_INVALID; }