Changeset 178
- Timestamp:
- 07/25/12 21:40:03 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r177 r178 201 201 READ_SIZE = 65535 202 202 203 def __init__(self, switch, dev, debug=False): 203 def __init__(self, ioloop, switch, dev, debug=False): 204 self._ioloop = ioloop 204 205 self._switch = switch 205 206 self._dev = dev … … 217 218 self._tap.up() 218 219 self._switch.register_port(self) 220 self._ioloop.add_handler(self.fileno(), self, self._ioloop.READ) 219 221 220 222 def close(self): 221 223 if self.closed: 222 224 raise ValueError('I/O operation on closed tap') 225 self._ioloop.remove_handler(self.fileno()) 223 226 self._switch.unregister_port(self) 224 227 self._tap.close() … … 241 244 except: 242 245 traceback.print_exc() 243 tornado.ioloop.IOLoop.instance().stop() # XXX: should unregister fd246 self.close() 244 247 245 248 def _read(self): … … 273 276 274 277 class EtherWebSocketClient(DebugMixIn): 275 def __init__(self, switch, url, cred=None, debug=False): 278 def __init__(self, ioloop, switch, url, cred=None, debug=False): 279 self._ioloop = ioloop 276 280 self._switch = switch 277 281 self._url = url … … 295 299 self._sock.connect(self._url, **self._options) 296 300 self._switch.register_port(self) 301 self._ioloop.add_handler(self.fileno(), self, self._ioloop.READ) 297 302 self.dprintf('connected: %s\n', lambda: self._url) 298 303 … … 300 305 if self.closed: 301 306 raise websocket.WebSocketException('already closed') 307 self._ioloop.remove_handler(self.fileno()) 302 308 self._switch.unregister_port(self) 303 309 self._sock.close() … … 327 333 except: 328 334 traceback.print_exc() 329 tornado.ioloop.IOLoop.instance().stop() # XXX: should unregister fd335 self.close() 330 336 331 337 … … 470 476 471 477 for dev in args.device: 472 tap = TapHandler( switch, dev, debug=args.debug)478 tap = TapHandler(ioloop, switch, dev, debug=args.debug) 473 479 tap.open() 474 ioloop.add_handler(tap.fileno(), tap, ioloop.READ)475 480 476 481 if not args.foreground: … … 506 511 507 512 for uri in args.uri: 508 client = EtherWebSocketClient( switch, uri, cred, args.debug)513 client = EtherWebSocketClient(ioloop, switch, uri, cred, args.debug) 509 514 client.open() 510 ioloop.add_handler(client.fileno(), client, ioloop.READ)511 515 512 516 for dev in args.device: 513 tap = TapHandler( switch, dev, debug=args.debug)517 tap = TapHandler(ioloop, switch, dev, debug=args.debug) 514 518 tap.open() 515 ioloop.add_handler(tap.fileno(), tap, ioloop.READ)516 519 517 520 if not args.foreground:
Note: See TracChangeset
for help on using the changeset viewer.