fakepoll.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2002,2003 Nick Mathewson, Roger Dingledine. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. #ifndef __FAKEPOLL_H
  5. #define __FAKEPOLL_H
  6. #define FAKEPOLL_H_ID "$Id$"
  7. /**
  8. * \file fakepoll.h
  9. * \brief Headers for fakepoll.c
  10. */
  11. #include "orconfig.h"
  12. #define POLL_NO_WARN
  13. #if defined(HAVE_POLL_H)
  14. #include <poll.h>
  15. #elif defined(HAVE_SYS_POLL_H)
  16. #include <sys/poll.h>
  17. #endif
  18. /* If _POLL_EMUL_H_ is defined, then poll is just a just a thin wrapper around
  19. * select. On Mac OS 10.3, this wrapper is kinda flaky, and we should
  20. * use our own.
  21. */
  22. #if !(defined(HAVE_POLL_H)||defined(HAVE_SYS_POLL_H))&&!defined(_POLL_EMUL_H_)
  23. #define USE_FAKE_POLL
  24. #endif
  25. #if defined USE_FAKE_POLL && !defined(_POLL_EMUL_H_)
  26. struct pollfd {
  27. int fd;
  28. short events;
  29. short revents;
  30. };
  31. #define POLLIN 0x0001
  32. #define POLLPRI 0x0002
  33. #define POLLOUT 0x0004
  34. #define POLLERR 0x0008
  35. #define POLLHUP 0x0010
  36. #define POLLNVAL 0x0020
  37. #endif
  38. #ifdef MS_WINDOWS
  39. #define MAXCONNECTIONS 10000 /* XXXX copied from or.h */
  40. /* This trick makes winsock resize fd_set, which defaults to the insanely low
  41. * 64. */
  42. #define FD_SETSIZE MAXCONNECTIONS
  43. /* XXXX But Windows FD_SET and FD_CLR are tremendously ugly, and linear in
  44. * the total number of sockets set! Perhaps we should eventually use
  45. * WSAEventSelect and WSAWaitForMultipleEvents instead of select? */
  46. #endif
  47. #if defined(MS_WINDOWS) || ! defined(USE_FAKE_POLL)
  48. /* If we're using poll, we can poll as many sockets as we want.
  49. * If we're on Windows, having too many sockets is harmless, since
  50. * select stupidly uses an array of sockets rather than a bitfield. */
  51. #define SOCKET_IS_POLLABLE(fd) ((fd) >= 0)
  52. #else
  53. /* If we're using a real Posix select, then in order to be pollable, a socket
  54. * must
  55. * a) be valid (>= 0)
  56. * b) be < FD_SETSIZE.
  57. */
  58. #define SOCKET_IS_POLLABLE(fd) ((fd) >= 0 && (fd) < FD_SETSIZE)
  59. #endif
  60. int tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout);
  61. #endif