Support Windows

pull/21643/head
Lidi Zheng 5 years ago
parent 6a70555290
commit bcd57dfb7d
  1. 7
      src/core/lib/iomgr/tcp_server_custom.cc
  2. 3
      src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi

@ -31,7 +31,6 @@
#include "src/core/lib/iomgr/iomgr_custom.h" #include "src/core/lib/iomgr/iomgr_custom.h"
#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include "src/core/lib/iomgr/tcp_custom.h" #include "src/core/lib/iomgr/tcp_custom.h"
#include "src/core/lib/iomgr/tcp_server.h" #include "src/core/lib/iomgr/tcp_server.h"
@ -82,13 +81,13 @@ static grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
const grpc_channel_args* args, const grpc_channel_args* args,
grpc_tcp_server** server) { grpc_tcp_server** server) {
grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server));
s->so_reuseport = grpc_is_socket_reuse_port_supported(); // Let the implementation decide if so_reuseport should be enabled or not.
s->so_reuseport = true;
s->resource_quota = grpc_resource_quota_create(nullptr); s->resource_quota = grpc_resource_quota_create(nullptr);
for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) { for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) {
if (0 == strcmp(GRPC_ARG_ALLOW_REUSEPORT, args->args[i].key)) { if (0 == strcmp(GRPC_ARG_ALLOW_REUSEPORT, args->args[i].key)) {
if (args->args[i].type == GRPC_ARG_INTEGER) { if (args->args[i].type == GRPC_ARG_INTEGER) {
s->so_reuseport = grpc_is_socket_reuse_port_supported() && s->so_reuseport = args->args[i].value.integer != 0;
(args->args[i].value.integer != 0);
} else { } else {
gpr_free(s); gpr_free(s);
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(GRPC_ARG_ALLOW_REUSEPORT return GRPC_ERROR_CREATE_FROM_STATIC_STRING(GRPC_ARG_ALLOW_REUSEPORT

@ -13,6 +13,8 @@
# limitations under the License. # limitations under the License.
import platform
from cpython cimport Py_INCREF, Py_DECREF from cpython cimport Py_INCREF, Py_DECREF
from libc cimport string from libc cimport string
@ -124,6 +126,7 @@ cdef grpc_error* asyncio_socket_listen(grpc_custom_socket* grpc_socket) with gil
def _asyncio_apply_socket_options(object s, int flags): def _asyncio_apply_socket_options(object s, int flags):
s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEADDR, 1) s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEADDR, 1)
if platform.system() != 'Windows':
if GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT & flags: if GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT & flags:
s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEPORT, 1) s.setsockopt(native_socket.SOL_SOCKET, native_socket.SO_REUSEPORT, 1)
s.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True) s.setsockopt(native_socket.IPPROTO_TCP, native_socket.TCP_NODELAY, True)

Loading…
Cancel
Save