Skip to content

Commit 7cc77b0

Browse files
author
Maciej Soltysiak
committed
rework tcp_listener_bind() so that tcp_tune() is called before a socket is bound. This is to make SO_REUSEPORT work and not bail on an already listening port
1 parent f187c7b commit 7cc77b0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tcp_request.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,21 @@ tcp_listener_bind(struct context *c)
400400
#ifndef LEV_OPT_DEFERRED_ACCEPT
401401
# define LEV_OPT_DEFERRED_ACCEPT 0
402402
#endif
403+
404+
evutil_socket_t fd;
405+
fd = socket(c->local_sockaddr.ss_family, SOCK_STREAM, IPPROTO_TCP);
406+
407+
tcp_tune(fd);
408+
403409
c->tcp_conn_listener =
404-
evconnlistener_new_bind(c->event_loop,
410+
evconnlistener_new(c->event_loop,
405411
tcp_connection_cb, c,
406412
LEV_OPT_CLOSE_ON_FREE |
407413
LEV_OPT_CLOSE_ON_EXEC |
408414
LEV_OPT_REUSEABLE |
409415
LEV_OPT_DEFERRED_ACCEPT,
410-
TCP_REQUEST_BACKLOG, (struct sockaddr *)
411-
&c->local_sockaddr, (int)c->local_sockaddr_len);
416+
TCP_REQUEST_BACKLOG,
417+
fd);
412418
if (c->tcp_conn_listener == NULL) {
413419
logger(LOG_ERR, "Unable to bind (TCP)");
414420
return -1;

0 commit comments

Comments
 (0)