#include <haproxy/namespace-t.h>
#include <haproxy/thread.h>
+/* Bit values for receiver->options */
+#define RX_F_BOUND 0x00000001 /* receiver already bound */
+
/* All the settings that are used to configure a receiver */
struct rx_settings {
unsigned long bind_proc; /* bitmask of processes allowed to use these listeners */
fd_stop_both(listener->rx.fd);
if (do_close) {
fd_delete(listener->rx.fd);
+ listener->rx.flags &= ~RX_F_BOUND;
listener->rx.fd = -1;
}
}
if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */
+ if (listener->rx.flags & RX_F_BOUND)
+ goto bound;
+
if (listener->rx.fd == -1) {
err |= ERR_FATAL | ERR_ALERT;
msg = "sockpair can be only used with inherited FDs";
msg = "cannot make sockpair non-blocking";
goto err_return;
}
+ listener->rx.flags |= RX_F_BOUND;
+ bound:
listener->state = LI_LISTEN;
fd_insert(fd, listener, listener->rx.proto->accept,
err = ERR_NONE;
+ if (listener->rx.flags & RX_F_BOUND)
+ goto bound;
+
if (listener->rx.fd == -1)
listener->rx.fd = sock_find_compatible_fd(listener);
msg = "cannot bind socket";
goto tcp_close_return;
}
+ listener->rx.flags |= RX_F_BOUND;
+ bound:
ready = 0;
ready_len = sizeof(ready);
if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &ready, &ready_len) == -1)
err = ERR_NONE;
+ if (listener->rx.flags & RX_F_BOUND)
+ goto bound;
+
/* TODO: Implement reuse fd. Take care that to identify fd to reuse
* listeners uses a special AF_CUST_ family and we MUST consider
* IPPROTO (sockaddr is not enough)
msg = "cannot bind socket";
goto udp_close_return;
}
+ listener->rx.flags |= RX_F_BOUND;
+ bound:
/* the socket is ready */
listener->rx.fd = fd;
listener->state = LI_LISTEN;
if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */
+ if (listener->rx.flags & RX_F_BOUND)
+ goto bound;
+
if (listener->rx.fd == -1)
listener->rx.fd = sock_find_compatible_fd(listener);
path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path;
msg = "cannot change UNIX socket ownership";
goto err_unlink_temp;
}
+ listener->rx.flags |= RX_F_BOUND;
+ bound:
ready = 0;
ready_len = sizeof(ready);
if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &ready, &ready_len) == -1)