feat: improve performance of reading from the socket during unmarshall (#200)

This commit is contained in:
J. Nick Koston 2023-05-03 17:20:50 -05:00 committed by GitHub
parent a17d6d0fd0
commit e5d355ff40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -65,7 +65,7 @@ jobs:
if [ "${{ matrix.extension }}" = "skip_cython" ]; then
SKIP_CYTHON=1 poetry install --only=main,dev
else
poetry install --only=main,dev
REQUIRE_CYTHON=1 poetry install --only=main,dev
fi
- name: Test with Pytest
run: export $(dbus-launch); poetry run pytest --cov-report=xml --timeout=5

View File

@ -123,6 +123,7 @@ cdef class Unmarshaller:
@cython.locals(
msg=cython.bytes,
recv=cython.tuple
)
cdef bytes _read_sock(self, object length)

View File

@ -250,13 +250,16 @@ class Unmarshaller:
from the read itself"""
# This will raise BlockingIOError if there is no data to read
# which we store in the MARSHALL_STREAM_END_ERROR object
msg, ancdata, _flags, _addr = self._sock.recvmsg(length, UNIX_FDS_CMSG_LENGTH) # type: ignore[union-attr]
for level, type_, data in ancdata:
if not (level == SOL_SOCKET and type_ == SCM_RIGHTS):
continue
self._unix_fds.extend(
ARRAY("i", data[: len(data) - (len(data) % MAX_UNIX_FDS_SIZE)])
)
recv = self._sock.recvmsg(length, UNIX_FDS_CMSG_LENGTH) # type: ignore[union-attr]
msg = recv[0]
ancdata = recv[1]
if ancdata:
for level, type_, data in ancdata:
if not (level == SOL_SOCKET and type_ == SCM_RIGHTS):
continue
self._unix_fds.extend(
ARRAY("i", data[: len(data) - (len(data) % MAX_UNIX_FDS_SIZE)])
)
return msg