Home | History | Annotate | Download | only in psdk_inc
      1 /**
      2  * This file has no copyright assigned and is placed in the Public Domain.
      3  * This file is part of the mingw-w64 runtime package.
      4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
      5  */
      6 
      7 #ifndef ___WSA_FD_TYPES_H
      8 #define ___WSA_FD_TYPES_H
      9 
     10 #include <psdk_inc/_socket_types.h>
     11 
     12 #ifndef FD_SETSIZE
     13 #define FD_SETSIZE	64
     14 #endif
     15 
     16 #ifndef _SYS_TYPES_FD_SET
     17 /* fd_set may have been defined by the newlib <sys/types.h>
     18  * if  __USE_W32_SOCKETS not defined.
     19  */
     20 
     21 typedef struct fd_set
     22 {
     23 	u_int	fd_count;
     24 	SOCKET	fd_array[FD_SETSIZE];
     25 } fd_set;
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 int WINAPI __WSAFDIsSet(SOCKET,fd_set *);
     32 
     33 #ifdef __cplusplus
     34 }
     35 #endif
     36 
     37 #ifndef FD_CLR
     38 #define FD_CLR(fd,set)							\
     39   do {									\
     40 	u_int __i;							\
     41 	for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {	\
     42 		if (((fd_set *)(set))->fd_array[__i] == fd) {		\
     43 			while (__i < ((fd_set *)(set))->fd_count - 1) {	\
     44 				((fd_set *)(set))->fd_array[__i] =	\
     45 				 ((fd_set *)(set))->fd_array[__i + 1];	\
     46 				__i++;					\
     47 			}						\
     48 			((fd_set *)(set))->fd_count--;			\
     49 			break;						\
     50 		}							\
     51 	}								\
     52   } while(0)
     53 #endif /* !FD_CLR */
     54 
     55 #ifndef FD_ZERO
     56 #define FD_ZERO(set)		(((fd_set *)(set))->fd_count = 0)
     57 #endif /* !FD_ZERO */
     58 
     59 #ifndef FD_ISSET
     60 #define FD_ISSET(fd,set)	__WSAFDIsSet((SOCKET)(fd),(fd_set *)(set))
     61 #endif /* !FD_ISSET */
     62 
     63 /* FD_SET is differently implement in winsock.h and winsock2.h.  If we
     64    encounter that we are going to redefine it, and if the original definition
     65    is from winsock.h, make sure to undef FD_SET so it can be redefined to
     66    the winsock2.h version. */
     67 #ifdef _FD_SET_WINSOCK_DEFINED
     68 #undef _FD_SET_WINSOCK_DEFINED
     69 #undef FD_SET
     70 #endif
     71 #ifndef FD_SET
     72 #ifdef _WINSOCK2API_
     73 #define FD_SET(fd,set)							\
     74   do {									\
     75 	u_int __i;							\
     76 	for(__i = 0; __i < ((fd_set *)(set))->fd_count; __i++) {	\
     77 		if (((fd_set *)(set))->fd_array[__i] == (fd)) {		\
     78 			break;						\
     79 		}							\
     80 	}								\
     81 	if (__i == ((fd_set *)(set))->fd_count) {			\
     82 		if (((fd_set *)(set))->fd_count < FD_SETSIZE) {		\
     83 			((fd_set *)(set))->fd_array[__i] = (fd);	\
     84 			((fd_set *)(set))->fd_count++;			\
     85 		}							\
     86 	}								\
     87   } while(0)
     88 #else
     89 #define _FD_SET_WINSOCK_DEFINED
     90 #define FD_SET(fd,set)							\
     91   do {									\
     92 	if (((fd_set *)(set))->fd_count < FD_SETSIZE)			\
     93 	    ((fd_set *)(set))->fd_array[((fd_set *)(set))->fd_count++] =\
     94 								   (fd);\
     95   } while(0)
     96 #endif /* _WINSOCK2API_ */
     97 #endif /* !FD_SET */
     98 
     99 #elif !defined(USE_SYS_TYPES_FD_SET)
    100 #warning "fd_set and associated macros have been defined in sys/types.  \
    101     This can cause runtime problems with W32 sockets"
    102 #endif /* !_SYS_TYPES_FD_SET */
    103 
    104 typedef struct fd_set	FD_SET;
    105 typedef struct fd_set	*PFD_SET;
    106 typedef struct fd_set	*LPFD_SET;
    107 
    108 #endif /* ___WSA_FD_TYPES_H */
    109 
    110