MCPcopy Index your code
hub / github.com/secdev/scapy / SocketMapper

Class SocketMapper

scapy/contrib/cansocket_python_can.py:44–80  ·  view source on GitHub ↗

Internal Helper class to map a python-can bus object to a list of SocketWrapper instances

Source from the content-addressed store, hash-verified

42
43
44class SocketMapper(object):
45 """Internal Helper class to map a python-can bus object to
46 a list of SocketWrapper instances
47 """
48 def __init__(self, bus, sockets):
49 # type: (can_BusABC, List[SocketWrapper]) -> None
50 """Initializes the SocketMapper helper class
51
52 :param bus: A python-can Bus object
53 :param sockets: A list of SocketWrapper objects which want to receive
54 messages from the provided python-can Bus object.
55 """
56 self.bus = bus
57 self.sockets = sockets
58
59 def mux(self):
60 # type: () -> None
61 """Multiplexer function. Tries to receive from its python-can bus
62 object. If a message is received, this message gets forwarded to
63 all receive queues of the SocketWrapper objects.
64 """
65 msgs = []
66 while True:
67 try:
68 msg = self.bus.recv(timeout=0)
69 if msg is None:
70 break
71 else:
72 msgs.append(msg)
73 except Exception as e:
74 warning("[MUX] python-can exception caught: %s" % e)
75
76 for sock in self.sockets:
77 with sock.lock:
78 for msg in msgs:
79 if sock._matches_filters(msg):
80 sock.rx_queue.append(msg)
81
82
83class _SocketsPool(object):

Callers 1

registerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…