- Timestamp:
- 05/13/12 06:20:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r134 r135 64 64 self._debug = debug 65 65 self._tap = pytun.TunTapDevice(dev, pytun.IFF_TAP | pytun.IFF_NO_PI) 66 self._tap .up()66 self._tap_lock = threading.Lock() 67 67 68 68 self._clients = [] 69 69 self._clients_lock = threading.Lock() 70 71 try: 72 self._tap_lock.acquire() 73 self._tap.up() 74 finally: 75 self._tap_lock.release() 70 76 71 77 def register_client(self, client): … … 98 104 if caller is not self: 99 105 clients.remove(caller) 100 self._tap.write(message) 106 try: 107 self._tap_lock.acquire() 108 self._tap.write(message) 109 finally: 110 self._tap_lock.release() 101 111 102 112 message = base64.b64encode(message) … … 107 117 def run(self): 108 118 epoll = select.epoll() 109 epoll.register(self._tap.fileno(), select.EPOLLIN) 119 120 try: 121 self._tap_lock.acquire() 122 epoll.register(self._tap.fileno(), select.EPOLLIN) 123 finally: 124 self._tap_lock.release() 110 125 111 126 while True: 112 127 evts = epoll.poll(1) 113 128 for fileno, evt in evts: 114 self.write(self, self._tap.read(self._tap.mtu)) 129 try: 130 self._tap_lock.acquire() 131 data = self._tap.read(self._tap.mtu) 132 finally: 133 self._tap_lock.release() 134 self.write(self, data) 115 135 116 136
Note: See TracChangeset
for help on using the changeset viewer.