OSDN Git Service

* fhandler.h: Add comment.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / select.h
1 /* select.h
2
3    Copyright 1998 Cygnus Solutions.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 /* Winsock select() types and macros */
12
13 /*
14  * Use this struct to interface to
15  * the system provided select.
16  */
17 typedef struct winsock_fd_set
18 {
19   unsigned int fd_count;
20   HANDLE fd_array[1024]; /* Dynamically allocated. */
21 } winsock_fd_set;
22
23 /*
24  * Define the Win32 winsock definitions to have a prefix WINSOCK_
25  * so we can be explicit when we are using them.
26  */
27 #define WINSOCK_FD_ISSET(fd, set) __WSAFDIsSet ((SOCKET)fd, (fd_set *)set)
28 #define WINSOCK_FD_SET(fd, set) do { \
29                (set)->fd_array[(set)->fd_count++]=fd;\
30 } while(0)
31 #define WINSOCK_FD_ZERO(set) ((set)->fd_count = 0)
32 #define WINSOCK_FD_CLR(fd, set) do { \
33     u_int __i; \
34     for (__i = 0; __i < (set)->fd_count ; __i++) { \
35         if ((set)->fd_array[__i] == fd) { \
36             while (__i < (set)->fd_count-1) { \
37                 (set)->fd_array[__i] = \
38                     (set)->fd_array[__i+1]; \
39                 __i++; \
40             } \
41             (set)->fd_count--; \
42             break; \
43         } \
44     } \
45 } while(0)
46
47 extern "C" int PASCAL __WSAFDIsSet(SOCKET, fd_set*);
48 extern "C" int PASCAL win32_select(int, fd_set*, fd_set*, fd_set*, const struct timeval*);
49
50 /*
51  * call to winsock's select() -
52  * type coercion need to appease confused prototypes
53  */
54 #define WINSOCK_SELECT(nfd, rd, wr, ex, timeo) \
55     win32_select (nfd, (fd_set *)rd, (fd_set *)wr, (fd_set *)ex, timeo)
56