bug-cvs
[Top][All Lists]
Advanced

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

Re: mingw32 and sockets


From: Derek Price
Subject: Re: mingw32 and sockets
Date: Tue, 27 Sep 2005 10:42:58 -0400
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

Bruno Haible wrote:

>The Woe32 socket API has three main differences w.r.t. the POSIX socket API:
>
>  - The type of a socket is 'SOCKET', not 'int'. A SOCKET cannot be used in
>    places where a file descriptor is used. This means in particular that
>    close(), select(), poll() don't work on sockets. But the Woe32 API
>    offers equivalents under different names.
>  
>

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).

Cygwin deals with this by having their select() wrapper always return
ready for files, but they use complex magic in open()/connect()/etc. to
relate a single set of fds back to either a Windows file, pipe, or
socket handle and wrap select() and all the other low-level IO routines
to differentiate and pick the correct Windows functions for whatever
object they were passed.

>#ifdef _WIN32
># define sock_errno WSAGetLastError ()
># define sock_errno_is(val) (WSAGetLastError () == WSA##val)
># define sock_set_errno(val) WSASetLastError (WSA##val)
>  extern int sock_read (...);
>  extern int sock_write (...);
>#else
># define sock_errno errno
># define sock_errno_is(val) (errno == val)
># define sock_set_errno(val) (void)(errno = val)
># define sock_read read
># define sock_write write
>#endif
>
>This means that the program code uses slightly different conventions than
>POSIX, but still someone who knows POSIX can use this API without effort.
>  
>

This is basically what CVS has been using for a long time.  We are now
proposing adding, basically:

#ifdef _WIN32
# define sock_select   select
# define fd_select wnt_select
#else
# define sock_select select
# define fd_select select
#endif

And defnining wnt_select such that it can differentiate between a file
and a pipe and make the correct choice about what to do.  I have yet to
hear for sure if this is possible, though I think Conrad Pino, the
developer working on it, currently thinks it is.

>Do you like that? Or better pure POSIX?
>  
>

A pure POSIX set of wrappers would be nice, but I'm not sure how to do
it without wrapping nearly all the low-level IO routines like Cygwin did.

Regards,

Derek

-- 
Derek R. Price
CVS Solutions Architect
Ximbiot <http://ximbiot.com>
v: +1 717.579.6168
f: +1 717.234.3125
<mailto:derek@ximbiot.com>






reply via email to

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