Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import select | 5 import select |
| 6 import socket | 6 import socket |
| 7 import SocketServer | 7 import SocketServer |
| 8 import threading | 8 import threading |
| 9 | 9 |
| 10 class Filter(object): | 10 class Filter(object): |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 filter: An instance of a subclass of Filter. | 93 filter: An instance of a subclass of Filter. |
| 94 port_in: Port on which to listen for incoming connections. | 94 port_in: Port on which to listen for incoming connections. |
| 95 address_out: Address to which outgoing connections will go. | 95 address_out: Address to which outgoing connections will go. |
| 96 address_port: Port to which outgoing connections will go. | 96 address_port: Port to which outgoing connections will go. |
| 97 """ | 97 """ |
| 98 self.port_in = port_in | 98 self.port_in = port_in |
| 99 self.address_out = address_out | 99 self.address_out = address_out |
| 100 self.port_out = port_out | 100 self.port_out = port_out |
| 101 self.filter = filter | 101 self.filter = filter |
| 102 | 102 |
| 103 SocketServer.TCPServer.__init__(self, | 103 try: |
| 104 ('', port_in), | 104 SocketServer.TCPServer.__init__(self, |
| 105 self._Handler) | 105 ('', port_in), |
| 106 self._Handler) | |
| 107 except socket.error: | |
| 108 import os | |
|
sosa
2011/01/19 20:07:55
please import os at the top
| |
| 109 os.system("sudo netstat -l --tcp -n -p") | |
|
sosa
2011/01/19 20:07:55
use '' rather than "" to be consistent.
| |
| 110 raise | |
| 106 | 111 |
| 107 def serve_forever_in_thread(self): | 112 def serve_forever_in_thread(self): |
| 108 """Helper method to start the server in a new background thread.""" | 113 """Helper method to start the server in a new background thread.""" |
| 109 server_thread = threading.Thread(target=self.serve_forever) | 114 server_thread = threading.Thread(target=self.serve_forever) |
| 110 server_thread.setDaemon(True) | 115 server_thread.setDaemon(True) |
| 111 server_thread.start() | 116 server_thread.start() |
| 112 | 117 |
| 113 return server_thread | 118 return server_thread |
| OLD | NEW |