diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2018-04-04 00:11:47 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2018-04-04 00:55:59 +0200 |
commit | 00531b326e9cdea7629644d9aa3e457773fe9182 (patch) | |
tree | 2dbf15191e74260502e0fb381c49c792b197840e /src/core/lib/iomgr/tcp_uv.cc | |
parent | cb078e5558836e7e5fb6510a6f687e4e3eefa939 (diff) |
Making tcp_custom's setsockopt a more generic thing.
Diffstat (limited to 'src/core/lib/iomgr/tcp_uv.cc')
-rw-r--r-- | src/core/lib/iomgr/tcp_uv.cc | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 5e3166926b..2f2fc9492a 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -299,14 +299,17 @@ static grpc_error* uv_socket_listen(grpc_custom_socket* socket) { return tcp_error_create("Failed to listen to port", status); } -static grpc_error* uv_socket_setsockopt(grpc_custom_socket* socket, int level, - int option_name, const void* optval, - socklen_t option_len) { - int fd; - uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; - uv_fileno((uv_handle_t*)uv_socket->handle, &fd); - // TODO Handle error here. Also, does this work on windows?? - setsockopt(fd, level, option_name, &optval, (socklen_t)option_len); +static grpc_error* uv_socket_setsockopt(grpc_custom_socket* socket) { +#if defined(GPR_LINUX) && defined(SO_REUSEPORT) + if (family == AF_INET || family == AF_INET6) { + int enable = 1; + int fd; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_fileno((uv_handle_t*)uv_socket->handle, &fd); + // TODO Handle error here. + setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)); + } +#endif return GRPC_ERROR_NONE; } |