Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / src / python / grpcio / grpc / _cython / _cygrpc / aio / completion_queue.pxd.pxi
1 # Copyright 2020 The gRPC Authors
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
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]:
19         queue()
20         bint empty()
21         T& front()
22         void pop()
23         void push(T&)
24         size_t size()
25
26
27 cdef extern from "<mutex>" namespace "std" nogil:
28     cdef cppclass mutex:
29         mutex()
30         void lock()
31         void unlock()
32
33
34 ctypedef queue[grpc_event] cpp_event_queue
35
36
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)
42
43
44 cdef void _unified_socket_write(int fd) nogil
45
46
47 cdef class BaseCompletionQueue:
48     cdef grpc_completion_queue *_cq
49
50     cdef grpc_completion_queue* c_ptr(self)
51
52
53 cdef class _BoundEventLoop:
54     cdef readonly object loop
55     cdef readonly object read_socket  # socket.socket
56     cdef bint _has_reader
57
58
59 cdef class PollerCompletionQueue(BaseCompletionQueue):
60     cdef bint _shutdown
61     cdef cpp_event_queue _queue
62     cdef mutex _queue_mutex
63     cdef object _poller_thread  # threading.Thread
64     cdef int _write_fd
65     cdef object _read_socket    # socket.socket
66     cdef object _write_socket   # socket.socket
67     cdef dict _loops            # Mapping[asyncio.AbstractLoop, _BoundEventLoop]
68
69     cdef void _poll(self) nogil
70     cdef shutdown(self)