Skip to content

Commit

Permalink
feat: improve performance of reading from the socket during unmarshall (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored May 3, 2023
1 parent a17d6d0 commit e5d355f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/dbus_fast/_private/unmarshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ cdef class Unmarshaller:

@cython.locals(
msg=cython.bytes,
recv=cython.tuple
)
cdef bytes _read_sock(self, object length)

Expand Down
17 changes: 10 additions & 7 deletions src/dbus_fast/_private/unmarshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,16 @@ def _read_sock(self, length: int) -> bytes:
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

Expand Down

0 comments on commit e5d355f

Please sign in to comment.