| 935 | self._loop.call_soon(callback, *args, context=self._context) |
| 936 | |
| 937 | class _SelectorSocketTransport(_SelectorTransport): |
| 938 | |
| 939 | _start_tls_compatible = True |
| 940 | _sendfile_compatible = constants._SendfileMode.TRY_NATIVE |
| 941 | |
| 942 | def __init__(self, loop, sock, protocol, waiter=None, |
| 943 | extra=None, server=None, context=None): |
| 944 | self._read_ready_cb = None |
| 945 | super().__init__(loop, sock, protocol, extra, server, context) |
| 946 | self._eof = False |
| 947 | self._empty_waiter = None |
| 948 | if _HAS_SENDMSG: |
| 949 | self._write_ready = self._write_sendmsg |
| 950 | else: |
| 951 | self._write_ready = self._write_send |
| 952 | # Disable the Nagle algorithm -- small writes will be |
| 953 | # sent without waiting for the TCP ACK. This generally |
| 954 | # decreases the latency (in some cases significantly.) |
| 955 | base_events._set_nodelay(self._sock) |
| 956 | |
| 957 | self._call_soon(self._protocol.connection_made, self) |
| 958 | # only start reading when connection_made() has been called |
| 959 | self._call_soon(self._add_reader, self._sock_fd, self._read_ready) |
| 960 | if waiter is not None: |
| 961 | # only wake up the waiter when connection_made() has been called |
| 962 | self._call_soon(futures._set_result_unless_cancelled, waiter, None) |
| 963 | |
| 964 | def set_protocol(self, protocol): |
| 965 | if isinstance(protocol, protocols.BufferedProtocol): |
| 966 | self._read_ready_cb = self._read_ready__get_buffer |
| 967 | else: |
| 968 | self._read_ready_cb = self._read_ready__data_received |
| 969 | |
| 970 | super().set_protocol(protocol) |
| 971 | |
| 972 | def _read_ready(self): |
| 973 | self._read_ready_cb() |
| 974 | |
| 975 | def _read_ready__get_buffer(self): |
| 976 | if self._conn_lost: |
| 977 | return |
| 978 | |
| 979 | try: |
| 980 | buf = self._protocol.get_buffer(-1) |
| 981 | if not len(buf): |
| 982 | raise RuntimeError('get_buffer() returned an empty buffer') |
| 983 | except (SystemExit, KeyboardInterrupt): |
| 984 | raise |
| 985 | except BaseException as exc: |
| 986 | self._fatal_error( |
| 987 | exc, 'Fatal error: protocol.get_buffer() call failed.') |
| 988 | return |
| 989 | |
| 990 | try: |
| 991 | nbytes = self._sock.recv_into(buf) |
| 992 | except (BlockingIOError, InterruptedError): |
| 993 | return |
| 994 | except (SystemExit, KeyboardInterrupt): |
no outgoing calls
searching dependent graphs…