[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFT] Wrap winsock functions for improved compatibility
From: |
Bruno Haible |
Subject: |
Re: [RFT] Wrap winsock functions for improved compatibility |
Date: |
Fri, 12 Sep 2008 13:32:02 +0200 |
User-agent: |
KMail/1.5.4 |
Hi Paolo,
This is exciting! By using _open_osfhandle you are ensuring that there
are no collisions between native file handles and socket-related file handles.
Great!
A few comments, though:
- > It needs to be tested on Windows (mingw and cygwin)
The patch is supposed to change nothing on Cygwin, right? Cygwin has
perfectly fine POSIX socket support already.
- The transformation of WSAGetLastError() values to errno values is a nice
trick, but the mapping e -> e - 10000 will not work out because of some
clashes. Looking at mingw's <errno.h> and <winsock2.h> the first ones are
ok but not the later ones:
#define EINTR 4 /* Interrupted function call */
#define WSAEINTR (WSABASEERR+4)
ok
#define EBADF 9 /* Bad file descriptor */
#define WSAEBADF (WSABASEERR+9)
ok
#define EACCES 13 /* Permission denied */
#define WSAEACCES (WSABASEERR+13)
ok
#define EFAULT 14 /* Bad address */
#define WSAEFAULT (WSABASEERR+14)
ok
#define EINVAL 22 /* Invalid argument */
#define WSAEINVAL (WSABASEERR+22)
ok
#define EMFILE 24 /* Too many open files */
#define WSAEMFILE (WSABASEERR+24)
ok
#define WSAEWOULDBLOCK (WSABASEERR+35)
ok
#define EDEADLOCK 36 /* Resource deadlock avoided (non-Cyg) */
#define WSAEINPROGRESS (WSABASEERR+36) /* deprecated on WinSock2 */
clash
#define WSAEALREADY (WSABASEERR+37)
#define ENAMETOOLONG 38 /* Filename too long (91 in Cyg?) */
#define WSAENOTSOCK (WSABASEERR+38)
clash
#define ENOLCK 39 /* No locks available (46 in Cyg?) */
#define WSAEDESTADDRREQ (WSABASEERR+39)
clash
#define ENOSYS 40 /* Function not implemented (88 in Cyg?) */
#define WSAEMSGSIZE (WSABASEERR+40)
clash
#define ENOTEMPTY 41 /* Directory not empty (90 in Cyg?) */
#define WSAEPROTOTYPE (WSABASEERR+41)
clash
#define EILSEQ 42 /* Illegal byte sequence */
#define WSAENOPROTOOPT (WSABASEERR+42)
clash
I would propose to leave the higher WSA* values as is, though a
mapping e -> (e < 10025 ? e - 10000 : e)
- It would be good to extend the gnulib <errno.h>, <string.h>, <stdio.h>,
strerror, perror replacements to handle these values (when the sys_socket
module is in use). (errno values are supposed to be all defined in <errno.h>,
strerror is supposed to be declared in <string.h>, and perror is supposed
to be declared in <stdio.h>.)
- Can we call the replacement functions "rpl_getsockopt" etc. please, not
"win_getsockopt"? To make it clear that it's the gnulib replacement, and
because the prefix "win" is subtle brainwashing.
- What about the need to call WSAInit()? Is it still needed at all?
- The doc should document that while most fd-based POSIX functions are
correctly replaced, things like
int fd = connect (...);
FILE *fp = fdopen (fd, "w");
will not work - because the fwrite() function will call write(), not send(),
under the hood.
Bruno
- [RFT] Wrap winsock functions for improved compatibility, Paolo Bonzini, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility, Paolo Bonzini, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility,
Bruno Haible <=
- Re: [RFT] Wrap winsock functions for improved compatibility, Paolo Bonzini, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility, Eric Blake, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility, Paolo Bonzini, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility, Eric Blake, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility, Paolo Bonzini, 2008/09/12
- Re: [RFT] Wrap winsock functions for improved compatibility, Bruno Haible, 2008/09/13