2
0

select.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include "curl_setup.h"
  25. #ifdef HAVE_SYS_POLL_H
  26. #include <sys/poll.h>
  27. #elif defined(HAVE_POLL_H)
  28. #include <poll.h>
  29. #endif
  30. /*
  31. * Definition of pollfd struct and constants for platforms lacking them.
  32. */
  33. #if !defined(HAVE_STRUCT_POLLFD) && \
  34. !defined(HAVE_SYS_POLL_H) && \
  35. !defined(HAVE_POLL_H)
  36. #define POLLIN 0x01
  37. #define POLLPRI 0x02
  38. #define POLLOUT 0x04
  39. #define POLLERR 0x08
  40. #define POLLHUP 0x10
  41. #define POLLNVAL 0x20
  42. struct pollfd
  43. {
  44. curl_socket_t fd;
  45. short events;
  46. short revents;
  47. };
  48. #endif
  49. #ifndef POLLRDNORM
  50. #define POLLRDNORM POLLIN
  51. #endif
  52. #ifndef POLLWRNORM
  53. #define POLLWRNORM POLLOUT
  54. #endif
  55. #ifndef POLLRDBAND
  56. #define POLLRDBAND POLLPRI
  57. #endif
  58. /* there are three CSELECT defines that are defined in the public header that
  59. are exposed to users, but this *IN2 bit is only ever used internally and
  60. therefore defined here */
  61. #define CURL_CSELECT_IN2 (CURL_CSELECT_ERR << 1)
  62. int Curl_socket_check(curl_socket_t readfd, curl_socket_t readfd2,
  63. curl_socket_t writefd,
  64. long timeout_ms);
  65. /* provide the former API internally */
  66. #define Curl_socket_ready(x,y,z) \
  67. Curl_socket_check(x, CURL_SOCKET_BAD, y, z)
  68. int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms);
  69. /* On non-DOS and non-Winsock platforms, when Curl_ack_eintr is set,
  70. * EINTR condition is honored and function might exit early without
  71. * awaiting full timeout. Otherwise EINTR will be ignored and full
  72. * timeout will elapse. */
  73. extern int Curl_ack_eintr;
  74. int Curl_wait_ms(int timeout_ms);
  75. #ifdef TPF
  76. int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
  77. fd_set* excepts, struct timeval* tv);
  78. #endif
  79. /* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1], which
  80. unfortunately makes it impossible for us to easily check if they're valid
  81. */
  82. #if defined(USE_WINSOCK) || defined(TPF)
  83. #define VALID_SOCK(x) 1
  84. #define VERIFY_SOCK(x) Curl_nop_stmt
  85. #else
  86. #define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE))
  87. #define VERIFY_SOCK(x) do { \
  88. if(!VALID_SOCK(x)) { \
  89. SET_SOCKERRNO(EINVAL); \
  90. return -1; \
  91. } \
  92. } WHILE_FALSE
  93. #endif
  94. #endif /* HEADER_CURL_SELECT_H */