1 # Copyright 2020 The gRPC Authors
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # NOTE(lidiz) Unfortunately, we can't use "cimport" here because Cython
16 # links it with exception handling. It introduces new dependencies.
17 cdef extern from "<queue>" namespace "std" nogil:
18 cdef cppclass queue[T]:
27 cdef extern from "<mutex>" namespace "std" nogil:
34 ctypedef queue[grpc_event] cpp_event_queue
37 IF UNAME_SYSNAME == "Windows":
38 cdef extern from "winsock2.h" nogil:
39 ctypedef uint32_t WIN_SOCKET "SOCKET"
40 WIN_SOCKET win_socket "socket" (int af, int type, int protocol)
41 int win_socket_send "send" (WIN_SOCKET s, const char *buf, int len, int flags)
44 cdef void _unified_socket_write(int fd) nogil
47 cdef class BaseCompletionQueue:
48 cdef grpc_completion_queue *_cq
50 cdef grpc_completion_queue* c_ptr(self)
53 cdef class _BoundEventLoop:
54 cdef readonly object loop
55 cdef readonly object read_socket # socket.socket
59 cdef class PollerCompletionQueue(BaseCompletionQueue):
61 cdef cpp_event_queue _queue
62 cdef mutex _queue_mutex
63 cdef object _poller_thread # threading.Thread
65 cdef object _read_socket # socket.socket
66 cdef object _write_socket # socket.socket
67 cdef dict _loops # Mapping[asyncio.AbstractLoop, _BoundEventLoop]
69 cdef void _poll(self) nogil