"Damjan Jovanovic" damjan.jov@gmail.com writes:
- while (!tcpc->quit)
- {
- FD_ZERO(&readableSet);
- FD_SET(tcpc->sock, &readableSet);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
- ret = select(tcpc->sock + 1, &readableSet, NULL, NULL, &timeout);
- if (ret < 0)
ERR("select failed with error %d\n", ret);
- else
- {
if (FD_ISSET(tcpc->sock, &readableSet))
{
SetEvent(tcpc->onEventAvailable);
WaitForSingleObject(tcpc->onEventHandled, INFINITE);
ResetEvent(tcpc->onEventHandled);
}
- }
It would be cleaner to use poll() instead of select(). Also you probably want to use auto-reset events, that would reduce the number of server calls you have to make.