Commit fd7a2911 authored by Alex Hultman's avatar Alex Hultman
Browse files

Fix broken Winsock error handling

parent 80711e9b
......@@ -120,6 +120,14 @@ struct Context {
closesocket(fd);
#else
close(fd);
#endif
}
bool wouldBlock() {
#ifdef _WIN32
return WSAGetLastError() == WSAEWOULDBLOCK;
#else
return errno == EWOULDBLOCK;// || errno == EAGAIN;
#endif
}
};
......
......@@ -93,7 +93,7 @@ public:
// * polling will cause the server to spin, using 100% cpu. Switch to a timer
// * event instead to avoid this.
// */
// if (!TIMER && errno != EAGAIN && errno != EWOULDBLOCK) {
// if (!TIMER && !netContext->wouldBlock()) {
// listenData->listenPoll->stop(listenData->nodeData->loop);
// listenData->listenPoll->close(listenData->nodeData->loop);
// listenData->listenPoll = nullptr;
......
......@@ -263,6 +263,7 @@ struct WIN32_EXPORT Socket : Poll {
static void ioHandler(Poll *p, int status, int events) {
Socket *socket = (Socket *) p;
NodeData *nodeData = socket->nodeData;
Context *netContext = nodeData->netContext;
if (status < 0) {
STATE::onEnd((Socket *) p);
......@@ -286,7 +287,7 @@ struct WIN32_EXPORT Socket : Poll {
break;
}
} else if (sent == SOCKET_ERROR) {
if (errno != EWOULDBLOCK) {
if (!netContext->wouldBlock()) {
STATE::onEnd((Socket *) p);
return;
}
......@@ -305,7 +306,7 @@ struct WIN32_EXPORT Socket : Poll {
int length = recv(socket->getFd(), nodeData->recvBuffer, nodeData->recvLength, 0);
if (length > 0) {
STATE::onData((Socket *) p, nodeData->recvBuffer, length);
} else if (length <= 0 || (length == SOCKET_ERROR && errno != EWOULDBLOCK)) {
} else if (length <= 0 || (length == SOCKET_ERROR && !netContext->wouldBlock())) {
STATE::onEnd((Socket *) p);
}
}
......@@ -391,7 +392,7 @@ struct WIN32_EXPORT Socket : Poll {
wasTransferred = false;
return true;
} else if (sent == SOCKET_ERROR) {
if (errno != EWOULDBLOCK) {
if (!nodeData->netContext->wouldBlock()) {
return false;
}
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment