MINOR: protocol: implement an ->rx_resume() method

This one undoes ->rx_suspend(), it tries to restore an operational socket.
It was only implemented for TCP since it's the only one we support right
now.
This commit is contained in:
Willy Tarreau 2020-09-25 19:40:31 +02:00
parent cb66ea60cf
commit 58e6b71bb0
2 changed files with 24 additions and 2 deletions

View File

@ -74,8 +74,9 @@ struct proto_fam {
/* This structure contains all information needed to easily handle a protocol.
* Its primary goal is to ease listeners maintenance. Specifically, the
* bind() primitive must be used before any fork(). rx_* may be null if the
* protocol doesn't provide direct access to the receiver.
* bind() primitive must be used before any fork(). rx_suspend()/rx_resume()
* return >0 on success, 0 if rx stopped, -1 on failure to proceed. rx_* may
* be null if the protocol doesn't provide direct access to the receiver.
*/
struct protocol {
char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */
@ -91,6 +92,7 @@ struct protocol {
/* functions acting on the receiver */
int (*rx_suspend)(struct receiver *rx); /* temporarily suspend this receiver for a soft restart */
int (*rx_resume)(struct receiver *rx); /* try to resume a temporarily suspended receiver */
/* functions acting on connections */
void (*accept)(int fd); /* generic accept function */

View File

@ -46,6 +46,7 @@
static int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen);
static int tcp_suspend_receiver(struct receiver *rx);
static int tcp_resume_receiver(struct receiver *rx);
static void tcpv4_add_listener(struct listener *listener, int port);
static void tcpv6_add_listener(struct listener *listener, int port);
@ -60,6 +61,7 @@ static struct protocol proto_tcpv4 = {
.add = tcpv4_add_listener,
.listen = tcp_bind_listener,
.rx_suspend = tcp_suspend_receiver,
.rx_resume = tcp_resume_receiver,
.accept = &listener_accept,
.connect = tcp_connect_server,
.receivers = LIST_HEAD_INIT(proto_tcpv4.receivers),
@ -79,6 +81,7 @@ static struct protocol proto_tcpv6 = {
.add = tcpv6_add_listener,
.listen = tcp_bind_listener,
.rx_suspend = tcp_suspend_receiver,
.rx_resume = tcp_resume_receiver,
.accept = &listener_accept,
.connect = tcp_connect_server,
.receivers = LIST_HEAD_INIT(proto_tcpv6.receivers),
@ -767,6 +770,23 @@ static int tcp_suspend_receiver(struct receiver *rx)
return -1;
}
/* Resume a receiver. Returns < 0 in case of failure, 0 if the receiver
* was totally stopped, or > 0 if correctly suspended.
*/
static int tcp_resume_receiver(struct receiver *rx)
{
struct listener *l = LIST_ELEM(rx, struct listener *, rx);
if (rx->fd < 0)
return 0;
if (listen(rx->fd, listener_backlog(l)) == 0) {
fd_want_recv(l->rx.fd);
return 1;
}
return -1;
}
/*
* Local variables: