mirror of https://github.com/grpc/grpc.git
Reimplement Gevent Integration (#28276)
* WIP * Add gevent test suite run under Bazel. * Fix things up * Yapf * Fix up Bazel files * Make py_grpc_test fancier * Attempt to fix Windows RBE * Attempt to kick GitHub * Fix Python 2 runs * Yet more fixes * And the patch file too * I am an idiot * Mark gevent tests flaky * Try to make rules_python more tolerant * Typo * Exclude reconnect test from gevent * Remove unnecessary parts of patch * Buildifier * You saw nothing * isort * Move py_grpc_test to an internal-only file * Review comments * More reviewer comments * Review * Add initial changes for gevent * WIP. Run completion_queue_next in a threadpool * WIP. * WIP * Re-remove skip annotation * Finally working * Reactivate tests * Clean up * Move C++ threading utilities to grpc.pxi * Unbreak sync stack * Refix test flake * WIP. Trying to get things working properly * Move test stuff to test runner * Clean up * Can't handle exceptions if you don't compile with exceptions * Remove debug stuff unintentionally left in * Add greenlet switch loggging and fix threading issue * Only run a greenlet scheduling greenlet when there are open channels * Format * Add threadpool modifications to old runner * And actually import geventpull/28853/head
parent
09e7e7456b
commit
27bc6fe779
25 changed files with 276 additions and 691 deletions
@ -1,132 +0,0 @@ |
||||
# Copyright 2019 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
# distutils: language=c++ |
||||
|
||||
from libcpp cimport bool as bool_t |
||||
from libcpp.string cimport string as cppstring |
||||
|
||||
cdef extern from "grpc/impl/codegen/slice.h": |
||||
struct grpc_slice_buffer: |
||||
int count |
||||
|
||||
cdef extern from "src/core/lib/iomgr/error.h": |
||||
struct grpc_error: |
||||
pass |
||||
ctypedef grpc_error* grpc_error_handle |
||||
|
||||
# TODO(https://github.com/grpc/grpc/issues/20135) Change the filename |
||||
# for something more meaningful. |
||||
cdef extern from "src/core/lib/iomgr/python_util.h": |
||||
grpc_error_handle grpc_socket_error(char* error) |
||||
char* grpc_slice_buffer_start(grpc_slice_buffer* buffer, int i) |
||||
int grpc_slice_buffer_length(grpc_slice_buffer* buffer, int i) |
||||
|
||||
cdef extern from "src/core/lib/iomgr/sockaddr.h": |
||||
ctypedef struct grpc_sockaddr: |
||||
pass |
||||
|
||||
cdef extern from "src/core/lib/iomgr/resolve_address.h": |
||||
ctypedef struct grpc_resolved_addresses: |
||||
size_t naddrs |
||||
grpc_resolved_address* addrs |
||||
|
||||
ctypedef struct grpc_resolved_address: |
||||
char[128] addr |
||||
size_t len |
||||
|
||||
cdef extern from "src/core/lib/iomgr/resolve_address_custom.h": |
||||
struct grpc_custom_resolver: |
||||
pass |
||||
|
||||
struct grpc_custom_resolver_vtable: |
||||
grpc_error_handle (*resolve)(const char* host, const char* port, grpc_resolved_addresses** res); |
||||
void (*resolve_async)(grpc_custom_resolver* resolver, const char* host, const char* port); |
||||
|
||||
void grpc_custom_resolve_callback(grpc_custom_resolver* resolver, |
||||
grpc_resolved_addresses* result, |
||||
grpc_error_handle error); |
||||
|
||||
cdef extern from "src/core/lib/iomgr/tcp_custom.h": |
||||
cdef int GRPC_CUSTOM_SOCKET_OPT_SO_REUSEPORT |
||||
|
||||
struct grpc_custom_socket: |
||||
void* impl |
||||
# We don't care about the rest of the fields |
||||
ctypedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket, |
||||
grpc_error_handle error) |
||||
ctypedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket, |
||||
grpc_error_handle error) |
||||
ctypedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket, |
||||
size_t nread, grpc_error_handle error) |
||||
ctypedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket, |
||||
grpc_custom_socket* client, |
||||
grpc_error_handle error) |
||||
ctypedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket) |
||||
|
||||
struct grpc_socket_vtable: |
||||
grpc_error_handle (*init)(grpc_custom_socket* socket, int domain); |
||||
void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr, |
||||
size_t len, grpc_custom_connect_callback cb); |
||||
void (*destroy)(grpc_custom_socket* socket); |
||||
void (*shutdown)(grpc_custom_socket* socket); |
||||
void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb); |
||||
void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices, |
||||
grpc_custom_write_callback cb); |
||||
void (*read)(grpc_custom_socket* socket, char* buffer, size_t length, |
||||
grpc_custom_read_callback cb); |
||||
grpc_error_handle (*getpeername)(grpc_custom_socket* socket, |
||||
const grpc_sockaddr* addr, int* len); |
||||
grpc_error_handle (*getsockname)(grpc_custom_socket* socket, |
||||
const grpc_sockaddr* addr, int* len); |
||||
grpc_error_handle (*bind)(grpc_custom_socket* socket, const grpc_sockaddr* addr, |
||||
size_t len, int flags); |
||||
grpc_error_handle (*listen)(grpc_custom_socket* socket); |
||||
void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client, |
||||
grpc_custom_accept_callback cb); |
||||
|
||||
cdef extern from "src/core/lib/iomgr/timer_custom.h": |
||||
struct grpc_custom_timer: |
||||
void* timer |
||||
int timeout_ms |
||||
# We don't care about the rest of the fields |
||||
|
||||
struct grpc_custom_timer_vtable: |
||||
void (*start)(grpc_custom_timer* t); |
||||
void (*stop)(grpc_custom_timer* t); |
||||
|
||||
void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error_handle error); |
||||
|
||||
cdef extern from "src/core/lib/iomgr/pollset_custom.h": |
||||
struct grpc_custom_poller_vtable: |
||||
void (*init)() |
||||
grpc_error_handle (*poll)(size_t timeout_ms) |
||||
void (*kick)() |
||||
void (*shutdown)() |
||||
|
||||
cdef extern from "src/core/lib/iomgr/iomgr_custom.h": |
||||
void grpc_custom_iomgr_init(grpc_socket_vtable* socket, |
||||
grpc_custom_resolver_vtable* resolver, |
||||
grpc_custom_timer_vtable* timer, |
||||
grpc_custom_poller_vtable* poller); |
||||
|
||||
cdef extern from "src/core/lib/address_utils/sockaddr_utils.h": |
||||
int grpc_sockaddr_get_port(const grpc_resolved_address *addr); |
||||
cppstring grpc_sockaddr_to_string(const grpc_resolved_address *addr, |
||||
bool_t normalize); |
||||
int grpc_sockaddr_set_port(const grpc_resolved_address *resolved_addr, |
||||
int port) |
||||
const char* grpc_sockaddr_get_uri_scheme(const grpc_resolved_address* resolved_addr) |
||||
|
||||
cdef extern from "src/core/lib/address_utils/parse_address.h": |
||||
grpc_error_handle grpc_string_to_sockaddr(grpc_resolved_address *out, char* addr, int port); |
@ -1,63 +0,0 @@ |
||||
# Copyright 2019 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
# distutils: language=c++ |
||||
|
||||
from libc cimport string |
||||
from libc.stdlib cimport malloc |
||||
from libcpp.string cimport string as cppstring |
||||
|
||||
cdef grpc_error_handle grpc_error_none(): |
||||
return <grpc_error_handle>0 |
||||
|
||||
cdef grpc_error_handle socket_error(str syscall, str err): |
||||
error_str = "{} failed: {}".format(syscall, err) |
||||
error_bytes = str_to_bytes(error_str) |
||||
return grpc_socket_error(error_bytes) |
||||
|
||||
cdef resolved_addr_to_tuple(grpc_resolved_address* address): |
||||
cdef cppstring res_str |
||||
port = grpc_sockaddr_get_port(address) |
||||
res_str = grpc_sockaddr_to_string(address, False) |
||||
byte_str = _decode(res_str) |
||||
if byte_str.endswith(':' + str(port)): |
||||
byte_str = byte_str[:(0 - len(str(port)) - 1)] |
||||
byte_str = byte_str.lstrip('[') |
||||
byte_str = byte_str.rstrip(']') |
||||
byte_str = '{}'.format(byte_str) |
||||
return byte_str, port |
||||
|
||||
cdef sockaddr_to_tuple(const grpc_sockaddr* address, size_t length): |
||||
cdef grpc_resolved_address c_addr |
||||
string.memcpy(<void*>c_addr.addr, <void*> address, length) |
||||
c_addr.len = length |
||||
return resolved_addr_to_tuple(&c_addr) |
||||
|
||||
cdef sockaddr_is_ipv4(const grpc_sockaddr* address, size_t length): |
||||
cdef grpc_resolved_address c_addr |
||||
string.memcpy(<void*>c_addr.addr, <void*> address, length) |
||||
c_addr.len = length |
||||
return grpc_sockaddr_get_uri_scheme(&c_addr) == b'ipv4' |
||||
|
||||
cdef grpc_resolved_addresses* tuples_to_resolvaddr(tups): |
||||
cdef grpc_resolved_addresses* addresses |
||||
tups_set = set((tup[4][0], tup[4][1]) for tup in tups) |
||||
addresses = <grpc_resolved_addresses*> malloc(sizeof(grpc_resolved_addresses)) |
||||
addresses.naddrs = len(tups_set) |
||||
addresses.addrs = <grpc_resolved_address*> malloc(sizeof(grpc_resolved_address) * len(tups_set)) |
||||
i = 0 |
||||
for tup in set(tups_set): |
||||
hostname = str_to_bytes(tup[0]) |
||||
grpc_string_to_sockaddr(&addresses.addrs[i], hostname, tup[1]) |
||||
i += 1 |
||||
return addresses |
Loading…
Reference in new issue