Tor  0.4.7.0-alpha-dev
Functions
alertsock.c File Reference

Use a socket to alert the main thread from a worker thread. More...

#include "orconfig.h"
#include "lib/net/alertsock.h"
#include "lib/net/socket.h"
#include "lib/log/util_bug.h"

Go to the source code of this file.

Functions

static int send_ni (int fd, const void *buf, size_t n, int flags)
 
static int recv_ni (int fd, void *buf, size_t n, int flags)
 
static int sock_alert (tor_socket_t fd)
 
static int sock_drain (tor_socket_t fd)
 
int alert_sockets_create (alert_sockets_t *socks_out, uint32_t flags)
 
void alert_sockets_close (alert_sockets_t *socks)
 

Detailed Description

Use a socket to alert the main thread from a worker thread.

Because our main loop spends all of its time in select, epoll, kqueue, or etc, we need a way to wake up the main loop from another thread. This code tries to provide the fastest reasonable way to do that, depending on our platform.

Definition in file alertsock.c.

Function Documentation

◆ alert_sockets_close()

void alert_sockets_close ( alert_sockets_t socks)

Close the sockets in socks.

Definition at line 283 of file alertsock.c.

◆ alert_sockets_create()

int alert_sockets_create ( alert_sockets_t socks_out,
uint32_t  flags 
)

Allocate a new set of alert sockets, and set the appropriate function pointers, in socks_out.

Definition at line 191 of file alertsock.c.

◆ recv_ni()

static int recv_ni ( int  fd,
void *  buf,
size_t  n,
int  flags 
)
static

As recv(), but retry on EINTR, and return the negative error code on error.

Definition at line 94 of file alertsock.c.

Referenced by sock_drain().

◆ send_ni()

static int send_ni ( int  fd,
const void *  buf,
size_t  n,
int  flags 
)
static

As send(), but retry on EINTR, and return the negative error code on error.

Definition at line 76 of file alertsock.c.

Referenced by sock_alert().

◆ sock_alert()

static int sock_alert ( tor_socket_t  fd)
static

Send a byte on socket fdt. Return 0 on success or EAGAIN, -1 on error.

Definition at line 164 of file alertsock.c.

Referenced by alert_sockets_close().

◆ sock_drain()

static int sock_drain ( tor_socket_t  fd)
static

Drain all the input from a socket fd, and ignore it. Return 0 on success, -errno on error.

Definition at line 175 of file alertsock.c.