piscisaureus / wepoll

wepoll: fast epoll for windows⁧ 🎭

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`socket == 0` is wrong

mgood7123 opened this issue · comments

wepoll/wepoll.c

Line 1640 in 0598a79

if (socket == 0 || socket == INVALID_SOCKET)

the windows api specifies If no error occurs, socket returns a descriptor referencing the new socket. Otherwise, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling [WSAGetLastError](https://learn.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsagetlasterror). however does not state if such valid return is non-zero or not

however based on https://stackoverflow.com/questions/2135159/socket-returns-0-in-c-client-server-application

socket CAN and WILL return zero if available (eg, if stdin has been closed)

That stack overflow post is clearly about a Unix like system. Indeed, posix mandates that the lowest available file descriptor must be returned, which is 0 if stdin has been closed.

Wepoll runs on Windows; here socket() does not return a file descriptor at all, and its return value is never 0.