Permalink
Browse files

Add support for SO_REUSEPORT. This is also a workaround for libevent'…

…s current lack of support for this sockopt.
  • Loading branch information...
Maciej Soltysiak
Maciej Soltysiak committed Oct 13, 2014
1 parent 7cc77b0 commit 2e6d756cfb46afa9e4fdb9106812fe436b7a5bf8
Showing with 10 additions and 1 deletion.
  1. +10 −1 tcp_request.c
@@ -401,10 +401,19 @@ tcp_listener_bind(struct context *c)
# define LEV_OPT_DEFERRED_ACCEPT 0
#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;
fd = socket(c->local_sockaddr.ss_family, SOCK_STREAM, IPPROTO_TCP);
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 =
evconnlistener_new(c->event_loop,
@@ -416,7 +425,7 @@ tcp_listener_bind(struct context *c)
TCP_REQUEST_BACKLOG,
fd);
if (c->tcp_conn_listener == NULL) {
logger(LOG_ERR, "Unable to bind (TCP)");
logger(LOG_ERR, "Unable to create listener (TCP)");
return -1;
}
if (evconnlistener_disable(c->tcp_conn_listener) != 0) {

0 comments on commit 2e6d756

Please sign in to comment.