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.
diff --git a/include/haproxy/listener-t.h b/include/haproxy/listener-t.h
index 7a07e3f..2bc0d0c 100644
--- a/include/haproxy/listener-t.h
+++ b/include/haproxy/listener-t.h
@@ -193,8 +193,8 @@
 
 /* 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 @@
 	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 */
diff --git a/src/frontend.c b/src/frontend.c
index 5658a5f..3da48f2 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -111,20 +111,20 @@
 
 		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;
 		}
diff --git a/src/haproxy.c b/src/haproxy.c
index 12a5992..2209517 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2599,7 +2599,7 @@
 			 * 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);
diff --git a/src/listener.c b/src/listener.c
index eac95e2..b62d6fd 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -247,7 +247,7 @@
 			}
 		}
 		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 @@
 	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 @@
 
 	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 @@
 
 	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 @@
 		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 @@
 	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 @@
 	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 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 @@
 		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 @@
 		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;
diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c
index ff7c0a2..c736995 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -93,7 +93,7 @@
  */
 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 @@
 	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;
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index a338ad8..a97cdc3 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -569,15 +569,15 @@
 
 	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 @@
 #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 @@
  */
 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;
 }
diff --git a/src/proto_udp.c b/src/proto_udp.c
index 7d190a1..38be905 100644
--- a/src/proto_udp.c
+++ b/src/proto_udp.c
@@ -275,7 +275,7 @@
 	}
 
 	/* the socket is ready */
-	listener->fd = fd;
+	listener->rx.fd = fd;
 	listener->state = LI_LISTEN;
 
 	if (listener->bind_conf->frontend->mode == PR_MODE_SYSLOG)
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index 33768a1..9b5a28d 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -109,9 +109,8 @@
 	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 @@
 	 * 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 @@
 		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,
diff --git a/src/proxy.c b/src/proxy.c
index dda701c..3f25dac 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1245,7 +1245,7 @@
 			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;
 			}
 		}