8000 GH-91166: zero copy SelectorSocketTransport transport implementation by kumaraditya303 · Pull Request #31871 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-91166: zero copy SelectorSocketTransport transport implementation #31871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 24, 2022
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use sysconf
  • Loading branch information
kumaraditya303 authored Oct 24, 2022
commit 0692952b2a1446c66836fffadead07e032cd1e7a
17 changes: 11 additions & 6 deletions Lib/asyncio/selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import collections
import errno
import functools
import itertools
import os
import selectors
import socket
import warnings
import weakref
try:
import ssl
except ImportError: # pragma: no cover
ssl = None

from . import base_events
from . import constants
Expand All @@ -28,6 +26,10 @@
from . import trsock
from .log import logger

HAVE_SENDMSG = hasattr(socket.socket, 'sendmsg')

if HAVE_SENDMSG:
SC_IOV_MAX = os.sysconf('SC_IOV_MAX')

def _test_selector_event(selector, fd, event):
# Test if the selector is monitoring 'event' events
Expand Down Expand Up @@ -899,7 +901,7 @@ def __init__(self, loop, sock, protocol, waiter=None,
self._eof = False
self._paused = False
self._empty_waiter = None
if hasattr(socket.socket, 'sendmsg'):
if HAVE_SENDMSG:
self._write_ready = self._write_sendmsg
else:
self._write_ready = self._write_send
Expand Down Expand Up @@ -1070,12 +1072,15 @@ def write(self, data):
self._buffer.append(data)
self._maybe_pause_protocol()

def _get_sendmsg_buffer(self):
return itertools.islice(self._buffer, SC_IOV_MAX)

def _write_sendmsg(self):
assert self._buffer, 'Data should not be empty'
if self._conn_lost:
return
try:
n = self._sock.sendmsg(self._buffer)
n = self._sock.sendmsg(self._get_sendmsg_buffer())
self._adjust_leftover_buffer(n)
except (BlockingIOError, InterruptedError):
pass
Expand Down
0