2012/6/28 Ozkan Sezer <seze...@gmail.com>:
> On Thu, Jun 28, 2012 at 1:45 PM, Corinna Vinschen <vinsc...@redhat.com> wrote:
>> Hi,
>>
>> the below patch adds the first snippets of code to make the winsock stuff
>> more agreeable to a Cygwin build environment and building Cygwin itself.
>> There's more to come, but smaller snippets are easier to review, so...
>>
>> Here's what the patch does:
>>
>> - Move the definitions of __WSAFDIsSet and the FD_xxx macros into
>>  psdk_inc/_fd_types.h.
>>
>>  This has two advantages.  First, this stuff is shared between winsock.h
>>  and winsock2.h anyway, so we only have one definition now.
>
> This part looks problematic to me:
>
> - The ws1 and ws2 variants of FD_SET() macros aren't exactly the same.
>
> - The patch moves the defs to a shared header but doesn't remove the
> associated #undefs from psdk_inc/_ws1_undef.h
>
> - The moved __WSAFDIsSet() prototype is not enclosed between c-only
> linkage ifdefs
>
>>  Second, it restricts the confusing preprocessor juggeling which is
>>  required to let the fd_set-related settings work in a Cygwin environment
>>  to a single file.
>>
>> - Add the required Cygwin build environment preprocessor stuff to
>>  _fd_types.h.
>>
>> - Disable a first set of socket function declarations when building
>>  Cygwin itself.
>>
>> - Rearrange psdk_inc/_ip_type.h, so that the Windows-compatible typedef's
>>  are at the end of the file.  Add the required test to allow building
>>  Cygwin itself.
>>
>> Ok to apply?
>>
>>
>> Thanks,
>> Corinna
>>
>>
>>        * winsock2.h (__WSAFDIsSet): Move declaration to psdk_inv/_fd_type.h.
>>        (FD_CLR): Move definition to psdk_inv/_fd_type.h.
>>        (FD_ZERO): Ditto.
>>        (FD_ISSET): Ditto.
>>        (FD_SET): Ditto.
>>        (htonl): Don't declare when building Cygwin.
>>        (htons): Ditto.
>>        (ntohl): Ditto.
>>        (ntohs): Ditto.
>>        (gethostname): Ditto.
>>        * winsock.h: Ditto.
>>        * psdk_inc/_fd_types.h: Add Cygwin build environment magic to avoid
>>        multiple definition of the select function related datatypes and
>>        macros.
>>        (__WSAFDIsSet): Declare here.
>>        (FD_CLR): Define here.
>>        (FD_ZERO): Ditto.
>>        (FD_ISSET): Ditto.
>>        (FD_SET): Ditto.
>>        * psdk_inc/_ip_types.h: Rearrange slightly and don't define POSIX
>>        compatible datatypes when building Cygwin.
>>
>>
>> Index: include/winsock2.h
>> ===================================================================
>> --- include/winsock2.h  (revision 5139)
>> +++ include/winsock2.h  (working copy)
>> @@ -56,44 +56,6 @@
>>  extern "C" {
>>  #endif
>>
>> -extern int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
>> -
>> -#define FD_CLR(fd,set)                                                 \
>> -  do {                                                                 \
>> -       u_int __i;                                                      \
>> -       for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {        \
>> -               if (((fd_set *)(set))->fd_array[__i] == fd) {           \
>> -                       while (__i < ((fd_set *)(set))->fd_count - 1) { \
>> -                               ((fd_set *)(set))->fd_array[__i] =      \
>> -                                ((fd_set *)(set))->fd_array[__i + 1];  \
>> -                               __i++;                                  \
>> -                       }                                               \
>> -                       ((fd_set *)(set))->fd_count--;                  \
>> -                       break;                                          \
>> -               }                                                       \
>> -       }                                                               \
>> -} while(0)
>> -
>> -#define FD_ZERO(set)           (((fd_set *)(set))->fd_count = 0)
>> -
>> -#define FD_ISSET(fd,set)       __WSAFDIsSet((SOCKET)(fd),(fd_set *)(set))
>> -
>> -#define FD_SET(fd,set)                                                 \
>> -  do {                                                                 \
>> -       u_int __i;                                                      \
>> -       for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {        \
>> -               if (((fd_set *)(set))->fd_array[__i] == (fd)) {         \
>> -                       break;                                          \
>> -               }                                                       \
>> -       }                                                               \
>> -       if (__i == ((fd_set *)(set))->fd_count) {                       \
>> -               if (((fd_set *)(set))->fd_count < FD_SETSIZE) {         \
>> -                       ((fd_set *)(set))->fd_array[__i] = (fd);        \
>> -                       ((fd_set *)(set))->fd_count++;                  \
>> -               }                                                       \
>> -       }                                                               \
>> -} while(0)
>> -
>>  #define IOCPARM_MASK 0x7f
>>  #define IOC_VOID 0x20000000
>>  #define IOC_OUT 0x40000000
>> @@ -1001,13 +963,17 @@
>>   WINSOCK_API_LINKAGE int WSAAPI getpeername(SOCKET s,struct sockaddr 
>> *name,int *namelen);
>>   WINSOCK_API_LINKAGE int WSAAPI getsockname(SOCKET s,struct sockaddr 
>> *name,int *namelen);
>>   WINSOCK_API_LINKAGE int WSAAPI getsockopt(SOCKET s,int level,int 
>> optname,char *optval,int *optlen);
>> +#ifndef __INSIDE_CYGWIN__
>>   WINSOCK_API_LINKAGE u_long WSAAPI htonl(u_long hostlong);
>>   WINSOCK_API_LINKAGE u_short WSAAPI htons(u_short hostshort);
>> +#endif /* !__INSIDE_CYGWIN__ */
>>   WINSOCK_API_LINKAGE unsigned long WSAAPI inet_addr(const char *cp);
>>   WINSOCK_API_LINKAGE char *WSAAPI inet_ntoa(struct in_addr in);
>>   WINSOCK_API_LINKAGE int WSAAPI listen(SOCKET s,int backlog);
>> +#ifndef __INSIDE_CYGWIN__
>>   WINSOCK_API_LINKAGE u_long WSAAPI ntohl(u_long netlong);
>>   WINSOCK_API_LINKAGE u_short WSAAPI ntohs(u_short netshort);
>> +#endif /* !__INSIDE_CYGWIN__ */
>>   WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
>>   WINSOCK_API_LINKAGE int WSAAPI recvfrom(SOCKET s,char *buf,int len,int 
>> flags,struct sockaddr *from,int *fromlen);
>>   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set 
>> *writefds,fd_set *exceptfds,const struct timeval *timeout);
>> @@ -1018,7 +984,9 @@
>>   WINSOCK_API_LINKAGE SOCKET WSAAPI socket(int af,int type,int protocol);
>>   WINSOCK_API_LINKAGE struct hostent *WSAAPI gethostbyaddr(const char 
>> *addr,int len,int type);
>>   WINSOCK_API_LINKAGE struct hostent *WSAAPI gethostbyname(const char *name);
>> +#ifndef __INSIDE_CYGWIN__
>>   WINSOCK_API_LINKAGE int WSAAPI gethostname(char *name,int namelen);
>> +#endif /* !__INSIDE_CYGWIN__ */
>>   WINSOCK_API_LINKAGE struct servent *WSAAPI getservbyport(int port,const 
>> char *proto);
>>   WINSOCK_API_LINKAGE struct servent *WSAAPI getservbyname(const char 
>> *name,const char *proto);
>>   WINSOCK_API_LINKAGE struct protoent *WSAAPI getprotobynumber(int number);
>> Index: include/winsock.h
>> ===================================================================
>> --- include/winsock.h   (revision 5139)
>> +++ include/winsock.h   (working copy)
>> @@ -37,35 +37,6 @@
>>  extern "C" {
>>  #endif
>>
>> -extern int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
>> -
>> -#define FD_CLR(fd,set)                                                 \
>> -  do {                                                                 \
>> -       u_int __i;                                                      \
>> -       for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {        \
>> -               if (((fd_set *)(set))->fd_array[__i] == fd) {           \
>> -                       while (__i < ((fd_set *)(set))->fd_count - 1) { \
>> -                               ((fd_set *)(set))->fd_array[__i] =      \
>> -                                ((fd_set *)(set))->fd_array[__i + 1];  \
>> -                               __i++;                                  \
>> -                       }                                               \
>> -                       ((fd_set *)(set))->fd_count--;                  \
>> -                       break;                                          \
>> -               }                                                       \
>> -       }                                                               \
>> -} while(0)
>> -
>> -#define FD_ZERO(set)           (((fd_set *)(set))->fd_count = 0)
>> -
>> -#define FD_ISSET(fd,set)       __WSAFDIsSet((SOCKET)(fd),(fd_set *)(set))
>> -
>> -#define FD_SET(fd,set)                                                 \
>> -  do {                                                                 \
>> -       if (((fd_set *)(set))->fd_count < FD_SETSIZE)                   \
>> -           ((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++] =\
>> -                                                                  (fd);\
>> -} while(0)
>> -
>>  #define IOCPARM_MASK 0x7f
>>  #define IOC_VOID 0x20000000
>>  #define IOC_OUT 0x40000000
>> @@ -305,13 +276,17 @@
>>   WINSOCK_API_LINKAGE int WSAAPI getpeername(SOCKET s,struct sockaddr 
>> *name,int *namelen);
>>   WINSOCK_API_LINKAGE int WSAAPI getsockname(SOCKET s,struct sockaddr 
>> *name,int *namelen);
>>   WINSOCK_API_LINKAGE int WSAAPI getsockopt(SOCKET s,int level,int 
>> optname,char *optval,int *optlen);
>> +#ifndef __INSIDE_CYGWIN__
>>   WINSOCK_API_LINKAGE u_long WSAAPI htonl(u_long hostlong);
>>   WINSOCK_API_LINKAGE u_short WSAAPI htons(u_short hostshort);
>> +#endif /* !__INSIDE_CYGWIN__ */
>>   WINSOCK_API_LINKAGE unsigned long WSAAPI inet_addr(const char *cp);
>>   WINSOCK_API_LINKAGE char *WSAAPI inet_ntoa(struct in_addr in);
>>   WINSOCK_API_LINKAGE int WSAAPI listen(SOCKET s,int backlog);
>> +#ifndef __INSIDE_CYGWIN__
>>   WINSOCK_API_LINKAGE u_long WSAAPI ntohl(u_long netlong);
>>   WINSOCK_API_LINKAGE u_short WSAAPI ntohs(u_short netshort);
>> +#endif /* !__INSIDE_CYGWIN__ */
>>   WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
>>   WINSOCK_API_LINKAGE int WSAAPI recvfrom(SOCKET s,char *buf,int len,int 
>> flags,struct sockaddr *from,int *fromlen);
>>   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set 
>> *writefds,fd_set *exceptfds,const struct timeval *timeout);
>> @@ -322,7 +297,9 @@
>>   WINSOCK_API_LINKAGE SOCKET WSAAPI socket(int af,int type,int protocol);
>>   WINSOCK_API_LINKAGE struct hostent *WSAAPI gethostbyaddr(const char 
>> *addr,int len,int type);
>>   WINSOCK_API_LINKAGE struct hostent *WSAAPI gethostbyname(const char *name);
>> +#ifndef __INSIDE_CYGWIN__
>>   WINSOCK_API_LINKAGE int WSAAPI gethostname(char *name,int namelen);
>> +#endif /* !__INSIDE_CYGWIN__ */
>>   WINSOCK_API_LINKAGE struct servent *WSAAPI getservbyport(int port,const 
>> char *proto);
>>   WINSOCK_API_LINKAGE struct servent *WSAAPI getservbyname(const char 
>> *name,const char *proto);
>>   WINSOCK_API_LINKAGE struct protoent *WSAAPI getprotobynumber(int number);
>> Index: include/psdk_inc/_fd_types.h
>> ===================================================================
>> --- include/psdk_inc/_fd_types.h        (revision 5139)
>> +++ include/psdk_inc/_fd_types.h        (working copy)
>> @@ -12,12 +12,60 @@
>>  #ifndef FD_SETSIZE
>>  #define FD_SETSIZE     64
>>  #endif
>> +
>> +#ifndef _SYS_TYPES_FD_SET
>> +/* fd_set may have been defined by the newlib <sys/types.h>
>> + * if  __USE_W32_SOCKETS not defined.
>> + */
>> +
>>  typedef struct fd_set
>>  {
>>        u_int   fd_count;
>>        SOCKET  fd_array[FD_SETSIZE];
>>  } fd_set;
>>
>> +extern int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
>> +
>> +#ifndef FD_CLR
>> +#define FD_CLR(fd,set)                                                 \
>> +  do {                                                                 \
>> +       u_int __i;                                                      \
>> +       for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {        \
>> +               if (((fd_set *)(set))->fd_array[__i] == fd) {           \
>> +                       while (__i < ((fd_set *)(set))->fd_count - 1) { \
>> +                               ((fd_set *)(set))->fd_array[__i] =      \
>> +                                ((fd_set *)(set))->fd_array[__i + 1];  \
>> +                               __i++;                                  \
>> +                       }                                               \
>> +                       ((fd_set *)(set))->fd_count--;                  \
>> +                       break;                                          \
>> +               }                                                       \
>> +       }                                                               \
>> +} while(0)
>> +#endif
>> +
>> +#ifndef FD_ZERO
>> +#define FD_ZERO(set)           (((fd_set *)(set))->fd_count = 0)
>> +#endif
>> +
>> +#ifndef FD_ISSET
>> +#define FD_ISSET(fd,set)       __WSAFDIsSet((SOCKET)(fd),(fd_set *)(set))
>> +#endif
>> +
>> +#ifndef FD_SET
>> +#define FD_SET(fd,set)                                                 \
>> +  do {                                                                 \
>> +       if (((fd_set *)(set))->fd_count < FD_SETSIZE)                   \
>> +           ((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++] =\
>> +                                                                  (fd);\
>> +} while(0)
>> +#endif
>> +
>> +#elif !defined(USE_SYS_TYPES_FD_SET)
>> +#warning "fd_set and associated macros have been defined in sys/types.  \
>> +    This can cause runtime problems with W32 sockets"
>> +#endif /* !_SYS_TYPES_FD_SET */
>> +
>>  typedef struct fd_set  FD_SET;
>>  typedef struct fd_set  *PFD_SET;
>>  typedef struct fd_set  *LPFD_SET;
>> Index: include/psdk_inc/_ip_types.h
>> ===================================================================
>> --- include/psdk_inc/_ip_types.h        (revision 5139)
>> +++ include/psdk_inc/_ip_types.h        (working copy)
>> @@ -9,6 +9,11 @@
>>
>>  #include <_bsd_types.h>
>>
>> +#ifndef __INSIDE_CYGWIN__
>> +
>> +#include <inaddr.h>
>> +#include <_timeval.h>
>> +
>>  #define h_addr h_addr_list[0]
>>
>>  struct hostent {
>> @@ -44,21 +49,7 @@
>>        short   p_proto;
>>  };
>>
>> -typedef struct hostent         HOSTENT;
>> -typedef struct hostent         *PHOSTENT;
>> -typedef struct hostent         *LPHOSTENT;
>>
>> -typedef struct servent         SERVENT;
>> -typedef struct servent         *PSERVENT;
>> -typedef struct servent         *LPSERVENT;
>> -
>> -typedef struct protoent                PROTOENT;
>> -typedef struct protoent                *PPROTOENT;
>> -typedef struct protoent                *LPPROTOENT;
>> -
>> -
>> -#include <inaddr.h>
>> -
>>  struct sockaddr_in {
>>        short   sin_family;
>>        u_short sin_port;
>> @@ -81,6 +72,20 @@
>>        u_short l_linger;
>>  };
>>
>> +#endif /* !__INSIDE_CYGWIN__ */
>> +
>> +typedef struct hostent         HOSTENT;
>> +typedef struct hostent         *PHOSTENT;
>> +typedef struct hostent         *LPHOSTENT;
>> +
>> +typedef struct servent         SERVENT;
>> +typedef struct servent         *PSERVENT;
>> +typedef struct servent         *LPSERVENT;
>> +
>> +typedef struct protoent                PROTOENT;
>> +typedef struct protoent                *PPROTOENT;
>> +typedef struct protoent                *LPPROTOENT;
>> +
>>  typedef struct sockaddr                SOCKADDR;
>>  typedef struct sockaddr                *PSOCKADDR;
>>  typedef struct sockaddr                *LPSOCKADDR;
>> @@ -93,9 +98,6 @@
>>  typedef struct linger          *PLINGER;
>>  typedef struct linger          *LPLINGER;
>>
>> -
>> -#include <_timeval.h>
>> -
>>  typedef struct timeval         TIMEVAL;
>>  typedef struct timeval         *PTIMEVAL;
>>  typedef struct timeval         *LPTIMEVAL;
>>

Hi Corinna, hi Ozkan,

Please address Ozkan's comments.  As those winsock-files are Ozkan's
baby, I let him review this part.

Cheers,
Kai

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to