alertsock.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_ALERTSOCK_H
  6. #define TOR_ALERTSOCK_H
  7. #include "orconfig.h"
  8. #include "lib/net/nettypes.h"
  9. #include "lib/cc/torint.h"
  10. /** Helper type used to manage waking up the main thread while it's in
  11. * the libevent main loop. Used by the work queue code. */
  12. typedef struct alert_sockets_t {
  13. /* XXXX This structure needs a better name. */
  14. /** Socket that the main thread should listen for EV_READ events on.
  15. * Note that this socket may be a regular fd on a non-Windows platform.
  16. */
  17. tor_socket_t read_fd;
  18. /** Socket to use when alerting the main thread. */
  19. tor_socket_t write_fd;
  20. /** Function to alert the main thread */
  21. int (*alert_fn)(tor_socket_t write_fd);
  22. /** Function to make the main thread no longer alerted. */
  23. int (*drain_fn)(tor_socket_t read_fd);
  24. } alert_sockets_t;
  25. /* Flags to disable one or more alert_sockets backends. */
  26. #define ASOCKS_NOEVENTFD2 (1u<<0)
  27. #define ASOCKS_NOEVENTFD (1u<<1)
  28. #define ASOCKS_NOPIPE2 (1u<<2)
  29. #define ASOCKS_NOPIPE (1u<<3)
  30. #define ASOCKS_NOSOCKETPAIR (1u<<4)
  31. int alert_sockets_create(alert_sockets_t *socks_out, uint32_t flags);
  32. void alert_sockets_close(alert_sockets_t *socks);
  33. #endif