[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mingw32 and sockets

From: Ingolf Steinbach
Subject: Re: mingw32 and sockets
Date: Tue, 27 Sep 2005 17:15:42 +0200
User-agent: KMail/1.5.2


On Tuesday 27 September 2005 16:42, Derek Price wrote:
> Actually, Windows select() works _only_ on sockets.  Select on other fds
> returns "WSAENOTSOCK".
> bug-cvs@nongnu.org has recently been discussion a select() wrapper that
> could tell the difference for CVS.  As I understand it, there is a
> peeknamedpipe function to get select information for pipes
> (http://msdn.microsoft.com/library/en-us/ipc/base/peeknamedpipe.asp),
> but there is no equivalent for files (there are sync and async write
> functions for files, instead).

I have done a select() emulation on Win32 once. It was horrible.
If you want to avoid multithreading the approach is as follows:
For sockets, create a socket event object and use WSAEventSelect()
to make the event object fire for the "correct" socket events.
For each pipe, serial port, etc, create an event object, an
OVERLAPPED object using this event and start an async read
with the OVERLAPPED structure.

Now WaitForMultipleObjects() with all of the above events.
After WaitForMultipleObjects() returns, use select() with a
0-timeout to check socket events and poll the other events
(WaitForSingleObject(event, 0)) to see whether one of them
has fired.

As this approach actually involves transmission of data (the
async read operation will succeed eventually), you must read
to an internal buffer first. The actual read() function must
be encapsulated, too, and look in this internal buffer first.

Adding write support works similarly.

Maybe someone with more knowledge of the Win32 API has a
better approach than the above. Please let me know.

And maybe the situation is easier for CVS when the communication
can be reduced to pipes and sockets (e.g. no serial support).

Kind regards

Ingolf Steinbach                       Jena-Optronik GmbH
ingolf.steinbach@jena-optronik.de       ++49 3641 200-147
PGP: 0x7B3B5661  213C 828E 0C92 16B5  05D0 4D5B A324 EC04

reply via email to

[Prev in Thread] Current Thread [Next in Thread]