Mingw doesn't like write() to socket
Bert Belder
H.Belder at student.TUDelft.NL
Wed Dec 8 02:21:25 CET 2010
> -----Oorspronkelijk bericht-----
> Van: Marc Lehmann [mailto:schmorp at schmorp.de]
> Verzonden: donderdag 25 november 2010 1:46
> Aan: Bert Belder
> CC: libev at lists.schmorp.de
> Onderwerp: Re: Mingw doesn't like write() to socket
>
> On Tue, Nov 23, 2010 at 12:58:29PM +0100, Bert Belder
> <H.Belder at student.TUDelft.NL> wrote:
> > I'm trying to use libev in a MinGW project. Initially ev_async
> watchers
> > didn't work; after some debugging I found out that the write() call
> in
> > evpipe_write() always returns -1, indicating failure; apparently the
> > MinGW libraries don't like me writing to a socket using write.
>
> Actually, all the documentation I can find points to mingw supporting
> read/write just fine.
>
> If send relaly works instead of write, then most likely
> EV_FD_TO_WIN32_HANDLEand the reverse are not working for mingw
somehow.
>
> > However swapping out the write call and replacing it with:
> > send(EV_FD_TO_WIN32_HANDLE(evpipe [1]), &dummy, 1, 0);
> > actually solves my problems; select() suddenly wakes up.
>
> Most likely it will cause other issues though - write on mingw should
> just
> work on socket fds (not socket handles).
>
> So the mystery is sitll there.
I think I found out what the problem is.
It's not really a mingw limitation but a windows limitation.
Sockets are opened in overlapped mode by default (I'm not sure about
earlier windows versions, but on Vista and later for sure).
The read/write crt functions call winapi's ReadFile and WriteFile
internally like you would if you were working with non-overlapped
handles, e.g. without passing an overlapped structure. These api calls
subsequently fail because passing an overlapped structure is obligatory
for overlapped file handles.
It is possible (though hard) to open a socket in blocking mode, but
ev_pipe doesn't do this. And you wouldn't be able to select() on a
non-overlapped socket.
I'm wondering - Sure you tested libev on windows; which windows version
and toolchain did/do you use?
- Bert
More information about the libev
mailing list