cfab5549b2ee2cec4d0d856ea3f429ce8c81cea2
[platform/upstream/grpc.git] / src / python / grpcio / grpc / _cython / _cygrpc / aio / iomgr / socket.pxd.pxi
1 # Copyright 2019 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
16 cdef class _AsyncioSocket:
17     cdef:
18         # Common attributes
19         grpc_custom_socket * _grpc_socket
20         grpc_custom_read_callback _grpc_read_cb
21         grpc_custom_write_callback _grpc_write_cb
22         object _reader
23         object _writer
24         object _task_read
25         object _task_write
26         object _task_connect
27         object _task_listen
28         char * _read_buffer
29         # Caches the picked event loop, so we can avoid the 30ns overhead each
30         # time we need access to the event loop.
31         object _loop
32         # TODO(lidiz) Drop after 3.6 deprecation. Python 3.7 introduces methods
33         # like `is_closing()` to help graceful shutdown.
34         bint _closed
35
36         # Client-side attributes
37         grpc_custom_connect_callback _grpc_connect_cb
38         
39         # Server-side attributes
40         grpc_custom_accept_callback _grpc_accept_cb
41         grpc_custom_socket * _grpc_client_socket
42         object _server
43         object _py_socket
44         object _peername
45
46     @staticmethod
47     cdef _AsyncioSocket create(
48             grpc_custom_socket * grpc_socket,
49             object reader,
50             object writer)
51     @staticmethod
52     cdef _AsyncioSocket create_with_py_socket(grpc_custom_socket * grpc_socket, object py_socket)
53
54     cdef void connect(self, object host, object port, grpc_custom_connect_callback grpc_connect_cb)
55     cdef void write(self, grpc_slice_buffer * g_slice_buffer, grpc_custom_write_callback grpc_write_cb)
56     cdef void read(self, char * buffer_, size_t length, grpc_custom_read_callback grpc_read_cb)
57     cdef bint is_connected(self)
58     cdef void close(self)
59
60     cdef accept(self, grpc_custom_socket* grpc_socket_client, grpc_custom_accept_callback grpc_accept_cb)
61     cdef listen(self)
62     cdef tuple peername(self)
63     cdef tuple sockname(self)