mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: sock: add sock_accept_conn() to test a listening socket
At several places we need to check if a socket is still valid and still willing to accept connections. Instead of open-coding this, each time, let's add a new function for this.
This commit is contained in:
parent
8b6fc3d10e
commit
5ced3e8879
@ -40,6 +40,7 @@ int sock_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
|
|||||||
int sock_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
|
int sock_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
|
||||||
int sock_get_old_sockets(const char *unixsocket);
|
int sock_get_old_sockets(const char *unixsocket);
|
||||||
int sock_find_compatible_fd(const struct receiver *rx);
|
int sock_find_compatible_fd(const struct receiver *rx);
|
||||||
|
int sock_accept_conn(const struct receiver *rx);
|
||||||
|
|
||||||
#endif /* _HAPROXY_SOCK_H */
|
#endif /* _HAPROXY_SOCK_H */
|
||||||
|
|
||||||
|
16
src/sock.c
16
src/sock.c
@ -466,6 +466,22 @@ int sock_find_compatible_fd(const struct receiver *rx)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tests if the receiver supports accepting connections. Returns positive on
|
||||||
|
* success, 0 if not possible, negative if the socket is non-recoverable. The
|
||||||
|
* rationale behind this is that inherited FDs may be broken and that shared
|
||||||
|
* FDs might have been paused by another process.
|
||||||
|
*/
|
||||||
|
int sock_accept_conn(const struct receiver *rx)
|
||||||
|
{
|
||||||
|
int opt_val = 0;
|
||||||
|
socklen_t opt_len = sizeof(opt_val);
|
||||||
|
|
||||||
|
if (getsockopt(rx->fd, SOL_SOCKET, SO_ACCEPTCONN, &opt_val, &opt_len) == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return opt_val;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-indent-level: 8
|
* c-indent-level: 8
|
||||||
|
Loading…
Reference in New Issue
Block a user