Skip to content

Commit

Permalink
Add support for SO_REUSEPORT. This is also a workaround for libevent'…
Browse files Browse the repository at this point in the history
…s current lack of support for this sockopt.
  • Loading branch information
Maciej Soltysiak committed Oct 13, 2014
1 parent 7cc77b0 commit 2e6d756
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tcp_request.c
Expand Up @@ -401,10 +401,19 @@ tcp_listener_bind(struct context *c)
# define LEV_OPT_DEFERRED_ACCEPT 0 # define LEV_OPT_DEFERRED_ACCEPT 0
#endif #endif


/* Until libevent gets support for SO_REUSEPORT we have to break
* evconnlistener_new_bind() into a series of:
* socket(), tcp_tune(), bind(), evconnlistener_new() */
evutil_socket_t fd; evutil_socket_t fd;
fd = socket(c->local_sockaddr.ss_family, SOCK_STREAM, IPPROTO_TCP); fd = socket(c->local_sockaddr.ss_family, SOCK_STREAM, IPPROTO_TCP);


tcp_tune(fd); tcp_tune(fd);
evutil_make_socket_nonblocking(fd);

if (bind(fd, (struct sockaddr *) &c->local_sockaddr, c->local_sockaddr_len) < 0) {
logger(LOG_ERR, "Unable to bind (TCP): %s");
return -1;
}


c->tcp_conn_listener = c->tcp_conn_listener =
evconnlistener_new(c->event_loop, evconnlistener_new(c->event_loop,
Expand All @@ -416,7 +425,7 @@ tcp_listener_bind(struct context *c)
TCP_REQUEST_BACKLOG, TCP_REQUEST_BACKLOG,
fd); fd);
if (c->tcp_conn_listener == NULL) { if (c->tcp_conn_listener == NULL) {
logger(LOG_ERR, "Unable to bind (TCP)"); logger(LOG_ERR, "Unable to create listener (TCP)");
return -1; return -1;
} }
if (evconnlistener_disable(c->tcp_conn_listener) != 0) { if (evconnlistener_disable(c->tcp_conn_listener) != 0) {
Expand Down

0 comments on commit 2e6d756

Please sign in to comment.