diff --git a/src/zeroconf/_listener.pxd b/src/zeroconf/_listener.pxd new file mode 100644 index 000000000..0f32a44a7 --- /dev/null +++ b/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) diff --git a/src/zeroconf/_listener.py b/src/zeroconf/_listener.py index 97bcf007e..bc0af296f 100644 --- a/src/zeroconf/_listener.py +++ b/src/zeroconf/_listener.py @@ -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 @@ -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