EV_FD_TO_WIN32_HANDLE on Windows

Alexey Borzenkov snaury at gmail.com
Sat Mar 8 08:26:19 CET 2014


Hi Mikkel,

On Sat, Mar 8, 2014 at 9:05 AM, Mikkel Kroman <mk at uplink.io> wrote:
> Hi, I'm currently experiencing the same problem as explained here:
> http://lists.schmorp.de/pipermail/libev/2011q2/001470.html
>
> Was this issue ever acknowledged or resolved?

Looking at the original e-mail it's clear that there was a
misunderstanding. On this line:

SOCKET fd = socket( AF_INET, SOCK_STREAM, 0 );

The fd variable actually holds a socket handle (fh), not a file
descriptor (fd). To obtain a file descriptor (which are emulated by
the Visual C++ C runtime) you would need to do the following:

SOCKET fh = socket( AF_INET, SOCK_STREAM, 0 );
int fd = _open_osfhandle(fh);

See http://msdn.microsoft.com/en-us/library/bdts1c9x.aspx for details.
The assertion and/or incorrect handle value may be a result of fd not
being valid or being outside of the file descriptor range.

> This is happening when running Windows 8.1 with the Visual Studio 2013 runtime.

Also, make sure that your executable is not using multiple runtimes at
the same time. File descriptors from different runtimes are not
compatible and would also result in file descriptors not being valid
in one runtime or the other.

Best regards,
Alexey.



More information about the libev mailing list