Windows Compilation problem

Horacio Sanson hsanson at
Thu Jun 26 04:09:35 CEST 2008

Ok I think I solved my problem but want to make sure it is the correct
way to do this.

I keep all my code the same except for the calls to ev_io_set().
Instead of passing the socket descriptor as returned by socket() or
WSASocket() I convert if first to handle and then pass the handle to
ev_io_set...  the relevant code looks like:

ev_io_set (&client->read_watcher, _open_osfhandle(client->socketfd,

This works as my client now connects and transmits data to the server
(Linux) but is a little ugly.

better ways to do this are appreciated...


On Thu, Jun 26, 2008 at 10:28 AM, Horacio Sanson <hsanson at> wrote:
> On Fri, Jun 6, 2008 at 9:35 AM, Chris Hulbert <chris.hulbert at> wrote:
>> FYI, i just had the same problem.
>> To convert from a socket to a file descriptor, you'll need to use this function:
>>  // for win32: convert from socket to file descriptor
>>  // //
>>  int fd = _open_osfhandle(socket,0);
> I just encounter this same error but I am unable to solve it. My
> program can create a socket() and actually connect to the server using
> connect() but when I start the libev default loop an assertion ocurrs
> when it calls _get_osfhandle() on line 716 of ev.c file.
> How exactly am I supposed to use the _open_osfhandle() method as you
> mention here?? If I use this method on the socket I get from the
> socket() method then all subsequent calls on the socket (i.e. connect,
> bind, listen) would return WSAENOTSOCK error.
> Shall I replace all instances of _get_osfhandle() with a call to
> _open_sofhandle()??  or am I missing something else??
> regards
> Horacio
>> On Thu, Jun 5, 2008 at 6:23 PM, Marc Lehmann <schmorp at> wrote:
>>> On Wed, Jun 04, 2008 at 04:29:46PM -0700, Matt Tolton <matt at> wrote:
>>>> Any pointers here?  The fd that I'm using is a socket obtained from
>>>> the winsock socket() call.  Here is the code used to initialize it:
>>> That doesn't work - the libev API requires file descriptors on all
>>> platforms.  What you pass in is a native opertaing system handle that is
>>> not a file descriptor.
>> _______________________________________________
>> libev mailing list
>> libev at

More information about the libev mailing list