1 #ifndef HEADER_CURL_SELECT_H 2 #define HEADER_CURL_SELECT_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at http://curl.haxx.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 ***************************************************************************/ 24 25 #include "curl_setup.h" 26 27 #ifdef HAVE_SYS_POLL_H 28 #include <sys/poll.h> 29 #elif defined(HAVE_POLL_H) 30 #include <poll.h> 31 #endif 32 33 /* 34 * Definition of pollfd struct and constants for platforms lacking them. 35 */ 36 37 #if !defined(HAVE_STRUCT_POLLFD) && \ 38 !defined(HAVE_SYS_POLL_H) && \ 39 !defined(HAVE_POLL_H) 40 41 #define POLLIN 0x01 42 #define POLLPRI 0x02 43 #define POLLOUT 0x04 44 #define POLLERR 0x08 45 #define POLLHUP 0x10 46 #define POLLNVAL 0x20 47 48 struct pollfd 49 { 50 curl_socket_t fd; 51 short events; 52 short revents; 53 }; 54 55 #endif 56 57 #ifndef POLLRDNORM 58 #define POLLRDNORM POLLIN 59 #endif 60 61 #ifndef POLLWRNORM 62 #define POLLWRNORM POLLOUT 63 #endif 64 65 #ifndef POLLRDBAND 66 #define POLLRDBAND POLLPRI 67 #endif 68 69 /* there are three CSELECT defines that are defined in the public header that 70 are exposed to users, but this *IN2 bit is only ever used internally and 71 therefore defined here */ 72 #define CURL_CSELECT_IN2 (CURL_CSELECT_ERR << 1) 73 74 int Curl_socket_check(curl_socket_t readfd, curl_socket_t readfd2, 75 curl_socket_t writefd, 76 long timeout_ms); 77 78 /* provide the former API internally */ 79 #define Curl_socket_ready(x,y,z) \ 80 Curl_socket_check(x, CURL_SOCKET_BAD, y, z) 81 82 int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms); 83 84 /* On non-DOS and non-Winsock platforms, when Curl_ack_eintr is set, 85 * EINTR condition is honored and function might exit early without 86 * awaiting full timeout. Otherwise EINTR will be ignored and full 87 * timeout will elapse. */ 88 extern int Curl_ack_eintr; 89 90 int Curl_wait_ms(int timeout_ms); 91 92 #ifdef TPF 93 int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes, 94 fd_set* excepts, struct timeval* tv); 95 #endif 96 97 /* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1], which 98 unfortunately makes it impossible for us to easily check if they're valid 99 */ 100 #if defined(USE_WINSOCK) || defined(TPF) 101 #define VALID_SOCK(x) 1 102 #define VERIFY_SOCK(x) Curl_nop_stmt 103 #else 104 #define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE)) 105 #define VERIFY_SOCK(x) do { \ 106 if(!VALID_SOCK(x)) { \ 107 SET_SOCKERRNO(EINVAL); \ 108 return -1; \ 109 } \ 110 } WHILE_FALSE 111 #endif 112 113 #endif /* HEADER_CURL_SELECT_H */ 114 115