8000 feat: reorder incoming data handler to reduce overhead (#1189) · python-zeroconf/python-zeroconf@32756ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 32756ff

Browse files
authored
feat: reorder incoming data handler to reduce overhead (#1189)
1 parent 8cca755 commit 32756ff

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/zeroconf/_core.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,9 @@ def datagram_received(
271271
self, data: bytes, addrs: Union[Tuple[str, int], Tuple[str, int, int, int]]
272272
) -> None:
273273
assert self.transport is not None
274-
v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = ()
275274
data_len = len(data)
276275
debug = log.isEnabledFor(logging.DEBUG)
277276

278-
if len(addrs) == 2:
279-
# https://github.com/python/mypy/issues/1178
280-
addr, port = addrs # type: ignore
281-
scope = None
282-
else:
283-
# https://github.com/python/mypy/issues/1178
284-
addr, port, flow, scope = addrs # type: ignore
285-
if debug:
286-
log.debug('IPv6 scope_id %d associated to the receiving interface', scope)
287-
v6_flow_scope = (flow, scope)
288-
289277
if data_len > _MAX_MSG_ABSOLUTE:
290278
# Guard against oversized packets to ensure bad implementations cannot overwhelm
291279
# the system.
@@ -308,15 +296,26 @@ def datagram_received(
308296
# Guard against duplicate packets
309297
if debug:
310298
log.debug(
311-
'Ignoring duplicate message with no unicast questions received from %r:%r [socket %s] (%d bytes) as [%r]',
312-
addr,
313-
port,
299+
'Ignoring duplicate message with no unicast questions received from %s [socket %s] (%d bytes) as [%r]',
300+
addrs,
314301
self.sock_description,
315302
data_len,
316303
data,
317304
)
318305
return
319306

307+
v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = ()
308+
if len(addrs) == 2:
309+
# https://github.com/python/mypy/issues/1178
310+
addr, port = addrs # type: ignore
311+
scope = None
312+
else:
313+
# https://github.com/python/mypy/issues/1178
314+
addr, port, flow, scope = addrs # type: ignore
315+
if debug:
316+
log.debug('IPv6 scope_id %d associated to the receiving interface', scope)
317+
v6_flow_scope = (flow, scope)
318+
320319
msg = DNSIncoming(data, (addr, port), scope, now)
321320
self.data = data
322321
self.last_time = now

0 commit comments

Comments
 (0)
0