Skip to content

Commit

Permalink
feat: add cython pxd file for _listener.py to improve incoming messag…
Browse files Browse the repository at this point in the history
…e processing performance (#1221)
  • Loading branch information
bdraco committed Aug 14, 2023
1 parent 1901fb4 commit f459856
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/zeroconf/_listener.pxd
@@ -0,0 +1,24 @@

import cython


cdef object millis_to_seconds
cdef object log
cdef object logging_DEBUG

from ._protocol.incoming cimport DNSIncoming


cdef class AsyncListener:

cdef public object zc
cdef public cython.bytes data
cdef public cython.float last_time
cdef public DNSIncoming last_message
cdef public object transport
cdef public object sock_description
cdef public cython.dict _deferred
cdef public cython.dict _timers

@cython.locals(now=cython.float, msg=DNSIncoming)
cpdef datagram_received(self, cython.bytes bytes, cython.tuple addrs)
9 changes: 7 additions & 2 deletions src/zeroconf/_listener.py
Expand Up @@ -37,6 +37,11 @@
_TC_DELAY_RANDOM_INTERVAL = (400, 500)


_bytes = bytes

logging_DEBUG = logging.DEBUG


class AsyncListener:

"""A Listener is used by this module to listen on the multicast
Expand Down Expand Up @@ -69,11 +74,11 @@ def __init__(self, zc: 'Zeroconf') -> None:
super().__init__()

def datagram_received(
self, data: bytes, addrs: Union[Tuple[str, int], Tuple[str, int, int, int]]
self, data: _bytes, addrs: Union[Tuple[str, int], Tuple[str, int, int, int]]
) -> None:
assert self.transport is not None
data_len = len(data)
debug = log.isEnabledFor(logging.DEBUG)
debug = log.isEnabledFor(logging_DEBUG)

if data_len > _MAX_MSG_ABSOLUTE:
# Guard against oversized packets to ensure bad implementations cannot overwhelm
Expand Down

0 comments on commit f459856

Please sign in to comment.