MINOR: sock: provide a set of generic enable/disable functions

These will be used on receivers, to enable or disable receiving on a
listener, which most of the time just consists in enabling/disabling
the file descriptor.

We have to take care of the existence of fd_updt to know if we may
or not call fd_{want,stop}_recv() since it's not permitted in very
early boot.
This commit is contained in:
Willy Tarreau 2020-09-25 19:00:01 +02:00
parent 010fe151ce
commit e70c7977f2
2 changed files with 20 additions and 0 deletions

View File

@ -33,6 +33,8 @@
extern struct xfer_sock_list *xfer_sock_list;
int sock_create_server_socket(struct connection *conn);
void sock_enable(struct receiver *rx);
void sock_disable(struct receiver *rx);
int sock_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
int sock_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
int sock_get_old_sockets(const char *unixsocket);

View File

@ -55,6 +55,24 @@ int sock_create_server_socket(struct connection *conn)
return my_socketat(ns, conn->dst->ss_family, SOCK_STREAM, 0);
}
/* Enables receiving on receiver <rx> once already bound. Does nothing in early
* boot (needs fd_updt).
*/
void sock_enable(struct receiver *rx)
{
if (rx->flags & RX_F_BOUND && fd_updt)
fd_want_recv(rx->fd);
}
/* Disables receiving on receiver <rx> once already bound. Does nothing in early
* boot (needs fd_updt).
*/
void sock_disable(struct receiver *rx)
{
if (rx->flags & RX_F_BOUND && fd_updt)
fd_stop_recv(rx->fd);
}
/*
* Retrieves the source address for the socket <fd>, with <dir> indicating
* if we're a listener (=0) or an initiator (!=0). It returns 0 in case of