mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MEDIUM: proto_sockpair: make use of sockpair_bind_receiver()
Now we rely on the address family's receiver instead of binding everything ourselves.
This commit is contained in:
parent
62292b28a3
commit
9eda7a6d62
@ -150,9 +150,8 @@ int sockpair_bind_receiver(struct receiver *rx, void (*handler)(int fd), char **
|
||||
*/
|
||||
static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen)
|
||||
{
|
||||
int fd = listener->rx.fd;
|
||||
int err;
|
||||
const char *msg = NULL;
|
||||
char *msg = NULL;
|
||||
|
||||
err = ERR_NONE;
|
||||
|
||||
@ -163,38 +162,18 @@ static int sockpair_bind_listener(struct listener *listener, char *errmsg, int e
|
||||
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";
|
||||
goto err_return;
|
||||
err = sockpair_bind_receiver(&listener->rx, listener->rx.proto->accept, &msg);
|
||||
if (err != ERR_NONE) {
|
||||
snprintf(errmsg, errlen, "%s", msg);
|
||||
free(msg); msg = NULL;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (fd >= global.maxsock) {
|
||||
err |= ERR_FATAL | ERR_ALERT;
|
||||
msg = "socket(): not enough free sockets, raise -n argument";
|
||||
goto err_return;
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
|
||||
err |= ERR_FATAL | ERR_ALERT;
|
||||
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,
|
||||
thread_mask(listener->rx.settings->bind_thread) & all_threads_mask);
|
||||
|
||||
return err;
|
||||
|
||||
err_return:
|
||||
if (msg && errlen)
|
||||
snprintf(errmsg, errlen, "%s [fd %d]", msg, fd);
|
||||
snprintf(errmsg, errlen, "%s [fd %d]", msg, listener->rx.fd);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user