Permalink
Browse files

rework tcp_listener_bind() so that tcp_tune() is called before a sock…

…et is bound. This is to make SO_REUSEPORT work and not bail on an already listening port
  • Loading branch information...
Maciej Soltysiak
Maciej Soltysiak committed Oct 13, 2014
1 parent f187c7b commit 7cc77b0bebb36955f8147fdd39da65e8fb8afc6b
Showing with 9 additions and 3 deletions.
  1. +9 −3 tcp_request.c
@@ -400,15 +400,21 @@ tcp_listener_bind(struct context *c)
#ifndef LEV_OPT_DEFERRED_ACCEPT
# define LEV_OPT_DEFERRED_ACCEPT 0
#endif
evutil_socket_t fd;
fd = socket(c->local_sockaddr.ss_family, SOCK_STREAM, IPPROTO_TCP);
tcp_tune(fd);
c->tcp_conn_listener =
evconnlistener_new_bind(c->event_loop,
evconnlistener_new(c->event_loop,
tcp_connection_cb, c,
LEV_OPT_CLOSE_ON_FREE |
LEV_OPT_CLOSE_ON_EXEC |
LEV_OPT_REUSEABLE |
LEV_OPT_DEFERRED_ACCEPT,
TCP_REQUEST_BACKLOG, (struct sockaddr *)
&c->local_sockaddr, (int)c->local_sockaddr_len);
TCP_REQUEST_BACKLOG,
fd);
if (c->tcp_conn_listener == NULL) {
logger(LOG_ERR, "Unable to bind (TCP)");
return -1;

0 comments on commit 7cc77b0

Please sign in to comment.