• R/O
  • HTTP
  • SSH
  • HTTPS

mingw-org-wsl: Commit

The MinGW.OSDN Windows System Libraries. Formerly designated as "MinGW.org Windows System Libraries", this encapsulates the "mingwrt" C runtime library extensions, and the "w32api" 32-bit MS-Windows API libraries.

Please note that this project no longer owns the "MinGW.org" domain name; any software which may be distributed from that domain is NOT supported by this project.


Commit MetaInfo

Revisãoc93876877c12a2b88d3da6d53e6303255f1d10f2 (tree)
Hora2017-11-09 02:46:34
AutorKeith Marshall <keith@user...>
CommiterKeith Marshall

Mensagem de Log

Overhaul WinSock fd_set content management macros.

Mudança Sumário

Diff

--- a/w32api/ChangeLog
+++ b/w32api/ChangeLog
@@ -1,3 +1,20 @@
1+2017-11-08 Keith Marshall <keith@users.osdn.me>
2+
3+ Overhaul WinSock fd_set content management macros.
4+
5+ * include/winsock.h (FD_SET, FD_ISSET, FD_CLR, FD_ZERO): Replace the
6+ original implementations of each of these macros, redirecting to...
7+ (__FD_SET, __FD_ISSET, __FD_CLR, __FD_ZERO): ...these new, equivalent
8+ inline functions, respectively; these are more robust, and correct a
9+ defect in the original FD_SET macro implementation, whereby duplicate
10+ descriptors could be added to an fd_set array, but would not then be
11+ removed by the corresponding FD_CLR macro.
12+
13+ * tests/winsock.at (MINGW_AT_CHECK_WINSOCK): Ensure that all test
14+ programs are linked with -lwsock32 or -lws2_32, as appropriate; the
15+ __FD_SET and __FD_ISSET functions are dependent on the __WSAFDIsSet()
16+ function, which is implemented in each of these libraries.
17+
118 2017-11-07 Keith Marshall <keith@users.osdn.me>
219
320 Identify features which have been deprecated in WinSock v2.
--- a/w32api/include/winsock.h
+++ b/w32api/include/winsock.h
@@ -120,39 +120,51 @@ struct fd_set
120120 SOCKET fd_array[FD_SETSIZE];
121121 } fd_set;
122122
123-int PASCAL __WSAFDIsSet (SOCKET, fd_set *);
123+#ifndef FD_ISSET
124+int FD_ISSET (SOCKET, fd_set *);
125+#define FD_ISSET( __fd, __set ) __FD_ISSET ((__fd), (__set))
124126
125-#ifndef FD_CLR
126-#define FD_CLR( fd, set ) do \
127- { u_int __i; \
128- for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) \
129- { if (((fd_set *)(set))->fd_array[__i] == (fd)) \
130- { while (__i < ((fd_set *)(set))->fd_count-1) \
131- { ((fd_set *)(set))->fd_array[__i] \
132- = ((fd_set *)(set))->fd_array[__i + 1]; __i++; \
133- } \
134- ((fd_set *)(set))->fd_count--; \
135- break; \
136- } \
137- } \
138- } while (0)
139-#endif /* ! defined FD_CLR */
127+/* Microsoft provide this library function equivalent of the FD_ISSET
128+ * macro, and erroneously claim that it is neccessary to implement the
129+ * macro. We could just as easily implement it entirely inline...
130+ */
131+int PASCAL __WSAFDIsSet (SOCKET, fd_set *);
132+/* ...but, given the availability of the library function, we may just
133+ * as well use it.
134+ */
135+__CRT_ALIAS int __FD_ISSET( SOCKET __fd, fd_set *__set )
136+{ return __WSAFDIsSet (__fd, __set); }
137+#endif /* ! defined FD_ISSET */
140138
141139 #ifndef FD_SET
142-#define FD_SET( fd, set ) do \
143- { if (((fd_set *)(set))->fd_count < FD_SETSIZE) \
144- ((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++] = (fd); \
145- } while (0)
140+void FD_SET (SOCKET, fd_set *);
141+#define FD_SET( __fd, __set ) __FD_SET ((__fd), (__set))
142+__CRT_ALIAS void __FD_SET (SOCKET __fd, fd_set *__set)
143+{ if( (__set->fd_count < FD_SETSIZE) && ! FD_ISSET (__fd, __set) )
144+ __set->fd_array[__set->fd_count++] = __fd;
145+}
146146 #endif /* ! defined FD_SET */
147147
148+#ifndef FD_CLR
149+void FD_CLR (SOCKET, fd_set *);
150+#define FD_CLR( __fd, __set ) __FD_CLR ((__fd), (__set))
151+__CRT_ALIAS void __FD_CLR (SOCKET __fd, fd_set *__set)
152+{ u_int __m, __n; for (__m = __n = 0; __n < __set->fd_count; __n++)
153+ { if (__fd != __set->fd_array[__n])
154+ { if (__m < __n) __set->fd_array[__m] = __set->fd_array[__n];
155+ ++__m;
156+ }
157+ } __set->fd_count = __m;
158+}
159+#endif /* ! defined FD_CLR */
160+
148161 #ifndef FD_ZERO
149-#define FD_ZERO( set ) (((fd_set *)(set))->fd_count = 0)
162+void FD_ZERO (fd_set *);
163+#define FD_ZERO( __set ) __FD_ZERO (__set)
164+__CRT_ALIAS void __FD_ZERO (fd_set *__set)
165+{ __set->fd_count = 0; }
150166 #endif /* ! defined FD_ZERO */
151167
152-#ifndef FD_ISSET
153-#define FD_ISSET( fd, set ) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set))
154-#endif /* ! defined FD_ISSET */
155-
156168 #elif ! defined _USE_SYS_TYPES_FD_SET
157169 /* Definitions from <sys/types.h> probably aren't what the user wants;
158170 * if they know what they are doing, and they are sure that this really
@@ -562,7 +574,7 @@ int PASCAL gethostname (char *, int );
562574 #define WSAGETSELECTEVENT(l) LOWORD(l)
563575 #define WSAGETSELECTERROR(l) HIWORD(l)
564576
565-typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
577+typedef struct fd_set /* FD_SET, */ *PFD_SET, *LPFD_SET;
566578 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
567579 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
568580 typedef struct linger LINGER, *PLINGER, *LPLINGER;
--- a/w32api/tests/winsock.at
+++ b/w32api/tests/winsock.at
@@ -97,6 +97,7 @@ AT_CLEANUP])
9797 #
9898 m4_define([MINGW_AT_CHECK_WINSOCK],[dnl
9999 AT_BANNER([Windows Sockets $1 fd_set macro checks.])
100+MINGW_AT_LINK_LIBS([m4_case([$1],[v2],[-lws2_32],[-lwsock32])])
100101
101102 # Verify that the FD_ZERO macro clears all descriptors from the
102103 # predefined, non-empty fd_set {1, 2, 3, 4}
@@ -157,7 +158,6 @@ MINGW_AT_CHECK_FD_MACRO([$2],[FD_CLR],dnl
157158 # function, we must ensure that the test code is linked with
158159 # the appropriate version of the WinSock library.
159160 #
160-MINGW_AT_LINK_LIBS([m4_case([$1],[v2],[-lws2_32],[-lwsock32])])
161161 MINGW_AT_CHECK_FD_ISSET_MACRO([$2],[4])
162162 MINGW_AT_CHECK_FD_ISSET_MACRO([$2],[2])
163163
Show on old repository browser