alertsock.h 1.4 KB

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