mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-20 12:40:46 +00:00
REORG: listener: move the receiving FD to struct receiver
The listening socket is represented by its file descriptor, which is generic to all receivers and not just listeners, so it must move to the rx struct. It's worth noting that in order to extend receivers and listeners to other protocols such as QUIC, we'll need other handles than file descriptors here, and that either a union or a cast to uintptr_t will have to be used. This was not done yet and the field was preserved under the name "fd" to avoid adding confusion.
This commit is contained in:
parent
371590661e
commit
38ba647f9f
@ -193,8 +193,8 @@ struct bind_conf {
|
||||
|
||||
/* This describes a receiver with all its characteristics (address, status, etc) */
|
||||
struct receiver {
|
||||
int fd; /* handle we receive from (fd only for now) */
|
||||
unsigned int flags; /* receiver options (RX_F_*) */
|
||||
|
||||
/* warning: this struct is huge, keep it at the bottom */
|
||||
struct sockaddr_storage addr; /* the address the socket is bound to */
|
||||
};
|
||||
@ -207,7 +207,6 @@ struct listener {
|
||||
enum obj_type obj_type; /* object type = OBJ_TYPE_LISTENER */
|
||||
enum li_state state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */
|
||||
short int nice; /* nice value to assign to the instantiated tasks */
|
||||
int fd; /* the listen socket */
|
||||
int luid; /* listener universally unique ID, used for SNMP */
|
||||
int options; /* socket options : LI_O_* */
|
||||
struct fe_counters *counters; /* statistics counters */
|
||||
|
@ -111,20 +111,20 @@ int frontend_accept(struct stream *s)
|
||||
|
||||
if (!conn_get_src(conn)) {
|
||||
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n",
|
||||
s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
|
||||
s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
|
||||
l->luid, alpn);
|
||||
}
|
||||
else switch (addr_to_str(conn->src, pn, sizeof(pn))) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n",
|
||||
s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
|
||||
s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
|
||||
pn, get_host_port(conn->src), alpn);
|
||||
break;
|
||||
case AF_UNIX:
|
||||
/* UNIX socket, only the destination is known */
|
||||
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d] ALPN=%s\n",
|
||||
s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
|
||||
s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
|
||||
l->luid, alpn);
|
||||
break;
|
||||
}
|
||||
|
@ -2599,7 +2599,7 @@ void deinit(void)
|
||||
* Close it and give the listener its real state.
|
||||
*/
|
||||
if (p->state == PR_STSTOPPED && l->state >= LI_ZOMBIE) {
|
||||
close(l->fd);
|
||||
close(l->rx.fd);
|
||||
l->state = LI_INIT;
|
||||
}
|
||||
unbind_listener(l);
|
||||
|
@ -247,7 +247,7 @@ static void enable_listener(struct listener *listener)
|
||||
}
|
||||
}
|
||||
else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
|
||||
fd_want_recv(listener->fd);
|
||||
fd_want_recv(listener->rx.fd);
|
||||
listener->state = LI_READY;
|
||||
}
|
||||
else {
|
||||
@ -273,7 +273,7 @@ static void disable_listener(struct listener *listener)
|
||||
if (listener->state < LI_READY)
|
||||
goto end;
|
||||
if (listener->state == LI_READY)
|
||||
fd_stop_recv(listener->fd);
|
||||
fd_stop_recv(listener->rx.fd);
|
||||
MT_LIST_DEL(&listener->wait_queue);
|
||||
listener->state = LI_LISTEN;
|
||||
end:
|
||||
@ -312,7 +312,7 @@ int pause_listener(struct listener *l)
|
||||
|
||||
MT_LIST_DEL(&l->wait_queue);
|
||||
|
||||
fd_stop_recv(l->fd);
|
||||
fd_stop_recv(l->rx.fd);
|
||||
l->state = LI_PAUSED;
|
||||
end:
|
||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||
@ -368,7 +368,7 @@ int resume_listener(struct listener *l)
|
||||
|
||||
if (l->proto->sock_prot == IPPROTO_TCP &&
|
||||
l->state == LI_PAUSED &&
|
||||
listen(l->fd, listener_backlog(l)) != 0) {
|
||||
listen(l->rx.fd, listener_backlog(l)) != 0) {
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
@ -392,7 +392,7 @@ int resume_listener(struct listener *l)
|
||||
goto end;
|
||||
}
|
||||
|
||||
fd_want_recv(l->fd);
|
||||
fd_want_recv(l->rx.fd);
|
||||
l->state = LI_READY;
|
||||
end:
|
||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||
@ -408,7 +408,7 @@ static void listener_full(struct listener *l)
|
||||
if (l->state >= LI_READY) {
|
||||
MT_LIST_DEL(&l->wait_queue);
|
||||
if (l->state != LI_FULL) {
|
||||
fd_stop_recv(l->fd);
|
||||
fd_stop_recv(l->rx.fd);
|
||||
l->state = LI_FULL;
|
||||
}
|
||||
}
|
||||
@ -423,7 +423,7 @@ static void limit_listener(struct listener *l, struct mt_list *list)
|
||||
HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
|
||||
if (l->state == LI_READY) {
|
||||
MT_LIST_TRY_ADDQ(list, &l->wait_queue);
|
||||
fd_stop_recv(l->fd);
|
||||
fd_stop_recv(l->rx.fd);
|
||||
l->state = LI_LIMITED;
|
||||
}
|
||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||
@ -496,16 +496,16 @@ void dequeue_proxy_listeners(struct proxy *px)
|
||||
void do_unbind_listener(struct listener *listener, int do_close)
|
||||
{
|
||||
if (listener->state == LI_READY && fd_updt)
|
||||
fd_stop_recv(listener->fd);
|
||||
fd_stop_recv(listener->rx.fd);
|
||||
|
||||
MT_LIST_DEL(&listener->wait_queue);
|
||||
|
||||
if (listener->state >= LI_PAUSED) {
|
||||
listener->state = LI_ASSIGNED;
|
||||
fd_stop_both(listener->fd);
|
||||
fd_stop_both(listener->rx.fd);
|
||||
if (do_close) {
|
||||
fd_delete(listener->fd);
|
||||
listener->fd = -1;
|
||||
fd_delete(listener->rx.fd);
|
||||
listener->rx.fd = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -564,7 +564,7 @@ int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
|
||||
LIST_ADDQ(&bc->listeners, &l->by_bind);
|
||||
l->bind_conf = bc;
|
||||
|
||||
l->fd = fd;
|
||||
l->rx.fd = fd;
|
||||
memcpy(&l->rx.addr, ss, sizeof(*ss));
|
||||
MT_LIST_INIT(&l->wait_queue);
|
||||
l->state = LI_INIT;
|
||||
@ -1059,7 +1059,7 @@ void listener_accept(int fd)
|
||||
else
|
||||
fd_done_recv(fd);
|
||||
} else if (l->state > LI_ASSIGNED) {
|
||||
fd_stop_recv(l->fd);
|
||||
fd_stop_recv(l->rx.fd);
|
||||
}
|
||||
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
|
||||
return;
|
||||
|
@ -93,7 +93,7 @@ static void sockpair_add_listener(struct listener *listener, int port)
|
||||
*/
|
||||
static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
{
|
||||
int fd = listener->fd;
|
||||
int fd = listener->rx.fd;
|
||||
int err;
|
||||
const char *msg = NULL;
|
||||
|
||||
@ -106,7 +106,7 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e
|
||||
if (listener->state != LI_ASSIGNED)
|
||||
return ERR_NONE; /* already bound */
|
||||
|
||||
if (listener->fd == -1) {
|
||||
if (listener->rx.fd == -1) {
|
||||
err |= ERR_FATAL | ERR_ALERT;
|
||||
msg = "sockpair can be only used with inherited FDs";
|
||||
goto err_return;
|
||||
|
@ -569,15 +569,15 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
|
||||
err = ERR_NONE;
|
||||
|
||||
if (listener->fd == -1)
|
||||
listener->fd = sock_find_compatible_fd(listener);
|
||||
if (listener->rx.fd == -1)
|
||||
listener->rx.fd = sock_find_compatible_fd(listener);
|
||||
|
||||
/* if the listener already has an fd assigned, then we were offered the
|
||||
* fd by an external process (most likely the parent), and we don't want
|
||||
* to create a new socket. However we still want to set a few flags on
|
||||
* the socket.
|
||||
*/
|
||||
fd = listener->fd;
|
||||
fd = listener->rx.fd;
|
||||
ext = (fd >= 0);
|
||||
|
||||
if (!ext) {
|
||||
@ -765,7 +765,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
#endif
|
||||
|
||||
/* the socket is ready */
|
||||
listener->fd = fd;
|
||||
listener->rx.fd = fd;
|
||||
listener->state = LI_LISTEN;
|
||||
|
||||
fd_insert(fd, listener, listener->proto->accept,
|
||||
@ -830,13 +830,13 @@ static void tcpv6_add_listener(struct listener *listener, int port)
|
||||
*/
|
||||
int tcp_pause_listener(struct listener *l)
|
||||
{
|
||||
if (shutdown(l->fd, SHUT_WR) != 0)
|
||||
if (shutdown(l->rx.fd, SHUT_WR) != 0)
|
||||
return -1; /* Solaris dies here */
|
||||
|
||||
if (listen(l->fd, listener_backlog(l)) != 0)
|
||||
if (listen(l->rx.fd, listener_backlog(l)) != 0)
|
||||
return -1; /* OpenBSD dies here */
|
||||
|
||||
if (shutdown(l->fd, SHUT_RD) != 0)
|
||||
if (shutdown(l->rx.fd, SHUT_RD) != 0)
|
||||
return -1; /* should always be OK */
|
||||
return 1;
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
}
|
||||
|
||||
/* the socket is ready */
|
||||
listener->fd = fd;
|
||||
listener->rx.fd = fd;
|
||||
listener->state = LI_LISTEN;
|
||||
|
||||
if (listener->bind_conf->frontend->mode == PR_MODE_SYSLOG)
|
||||
|
@ -109,9 +109,8 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
||||
if (listener->state != LI_ASSIGNED)
|
||||
return ERR_NONE; /* already bound */
|
||||
|
||||
if (listener->fd == -1)
|
||||
listener->fd = sock_find_compatible_fd(listener);
|
||||
|
||||
if (listener->rx.fd == -1)
|
||||
listener->rx.fd = sock_find_compatible_fd(listener);
|
||||
path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path;
|
||||
|
||||
maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path));
|
||||
@ -121,7 +120,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
||||
* to create a new socket. However we still want to set a few flags on
|
||||
* the socket.
|
||||
*/
|
||||
fd = listener->fd;
|
||||
fd = listener->rx.fd;
|
||||
ext = (fd >= 0);
|
||||
if (ext)
|
||||
goto fd_ready;
|
||||
@ -259,7 +258,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
||||
unlink(backname);
|
||||
|
||||
/* the socket is now listening */
|
||||
listener->fd = fd;
|
||||
listener->rx.fd = fd;
|
||||
listener->state = LI_LISTEN;
|
||||
|
||||
fd_insert(fd, listener, listener->proto->accept,
|
||||
|
@ -1245,7 +1245,7 @@ void soft_stop(void)
|
||||
struct listener *l;
|
||||
list_for_each_entry(l, &p->conf.listeners, by_fe) {
|
||||
if (l->state > LI_ASSIGNED)
|
||||
close(l->fd);
|
||||
close(l->rx.fd);
|
||||
l->state = LI_INIT;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user