MINOR: sock: implement sock_find_compatible_fd()
This is essentially a merge from tcp_find_compatible_fd() and
uxst_find_compatible_fd() that relies on a listener's address and
compare function and still checks for other variations. For AF_INET6
it compares a few of the listener's bind options. A minor change for
UNIX sockets is that transparent mode, interface and namespace used
to be ignored when trying to pick a previous socket while now if they
are changed, the socket will not be reused. This could be refined but
it's still better this way as there is no more risk of using a
differently bound socket by accident.
Eventually we should not pass a listener there but a set of binding
parameters (address, interface, namespace etc...) which ultimately will
be grouped into a receiver. For now this still doesn't exist so let's
stick to the listener to break dependencies in the rest of the code.
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index f0cf999..2c3e202 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -83,36 +83,6 @@
* 2) listener-oriented functions
********************************/
-
-static int uxst_find_compatible_fd(struct listener *l)
-{
- struct xfer_sock_list *xfer_sock = xfer_sock_list;
- int ret = -1;
-
- while (xfer_sock) {
- /*
- * The bound socket's path as returned by getsockaddr
- * will be the temporary name <sockname>.XXXXX.tmp,
- * so we can't just compare the two names
- */
- if (!l->proto->addrcmp(&xfer_sock->addr, &l->addr))
- break;
- xfer_sock = xfer_sock->next;
- }
- if (xfer_sock != NULL) {
- ret = xfer_sock->fd;
- if (xfer_sock == xfer_sock_list)
- xfer_sock_list = xfer_sock->next;
- if (xfer_sock->prev)
- xfer_sock->prev->next = xfer_sock->next;
- if (xfer_sock->next)
- xfer_sock->next->prev = xfer_sock->prev;
- free(xfer_sock);
- }
- return ret;
-
-}
-
/* This function creates a UNIX socket associated to the listener. It changes
* the state from ASSIGNED to LISTEN. The socket is NOT enabled for polling.
* The return value is composed from ERR_NONE, ERR_RETRYABLE and ERR_FATAL. It
@@ -144,7 +114,8 @@
return ERR_NONE; /* already bound */
if (listener->fd == -1)
- listener->fd = uxst_find_compatible_fd(listener);
+ listener->fd = sock_find_compatible_fd(listener);
+
path = ((struct sockaddr_un *)&listener->addr)->sun_path;
maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path));