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