mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
MINOR: listeners: introduce listener_set_state()
This function is used as a wrapper to set a listener's state everywhere. We'll use it later to maintain some counters in a consistent state when switching state so it's capital that all state changes go through it. No functional change was made beyond calling the wrapper.
This commit is contained in:
parent
bec7ab0ad9
commit
a37b244509
@ -30,6 +30,9 @@
|
|||||||
#include <haproxy/list.h>
|
#include <haproxy/list.h>
|
||||||
#include <haproxy/listener-t.h>
|
#include <haproxy/listener-t.h>
|
||||||
|
|
||||||
|
/* adjust the listener's state and its proxy's listener counters if needed */
|
||||||
|
void listener_set_state(struct listener *l, enum li_state st);
|
||||||
|
|
||||||
/* This function tries to temporarily disable a listener, depending on the OS
|
/* This function tries to temporarily disable a listener, depending on the OS
|
||||||
* capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
|
* capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
|
||||||
* SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
|
* SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
|
||||||
|
@ -218,6 +218,12 @@ REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
|
|||||||
|
|
||||||
#endif // USE_THREAD
|
#endif // USE_THREAD
|
||||||
|
|
||||||
|
/* adjust the listener's state */
|
||||||
|
void listener_set_state(struct listener *l, enum li_state st)
|
||||||
|
{
|
||||||
|
l->state = st;
|
||||||
|
}
|
||||||
|
|
||||||
/* This function adds the specified listener's file descriptor to the polling
|
/* This function adds the specified listener's file descriptor to the polling
|
||||||
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
|
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
|
||||||
* LI_FULL state depending on its number of connections. In daemon mode, we
|
* LI_FULL state depending on its number of connections. In daemon mode, we
|
||||||
@ -237,15 +243,15 @@ static void enable_listener(struct listener *listener)
|
|||||||
do_unbind_listener(listener, 1);
|
do_unbind_listener(listener, 1);
|
||||||
else {
|
else {
|
||||||
do_unbind_listener(listener, 0);
|
do_unbind_listener(listener, 0);
|
||||||
listener->state = LI_LISTEN;
|
listener_set_state(listener, LI_LISTEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
|
else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
|
||||||
fd_want_recv(listener->rx.fd);
|
fd_want_recv(listener->rx.fd);
|
||||||
listener->state = LI_READY;
|
listener_set_state(listener, LI_READY);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
listener->state = LI_FULL;
|
listener_set_state(listener, LI_FULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* if this listener is supposed to be only in the master, close it in the workers */
|
/* if this listener is supposed to be only in the master, close it in the workers */
|
||||||
@ -269,7 +275,7 @@ static void disable_listener(struct listener *listener)
|
|||||||
if (listener->state == LI_READY)
|
if (listener->state == LI_READY)
|
||||||
fd_stop_recv(listener->rx.fd);
|
fd_stop_recv(listener->rx.fd);
|
||||||
MT_LIST_DEL(&listener->wait_queue);
|
MT_LIST_DEL(&listener->wait_queue);
|
||||||
listener->state = LI_LISTEN;
|
listener_set_state(listener, LI_LISTEN);
|
||||||
end:
|
end:
|
||||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
|
HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
|
||||||
}
|
}
|
||||||
@ -308,7 +314,7 @@ int pause_listener(struct listener *l)
|
|||||||
MT_LIST_DEL(&l->wait_queue);
|
MT_LIST_DEL(&l->wait_queue);
|
||||||
|
|
||||||
fd_stop_recv(l->rx.fd);
|
fd_stop_recv(l->rx.fd);
|
||||||
l->state = LI_PAUSED;
|
listener_set_state(l, LI_PAUSED);
|
||||||
end:
|
end:
|
||||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||||
return ret;
|
return ret;
|
||||||
@ -372,12 +378,12 @@ int resume_listener(struct listener *l)
|
|||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if (l->maxconn && l->nbconn >= l->maxconn) {
|
if (l->maxconn && l->nbconn >= l->maxconn) {
|
||||||
l->state = LI_FULL;
|
listener_set_state(l, LI_FULL);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_want_recv(l->rx.fd);
|
fd_want_recv(l->rx.fd);
|
||||||
l->state = LI_READY;
|
listener_set_state(l, LI_READY);
|
||||||
end:
|
end:
|
||||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||||
return ret;
|
return ret;
|
||||||
@ -393,7 +399,7 @@ static void listener_full(struct listener *l)
|
|||||||
MT_LIST_DEL(&l->wait_queue);
|
MT_LIST_DEL(&l->wait_queue);
|
||||||
if (l->state != LI_FULL) {
|
if (l->state != LI_FULL) {
|
||||||
fd_stop_recv(l->rx.fd);
|
fd_stop_recv(l->rx.fd);
|
||||||
l->state = LI_FULL;
|
listener_set_state(l, LI_FULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||||
@ -408,7 +414,7 @@ static void limit_listener(struct listener *l, struct mt_list *list)
|
|||||||
if (l->state == LI_READY) {
|
if (l->state == LI_READY) {
|
||||||
MT_LIST_TRY_ADDQ(list, &l->wait_queue);
|
MT_LIST_TRY_ADDQ(list, &l->wait_queue);
|
||||||
fd_stop_recv(l->rx.fd);
|
fd_stop_recv(l->rx.fd);
|
||||||
l->state = LI_LIMITED;
|
listener_set_state(l, LI_LIMITED);
|
||||||
}
|
}
|
||||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||||
}
|
}
|
||||||
@ -486,7 +492,7 @@ void do_unbind_listener(struct listener *listener, int do_close)
|
|||||||
MT_LIST_DEL(&listener->wait_queue);
|
MT_LIST_DEL(&listener->wait_queue);
|
||||||
|
|
||||||
if (listener->state >= LI_PAUSED) {
|
if (listener->state >= LI_PAUSED) {
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
fd_stop_both(listener->rx.fd);
|
fd_stop_both(listener->rx.fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +553,7 @@ int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
|
|||||||
l->rx.fd = fd;
|
l->rx.fd = fd;
|
||||||
memcpy(&l->rx.addr, ss, sizeof(*ss));
|
memcpy(&l->rx.addr, ss, sizeof(*ss));
|
||||||
MT_LIST_INIT(&l->wait_queue);
|
MT_LIST_INIT(&l->wait_queue);
|
||||||
l->state = LI_INIT;
|
listener_set_state(l, LI_INIT);
|
||||||
|
|
||||||
proto->add(l, port);
|
proto->add(l, port);
|
||||||
|
|
||||||
@ -575,7 +581,7 @@ void delete_listener(struct listener *listener)
|
|||||||
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
|
||||||
HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
|
HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
|
||||||
if (listener->state == LI_ASSIGNED) {
|
if (listener->state == LI_ASSIGNED) {
|
||||||
listener->state = LI_INIT;
|
listener_set_state(listener, LI_INIT);
|
||||||
LIST_DEL(&listener->rx.proto_list);
|
LIST_DEL(&listener->rx.proto_list);
|
||||||
listener->rx.proto->nb_listeners--;
|
listener->rx.proto->nb_listeners--;
|
||||||
_HA_ATOMIC_SUB(&jobs, 1);
|
_HA_ATOMIC_SUB(&jobs, 1);
|
||||||
|
@ -89,7 +89,7 @@ static void sockpair_add_listener(struct listener *listener, int port)
|
|||||||
{
|
{
|
||||||
if (listener->state != LI_INIT)
|
if (listener->state != LI_INIT)
|
||||||
return;
|
return;
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
listener->rx.proto = &proto_sockpair;
|
listener->rx.proto = &proto_sockpair;
|
||||||
LIST_ADDQ(&proto_sockpair.listeners, &listener->rx.proto_list);
|
LIST_ADDQ(&proto_sockpair.listeners, &listener->rx.proto_list);
|
||||||
proto_sockpair.nb_listeners++;
|
proto_sockpair.nb_listeners++;
|
||||||
@ -175,7 +175,7 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e
|
|||||||
goto err_return;
|
goto err_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
listener->state = LI_LISTEN;
|
listener_set_state(listener, LI_LISTEN);
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err_return:
|
err_return:
|
||||||
|
@ -676,7 +676,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* the socket is ready */
|
/* the socket is ready */
|
||||||
listener->state = LI_LISTEN;
|
listener_set_state(listener, LI_LISTEN);
|
||||||
goto tcp_return;
|
goto tcp_return;
|
||||||
|
|
||||||
tcp_close_return:
|
tcp_close_return:
|
||||||
@ -702,7 +702,7 @@ static void tcpv4_add_listener(struct listener *listener, int port)
|
|||||||
{
|
{
|
||||||
if (listener->state != LI_INIT)
|
if (listener->state != LI_INIT)
|
||||||
return;
|
return;
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
listener->rx.proto = &proto_tcpv4;
|
listener->rx.proto = &proto_tcpv4;
|
||||||
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
||||||
LIST_ADDQ(&proto_tcpv4.listeners, &listener->rx.proto_list);
|
LIST_ADDQ(&proto_tcpv4.listeners, &listener->rx.proto_list);
|
||||||
@ -720,7 +720,7 @@ static void tcpv6_add_listener(struct listener *listener, int port)
|
|||||||
{
|
{
|
||||||
if (listener->state != LI_INIT)
|
if (listener->state != LI_INIT)
|
||||||
return;
|
return;
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
listener->rx.proto = &proto_tcpv6;
|
listener->rx.proto = &proto_tcpv6;
|
||||||
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
||||||
LIST_ADDQ(&proto_tcpv6.listeners, &listener->rx.proto_list);
|
LIST_ADDQ(&proto_tcpv6.listeners, &listener->rx.proto_list);
|
||||||
|
@ -114,7 +114,7 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
|||||||
goto udp_return;
|
goto udp_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
listener->state = LI_LISTEN;
|
listener_set_state(listener, LI_LISTEN);
|
||||||
|
|
||||||
udp_return:
|
udp_return:
|
||||||
if (msg && errlen) {
|
if (msg && errlen) {
|
||||||
@ -134,7 +134,7 @@ static void udp4_add_listener(struct listener *listener, int port)
|
|||||||
{
|
{
|
||||||
if (listener->state != LI_INIT)
|
if (listener->state != LI_INIT)
|
||||||
return;
|
return;
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
listener->rx.proto = &proto_udp4;
|
listener->rx.proto = &proto_udp4;
|
||||||
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
||||||
LIST_ADDQ(&proto_udp4.listeners, &listener->rx.proto_list);
|
LIST_ADDQ(&proto_udp4.listeners, &listener->rx.proto_list);
|
||||||
@ -149,7 +149,7 @@ static void udp6_add_listener(struct listener *listener, int port)
|
|||||||
{
|
{
|
||||||
if (listener->state != LI_INIT)
|
if (listener->state != LI_INIT)
|
||||||
return;
|
return;
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
listener->rx.proto = &proto_udp6;
|
listener->rx.proto = &proto_udp6;
|
||||||
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
((struct sockaddr_in *)(&listener->rx.addr))->sin_port = htons(port);
|
||||||
LIST_ADDQ(&proto_udp6.listeners, &listener->rx.proto_list);
|
LIST_ADDQ(&proto_udp6.listeners, &listener->rx.proto_list);
|
||||||
|
@ -118,7 +118,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* the socket is now listening */
|
/* the socket is now listening */
|
||||||
listener->state = LI_LISTEN;
|
listener_set_state(listener, LI_LISTEN);
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
uxst_close_return:
|
uxst_close_return:
|
||||||
@ -142,7 +142,7 @@ static void uxst_add_listener(struct listener *listener, int port)
|
|||||||
{
|
{
|
||||||
if (listener->state != LI_INIT)
|
if (listener->state != LI_INIT)
|
||||||
return;
|
return;
|
||||||
listener->state = LI_ASSIGNED;
|
listener_set_state(listener, LI_ASSIGNED);
|
||||||
listener->rx.proto = &proto_unix;
|
listener->rx.proto = &proto_unix;
|
||||||
LIST_ADDQ(&proto_unix.listeners, &listener->rx.proto_list);
|
LIST_ADDQ(&proto_unix.listeners, &listener->rx.proto_list);
|
||||||
proto_unix.nb_listeners++;
|
proto_unix.nb_listeners++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user