On Jun 28 14:20, Ozkan Sezer wrote:
> 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.

Oops, how could I miss that?  Sorry about that.  Would something like
this be ok?

  #ifndef FD_SET
  #ifdef _WINSOCK2API_
  #define FD_SET ... from winsock2.h
  #else
  #define FD_SET ... from winsock.h
  #endif /* _WINSOCK2API_ */
  #endif /* !FD_SET */

> - The patch moves the defs to a shared header but doesn't remove the
> associated #undefs from psdk_inc/_ws1_undef.h

Hmm.  AFAICS they should stay there.  The _fd_type.h header is included
from winsock.h and winsock2.h only.  If you include winsock2.h before
winsock.h, the content of winsock.h will be ignored and you'll get the
FD_xxx definitions for winsock2.h.  If you include winsock2.h after
winsock.h, you want the FD_xxx definitions to be undef'ed, so that the
subsequent

  #ifndef FD_xxx
  #define FD_xxx
  #endif
  
will define the winsock2.h version of the definition, which seems to be
especially important for FD_SET.  Did I miss something?

> - The moved __WSAFDIsSet() prototype is not enclosed between c-only
> linkage ifdefs

Fixed in the patch below.  I only send the _fd_types.h patch since
that's the only changed file.


Thanks,
Corinna


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,86 @@
 #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;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#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 /* !FD_CLR */
+
+#ifndef FD_ZERO
+#define FD_ZERO(set)           (((fd_set *)(set))->fd_count = 0)
+#endif /* !FD_ZERO */
+
+#ifndef FD_ISSET
+#define FD_ISSET(fd,set)       __WSAFDIsSet((SOCKET)(fd),(fd_set *)(set))
+#endif /* !FD_ISSET */
+
+#ifndef FD_SET
+#ifdef _WINSOCK2API_
+#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)
+#else
+#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 /* _WINSOCK2API_ */
+#endif /* !FD_SET */
+
+#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;

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