mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-15 07:54:33 +00:00
MINOR: protocol: add a new pair of enable/disable methods for listeners
These methods will be used to enable/disable accepting new connections so that listeners do not play with FD directly anymore. Since all the currently supported protocols work on socket for now, these are identical to the rx_enable/rx_disable functions. However they were not defined in sock.c since it's likely that some will quickly start to differ. At the moment they're not used. We have to take care of fd_updt before calling fd_{want,stop}_recv() because it's allocated fairly late in the boot process and some such functions may be called very early (e.g. to stop a disabled frontend's listeners).
This commit is contained in:
parent
686fa3db50
commit
5ddf1ce9c4
@ -89,6 +89,8 @@ struct protocol {
|
||||
/* functions acting on the listener */
|
||||
void (*add)(struct listener *l, int port); /* add a listener for this protocol and port */
|
||||
int (*listen)(struct listener *l, char *errmsg, int errlen); /* start a listener */
|
||||
void (*enable)(struct listener *l); /* enable receipt of new connections */
|
||||
void (*disable)(struct listener *l); /* disable receipt of new connections */
|
||||
|
||||
/* functions acting on the receiver */
|
||||
void (*rx_enable)(struct receiver *rx); /* enable receiving on the receiver */
|
||||
|
@ -44,6 +44,8 @@
|
||||
|
||||
static void sockpair_add_listener(struct listener *listener, int port);
|
||||
static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen);
|
||||
static void sockpair_enable_listener(struct listener *listener);
|
||||
static void sockpair_disable_listener(struct listener *listener);
|
||||
static int sockpair_connect_server(struct connection *conn, int flags);
|
||||
|
||||
struct proto_fam proto_fam_sockpair = {
|
||||
@ -68,6 +70,8 @@ static struct protocol proto_sockpair = {
|
||||
.sock_prot = 0,
|
||||
.add = sockpair_add_listener,
|
||||
.listen = sockpair_bind_listener,
|
||||
.enable = sockpair_enable_listener,
|
||||
.disable = sockpair_disable_listener,
|
||||
.rx_enable = sock_enable,
|
||||
.rx_disable = sock_disable,
|
||||
.accept = &listener_accept,
|
||||
@ -95,6 +99,24 @@ static void sockpair_add_listener(struct listener *listener, int port)
|
||||
proto_sockpair.nb_receivers++;
|
||||
}
|
||||
|
||||
/* Enable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void sockpair_enable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_want_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Disable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void sockpair_disable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_stop_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Binds receiver <rx>, and assigns <handler> and rx->owner as the callback and
|
||||
* context, respectively, with <tm> as the thread mask. Returns and error code
|
||||
* made of ERR_* bits on failure or ERR_NONE on success. On failure, an error
|
||||
|
@ -47,6 +47,8 @@
|
||||
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 tcp_enable_listener(struct listener *listener);
|
||||
static void tcp_disable_listener(struct listener *listener);
|
||||
static void tcpv4_add_listener(struct listener *listener, int port);
|
||||
static void tcpv6_add_listener(struct listener *listener, int port);
|
||||
|
||||
@ -60,6 +62,8 @@ static struct protocol proto_tcpv4 = {
|
||||
.sock_prot = IPPROTO_TCP,
|
||||
.add = tcpv4_add_listener,
|
||||
.listen = tcp_bind_listener,
|
||||
.enable = tcp_enable_listener,
|
||||
.disable = tcp_disable_listener,
|
||||
.rx_enable = sock_enable,
|
||||
.rx_disable = sock_disable,
|
||||
.rx_suspend = tcp_suspend_receiver,
|
||||
@ -82,6 +86,8 @@ static struct protocol proto_tcpv6 = {
|
||||
.sock_prot = IPPROTO_TCP,
|
||||
.add = tcpv6_add_listener,
|
||||
.listen = tcp_bind_listener,
|
||||
.enable = tcp_enable_listener,
|
||||
.disable = tcp_disable_listener,
|
||||
.rx_enable = sock_enable,
|
||||
.rx_disable = sock_disable,
|
||||
.rx_suspend = tcp_suspend_receiver,
|
||||
@ -733,6 +739,24 @@ static void tcpv6_add_listener(struct listener *listener, int port)
|
||||
proto_tcpv6.nb_receivers++;
|
||||
}
|
||||
|
||||
/* Enable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void tcp_enable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_want_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Disable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void tcp_disable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_stop_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver
|
||||
* was totally stopped, or > 0 if correctly suspended.
|
||||
*/
|
||||
|
@ -42,6 +42,8 @@
|
||||
|
||||
static int udp_bind_listener(struct listener *listener, char *errmsg, int errlen);
|
||||
static int udp_suspend_receiver(struct receiver *rx);
|
||||
static void udp_enable_listener(struct listener *listener);
|
||||
static void udp_disable_listener(struct listener *listener);
|
||||
static void udp4_add_listener(struct listener *listener, int port);
|
||||
static void udp6_add_listener(struct listener *listener, int port);
|
||||
|
||||
@ -55,6 +57,8 @@ static struct protocol proto_udp4 = {
|
||||
.sock_prot = IPPROTO_UDP,
|
||||
.add = udp4_add_listener,
|
||||
.listen = udp_bind_listener,
|
||||
.enable = udp_enable_listener,
|
||||
.disable = udp_disable_listener,
|
||||
.rx_enable = sock_enable,
|
||||
.rx_disable = sock_disable,
|
||||
.rx_suspend = udp_suspend_receiver,
|
||||
@ -74,6 +78,8 @@ static struct protocol proto_udp6 = {
|
||||
.sock_prot = IPPROTO_UDP,
|
||||
.add = udp6_add_listener,
|
||||
.listen = udp_bind_listener,
|
||||
.enable = udp_enable_listener,
|
||||
.disable = udp_disable_listener,
|
||||
.rx_enable = sock_enable,
|
||||
.rx_disable = sock_disable,
|
||||
.rx_suspend = udp_suspend_receiver,
|
||||
@ -155,6 +161,24 @@ static void udp6_add_listener(struct listener *listener, int port)
|
||||
proto_udp6.nb_receivers++;
|
||||
}
|
||||
|
||||
/* Enable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void udp_enable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_want_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Disable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void udp_disable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_stop_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver
|
||||
* was totally stopped, or > 0 if correctly suspended.
|
||||
*/
|
||||
|
@ -43,6 +43,8 @@
|
||||
static int uxst_bind_listener(struct listener *listener, char *errmsg, int errlen);
|
||||
static int uxst_connect_server(struct connection *conn, int flags);
|
||||
static void uxst_add_listener(struct listener *listener, int port);
|
||||
static void uxst_enable_listener(struct listener *listener);
|
||||
static void uxst_disable_listener(struct listener *listener);
|
||||
static int uxst_suspend_receiver(struct receiver *rx);
|
||||
|
||||
/* Note: must not be declared <const> as its list will be overwritten */
|
||||
@ -55,6 +57,8 @@ static struct protocol proto_unix = {
|
||||
.sock_prot = 0,
|
||||
.add = uxst_add_listener,
|
||||
.listen = uxst_bind_listener,
|
||||
.enable = uxst_enable_listener,
|
||||
.disable = uxst_disable_listener,
|
||||
.rx_enable = sock_enable,
|
||||
.rx_disable = sock_disable,
|
||||
.rx_suspend = uxst_suspend_receiver,
|
||||
@ -148,6 +152,24 @@ static void uxst_add_listener(struct listener *listener, int port)
|
||||
proto_unix.nb_receivers++;
|
||||
}
|
||||
|
||||
/* Enable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void uxst_enable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_want_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Disable receipt of incoming connections for listener <l>. The receiver must
|
||||
* still be valid. Does nothing in early boot (needs fd_updt).
|
||||
*/
|
||||
static void uxst_disable_listener(struct listener *l)
|
||||
{
|
||||
if (fd_updt)
|
||||
fd_stop_recv(l->rx.fd);
|
||||
}
|
||||
|
||||
/* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver
|
||||
* was totally stopped, or > 0 if correctly suspended. Nothing is done for
|
||||
* plain unix sockets since currently it's the new process which handles
|
||||
|
Loading…
Reference in New Issue
Block a user