diff --git a/libratbox/include/commio-ssl.h b/libratbox/include/commio-ssl.h index e3147763..19e65c29 100644 --- a/libratbox/include/commio-ssl.h +++ b/libratbox/include/commio-ssl.h @@ -28,7 +28,7 @@ int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile); int rb_init_ssl(void); -int rb_ssl_listen(rb_fde_t *F, int backlog); +int rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept); int rb_init_prng(const char *path, prng_seed_t seed_type); int rb_get_random(void *buf, size_t length); diff --git a/libratbox/include/rb_commio.h b/libratbox/include/rb_commio.h index 1eef573a..70eea348 100644 --- a/libratbox/include/rb_commio.h +++ b/libratbox/include/rb_commio.h @@ -126,8 +126,8 @@ ssize_t rb_read(rb_fde_t *, void *buf, int count); int rb_pipe(rb_fde_t **, rb_fde_t **, const char *desc); int rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile); -int rb_ssl_listen(rb_fde_t *, int backlog); -int rb_listen(rb_fde_t *, int backlog); +int rb_ssl_listen(rb_fde_t *, int backlog, int defer_accept); +int rb_listen(rb_fde_t *, int backlog, int defer_accept); const char *rb_inet_ntop(int af, const void *src, char *dst, unsigned int size); int rb_inet_pton(int af, const char *src, void *dst); diff --git a/libratbox/src/commio.c b/libratbox/src/commio.c index 1a1dfb87..ca822649 100644 --- a/libratbox/src/commio.c +++ b/libratbox/src/commio.c @@ -761,7 +761,7 @@ mangle_mapped_sockaddr(struct sockaddr *in) * rb_listen() - listen on a port */ int -rb_listen(rb_fde_t *F, int backlog) +rb_listen(rb_fde_t *F, int backlog, int defer_accept) { int result; @@ -769,7 +769,7 @@ rb_listen(rb_fde_t *F, int backlog) result = listen(F->fd, backlog); #ifdef TCP_DEFER_ACCEPT - if (!result) + if (defer_accept && !result) { setsockopt(F->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &backlog, sizeof(int)); } diff --git a/libratbox/src/gnutls.c b/libratbox/src/gnutls.c index a2cb6522..36272dcd 100644 --- a/libratbox/src/gnutls.c +++ b/libratbox/src/gnutls.c @@ -348,10 +348,14 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile) } int -rb_ssl_listen(rb_fde_t *F, int backlog) +rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept) { + int result; + + result = listen(F->fd, backlog, defer_accept); F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL; - return listen(F->fd, backlog); + + return result; } struct ssl_connect diff --git a/libratbox/src/nossl.c b/libratbox/src/nossl.c index ee851899..b6ea2440 100644 --- a/libratbox/src/nossl.c +++ b/libratbox/src/nossl.c @@ -49,7 +49,7 @@ rb_init_ssl(void) } int -rb_ssl_listen(rb_fde_t *F, int backlog) +rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept) { errno = ENOSYS; return -1; diff --git a/libratbox/src/openssl.c b/libratbox/src/openssl.c index 5d719f2d..f00d14ad 100644 --- a/libratbox/src/openssl.c +++ b/libratbox/src/openssl.c @@ -390,10 +390,14 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile) } int -rb_ssl_listen(rb_fde_t *F, int backlog) +rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept) { + int result; + + result = rb_listen(F, backlog, defer_accept); F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL; - return listen(F->fd, backlog); + + return result; } struct ssl_connect