2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 11:01:09 +00:00

Switch from clear buffer to sized memoryview

Use the recvmsg hint to mask out the buffer rather
than zeroing the entire buffer. This is more efficient
and further improves efficiency of parsing of the packet.
This commit is contained in:
Jarrod Johnson 2022-05-14 18:35:15 -04:00
parent 54741517f1
commit eb99fbd8b2

View File

@ -381,7 +381,6 @@ def snoop(handler, protocol=None, nodeguess=None):
if not ready or not ready[0]:
continue
for netc in ready[0]:
rawbuffer[:] = b'\x00' * 2048
idx = None
if netc == net4:
i = recvmsg(netc.fileno(), ctypes.pointer(msg), 0)
@ -394,7 +393,7 @@ def snoop(handler, protocol=None, nodeguess=None):
if level == socket.IPPROTO_IP and typ == IP_PKTINFO:
idx, recv = struct.unpack('II', cmsgarr[16:24])
recv = ipfromint(recv)
rqv = memoryview(rawbuffer)
rqv = memoryview(rawbuffer)[:i]
if rawbuffer[0] == 1: # Boot request
process_dhcp4req(handler, nodeguess, cfg, net4, idx, recv, rqv)
elif netc == net6: