diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-24 20:19:22 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-24 20:19:22 +0300 |
commit | f592edf20b6d91fb6c25d9d3b1021d2ab4c5fcb3 (patch) | |
tree | 3e888d25dd9e46073dd2e8d7903b82eb8df55169 /src/util.c | |
parent | fb67ab386b508327054548533617a348427df4a6 (diff) | |
download | rspamd-f592edf20b6d91fb6c25d9d3b1021d2ab4c5fcb3.tar.gz rspamd-f592edf20b6d91fb6c25d9d3b1021d2ab4c5fcb3.zip |
* Fix multiply accept issues
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c index c4e85294a..1fdd2758a 100644 --- a/src/util.c +++ b/src/util.c @@ -43,7 +43,7 @@ make_socket_nonblocking (int fd) int make_tcp_socket (struct in_addr *addr, u_short port, gboolean is_server) { - int fd, r, optlen, s_error; + int fd, r, optlen, on = 1, s_error; int serrno; struct sockaddr_in sin; @@ -70,6 +70,7 @@ make_tcp_socket (struct in_addr *addr, u_short port, gboolean is_server) sin.sin_addr.s_addr = addr->s_addr; if (is_server) { + setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(int)); r = bind (fd, (struct sockaddr *)&sin, sizeof (struct sockaddr_in)); } else { @@ -109,6 +110,9 @@ accept_from_socket (int listen_sock, struct sockaddr *addr, socklen_t *len) int serrno; if ((nfd = accept (listen_sock, addr, len)) == -1) { + if (errno == EAGAIN) { + return 0; + } msg_warn ("accept_from_socket: accept failed: %d, '%s'", errno, strerror (errno)); return -1; } @@ -122,6 +126,8 @@ accept_from_socket (int listen_sock, struct sockaddr *addr, socklen_t *len) goto out; } + + return (nfd); out: @@ -136,7 +142,7 @@ int make_unix_socket (const char *path, struct sockaddr_un *addr, gboolean is_server) { size_t len = strlen (path); - int fd, s_error, r, optlen, serrno; + int fd, s_error, r, optlen, serrno, on = 1; if (len > sizeof (addr->sun_path) - 1) return -1; @@ -165,6 +171,7 @@ make_unix_socket (const char *path, struct sockaddr_un *addr, gboolean is_server goto out; } if (is_server) { + setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(int)); r = bind (fd, (struct sockaddr *)&sin, sizeof (struct sockaddr_in)); } else { |