|
9 | 9 | import collections
|
10 | 10 | import errno
|
11 | 11 | import functools
|
| 12 | +import itertools |
| 13 | +import os |
12 | 14 | import selectors
|
13 | 15 | import socket
|
14 | 16 | import warnings
|
15 | 17 | import weakref
|
16 |
| -try: |
17 |
| - import ssl |
18 |
| -except ImportError: # pragma: no cover |
19 |
| - ssl = None |
20 | 18 |
|
21 | 19 | from . import base_events
|
22 | 20 | from . import constants
|
|
28 | 26 | from . import trsock
|
29 | 27 | from .log import logger
|
30 | 28 |
|
| 29 | +HAVE_SENDMSG = hasattr(socket.socket, 'sendmsg') |
| 30 | + |
| 31 | +if HAVE_SENDMSG: |
| 32 | + SC_IOV_MAX = os.sysconf('SC_IOV_MAX') |
31 | 33 |
|
32 | 34 | def _test_selector_event(selector, fd, event):
|
33 | 35 | # Test if the selector is monitoring 'event' events
|
@@ -899,7 +901,7 @@ def __init__(self, loop, sock, protocol, waiter=None,
|
899 | 901 | self._eof = False
|
900 | 902 | self._paused = False
|
901 | 903 | self._empty_waiter = None
|
902 |
| - if hasattr(socket.socket, 'sendmsg'): |
| 904 | + if HAVE_SENDMSG: |
903 | 905 | self._write_ready = self._write_sendmsg
|
904 | 906 | else:
|
905 | 907 | self._write_ready = self._write_send
|
@@ -1070,12 +1072,15 @@ def write(self, data):
|
1070 | 1072 | self._buffer.append(data)
|
1071 | 1073 | self._maybe_pause_protocol()
|
1072 | 1074 |
|
| 1075 | + def _get_sendmsg_buffer(self): |
| 1076 | + return itertools.islice(self._buffer, SC_IOV_MAX) |
| 1077 | + |
1073 | 1078 | def _write_sendmsg(self):
|
1074 | 1079 | assert self._buffer, 'Data should not be empty'
|
1075 | 1080 | if self._conn_lost:
|
1076 | 1081 | return
|
1077 | 1082 | try:
|
1078 |
| - n = self._sock.sendmsg(self._buffer) |
| 1083 | + n = self._sock.sendmsg(self._get_sendmsg_buffer()) |
1079 | 1084 | self._adjust_leftover_buffer(n)
|
1080 | 1085 | except (BlockingIOError, InterruptedError):
|
1081 | 1086 | pass
|
|
0 commit comments