Changeset 162 for etherws/trunk/etherws.py
- Timestamp:
- 06/16/12 20:00:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r160 r162 67 67 68 68 class TapHandler(DebugMixIn): 69 READ_SIZE = 65535 70 69 71 def __init__(self, dev, debug=False): 70 72 self._debug = debug … … 72 74 self._tap = pytun.TunTapDevice(dev, pytun.IFF_TAP | pytun.IFF_NO_PI) 73 75 self._tap.up() 74 self._ glock = threading.Lock()76 self._taplock = threading.Lock() 75 77 76 78 def fileno(self): 77 with self._ glock:79 with self._taplock: 78 80 return self._tap.fileno() 79 81 80 82 def register_client(self, client): 81 with self._glock: 82 self._clients.append(client) 83 self._clients.append(client) 83 84 84 85 def unregister_client(self, client): 85 with self._glock: 86 self._clients.remove(client) 86 self._clients.remove(client) 87 87 88 88 def write(self, caller, message): 89 with self._glock: 90 clients = self._clients[:] 91 92 if caller is not self: 93 clients.remove(caller) 89 clients = self._clients[:] 90 91 if caller is not self: 92 clients.remove(caller) 93 94 with self._taplock: 94 95 self._tap.write(message) 95 96 96 97 97 for c in clients: 98 c.write_message(message, True) 98 99 99 100 def __call__(self, fd, events): 100 with self._glock: 101 data = self._tap.read(self._tap.mtu) 102 self.write(self, data) 101 buf = [] 102 103 while True: 104 with self._taplock: 105 data = self._tap.read(self.READ_SIZE) 106 107 if data: 108 buf.append(data) 109 110 if len(data) < self.READ_SIZE: 111 break 112 113 self.write(self, ''.join(buf)) 103 114 104 115
Note: See TracChangeset
for help on using the changeset viewer.