OSDN Git Service

Factor <winsock.h> duplicate content out of <winsock2.h>
[mingw/mingw-org-wsl.git] / w32api / include / winsock.h
index 7aa2462..08967b3 100644 (file)
@@ -1,7 +1,9 @@
 /*
  * winsock.h
  *
- * Definitions for WinSock Version 1.1 API.
+ * Definitions for WinSock Version 1.1 API; also includes a subset of the
+ * definitions which become applicable for WinSock Version 2, filtered such
+ * that they are exposed only when this file is included by <winsock2.h>
  *
  *
  * $Id$
@@ -200,7 +202,7 @@ __CRT_ALIAS void __FD_ZERO (fd_set *__set)
 #warning "Your <sys/types.h> may cause runtime problems with W32 sockets."
 #endif /* !_SYS_TYPES_FD_SET */
 
-#if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
+#ifndef __INSIDE_MSYS__
 
 struct hostent
 { char          *h_name;
@@ -216,7 +218,7 @@ struct linger
   u_short        l_linger;
 };
 
-#endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+#endif /* !__INSIDE_MSYS__ */
 
 #define IOCPARM_MASK                         0x7F
 #define IOC_VOID                       0x20000000
@@ -224,7 +226,7 @@ struct linger
 #define IOC_IN                         0x80000000
 #define IOC_INOUT                  (IOC_IN | IOC_OUT)
 
-#if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
+#ifndef __INSIDE_MSYS__
 
 #define _IO(x,y)       (IOC_VOID|((x)<<8)|(y))
 #define _IOR(x,y,t)    (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
@@ -232,7 +234,7 @@ struct linger
 
 #define FIONBIO                _IOW('f', 126, u_long)
 
-#endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+#endif /* !__INSIDE_MSYS__ */
 
 #define FIONREAD               _IOR('f', 127, u_long)
 #define FIOASYNC               _IOW('f', 125, u_long)
@@ -242,7 +244,7 @@ struct linger
 #define SIOCGLOWAT             _IOR('s',  3, u_long)
 #define SIOCATMARK             _IOR('s',  7, u_long)
 
-#if ! ( defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
+#ifndef __INSIDE_MSYS__
 
 struct netent
 { char          *n_name;
@@ -264,7 +266,7 @@ struct protoent
   short          p_proto;
 };
 
-#endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+#endif /* !__INSIDE_MSYS__ */
 
 #define IPPROTO_IP                                0
 #define IPPROTO_ICMP                              1
@@ -449,7 +451,7 @@ struct ip_mreq
 #define AF_ATM                                   22
 #define AF_INET6                                 23
 
-#if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
+#ifndef __INSIDE_MSYS__
 
 #define AF_MAX                                   24
 
@@ -458,7 +460,7 @@ struct sockaddr
   char                  sa_data[14];
 };
 
-#endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+#endif /* !__INSIDE_MSYS__ */
 
 struct sockproto
 { u_short               sp_family;
@@ -494,40 +496,77 @@ struct sockproto
 
 #define SOL_SOCKET                           0xFFFF
 
-#ifndef _WINSOCK2_H
-/* FIXME: Is this behaviour correct?
- * Historically, <winsock.h> defined SOMAXCONN unconditionally, with a
- * value of 5.  However, <winsock2.h> defines it, using a significantly
- * different value, only when compiling native Windows code, and doesn't
- * define it at all, when compiling for Cygwin or MSYS.  To accommodate
- * this difference in philosophy, we must now suppress this definition
- * in <winsock.h>, when <winsock.h> has been included by <winsock2.h>
+#ifndef __INSIDE_MSYS__
+
+/* This definition of SOMAXCONN is correct for WinSock v1.1, but not
+ * for WinSock v2; we define it thus here, but note that, if included
+ * by <winsock2.h>, it will subsequently be overridden by the correct
+ * WinSock v2 definition.
  */
 #define SOMAXCONN                                 5
-#endif /* !_WINSOCK2_H */
-
-#if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
 
 #define MSG_OOB                                   1
 #define MSG_PEEK                                  2
 #define MSG_DONTROUTE                             4
 
-#endif  /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+#endif  /* !__INSIDE_MSYS__ */
 
 #define MSG_MAXIOVLEN                            16
 #define MSG_PARTIAL                          0x8000
 #define MAXGETHOSTSTRUCT                       1024
 
-#define FD_READ                                   1
-#define FD_WRITE                                  2
-#define FD_OOB                                    4
-#define FD_ACCEPT                                 8
-#define FD_CONNECT                               16
-#define FD_CLOSE                                 32
+enum
+{ /* Enumerate the flags used to represent the events which may be
+   * detected on any socket, when monitored via an fd_set array.
+   */
+  FD_READ_BIT = 0,
+# define FD_READ                     (1 << FD_READ_BIT)
+
+  FD_WRITE_BIT,
+# define FD_WRITE                    (1 << FD_WRITE_BIT)
+
+  FD_OOB_BIT,
+# define FD_OOB                      (1 << FD_OOB_BIT)
+
+  FD_ACCEPT_BIT,
+# define FD_ACCEPT                   (1 << FD_ACCEPT_BIT)
+
+  FD_CONNECT_BIT,
+# define FD_CONNECT                  (1 << FD_CONNECT_BIT)
+
+  FD_CLOSE_BIT,
+# define FD_CLOSE                    (1 << FD_CLOSE_BIT)
+
+# ifdef _WINSOCK2_H
+/* WinSock v1.1 defines no further events, beyond FD_CLOSE (1 << 5 = 32).
+ * The following are specific to WinSock v2; for convenience, they may be
+ * enumerated here, but they are exposed only when <winsock.h> is included
+ * indirectly, by way of including <winsock2.h>
+ */
+  FD_QOS_BIT,
+# define FD_QOS                      (1 << FD_QOS_BIT)
+
+  FD_GROUP_QOS_BIT,
+# define FD_GROUP_QOS                (1 << FD_GROUP_QOS_BIT)
+
+  FD_ROUTING_INTERFACE_CHANGE_BIT,
+# define FD_ROUTING_INTERFACE_CHANGE  (1 << FD_ROUTING_INTERFACE_CHANGE_BIT)
+
+  FD_ADDRESS_LIST_CHANGE_BIT,
+# define FD_ADDRESS_LIST_CHANGE       (1 << FD_ADDRESS_LIST_CHANGE_BIT)
+
+# endif /* _WINSOCK2_H */
+  /* Regardless of WinSock version, FD_MAX_EVENTS represents the first
+   * unused flag bit, whence we may deduce FD_ALL_EVENTS, as a mask for
+   * all supported event flags, specific to the WinSock version in use.
+   */
+  FD_MAX_EVENTS,
+# define FD_ALL_EVENTS                 ((1 << FD_MAX_EVENTS) - 1)
+};
 
 #define WSANO_ADDRESS                  WSANO_DATA
 
-#if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
+#ifndef __INSIDE_MSYS__
 
 #define h_errno                        WSAGetLastError()
 #define HOST_NOT_FOUND                 WSAHOST_NOT_FOUND
@@ -536,7 +575,7 @@ struct sockproto
 #define NO_DATA                        WSANO_DATA
 #define NO_ADDRESS                     WSANO_ADDRESS
 
-#endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+#endif /* !__INSIDE_MSYS__ */
 
 WINSOCK_API_LINKAGE SOCKET PASCAL accept (SOCKET, struct sockaddr *, int *);
 
@@ -594,7 +633,7 @@ WINSOCK_API_LINKAGE HANDLE PASCAL WSAAsyncGetHostByAddr (HWND, u_int, const char
 WINSOCK_API_LINKAGE int PASCAL WSACancelAsyncRequest (HANDLE);
 WINSOCK_API_LINKAGE int PASCAL WSAAsyncSelect (SOCKET, HWND, u_int, long);
 
-#if ! (defined __INSIDE_CYGWIN__ || defined __INSIDE_MSYS__)
+#ifndef __INSIDE_MSYS__
 
 WINSOCK_API_LINKAGE u_long PASCAL htonl (u_long);
 WINSOCK_API_LINKAGE u_long PASCAL ntohl (u_long);
@@ -602,13 +641,9 @@ WINSOCK_API_LINKAGE u_short PASCAL htons (u_short);
 WINSOCK_API_LINKAGE u_short PASCAL ntohs (u_short);
 WINSOCK_API_LINKAGE int PASCAL select (int nfds, fd_set *, fd_set *, fd_set *, const struct timeval *);
 
-/* FIXME: <winsock2.h> moves the following declaration out of the
- * !(__INSIDE_CYGWIN__||__INSIDE_MSYS__) filter; which is correct?
- * Furthermore, should this not also have WINSOCK_API_LINKAGE?
- */
-int PASCAL gethostname (char *, int);
+#endif /* !__INSIDE_MSYS__ */
 
-#endif /* ! (__INSIDE_CYGWIN__ || __INSIDE_MSYS__) */
+WINSOCK_API_LINKAGE int PASCAL gethostname (char *, int);
 
 #define WSAMAKEASYNCREPLY(b,e)                 MAKELONG(b,e)
 #define WSAMAKESELECTREPLY(e,error)            MAKELONG(e,error)