Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This is a python sync server used for testing Chrome Sync. | 6 """This is a python sync server used for testing Chrome Sync. |
| 7 | 7 |
| 8 By default, it listens on an ephemeral port and xmpp_port and sends the port | 8 By default, it listens on an ephemeral port and xmpp_port and sends the port |
| 9 numbers back to the originating process over a pipe. The originating process can | 9 numbers back to the originating process over a pipe. The originating process can |
| 10 specify an explicit port and xmpp_port if necessary. | 10 specify an explicit port and xmpp_port if necessary. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import asyncore | 13 import asyncore |
| 14 import BaseHTTPServer | 14 import BaseHTTPServer |
| 15 import errno | 15 import errno |
| 16 import os | 16 import os |
| 17 import select | 17 import select |
| 18 import socket | 18 import socket |
| 19 import sys | 19 import sys |
| 20 import urlparse | 20 import urlparse |
| 21 | 21 |
| 22 import chromiumsync | 22 import chromiumsync |
| 23 import echo_message | 23 import echo_message |
| 24 import testserver_base | 24 import testserver_base |
| 25 import xmppserver | 25 import xmppserver |
| 26 | 26 |
| 27 | 27 |
| 28 class SyncHTTPServer(testserver_base.ClientRestrictingServerMixIn, | 28 class SyncHTTPServer(testserver_base.ClientRestrictingServerMixIn, |
|
maniscalco
2015/01/06 18:39:59
What's the overall goal of this change? Does the
sigbjorn
2015/01/07 09:26:34
This allows for clean shutdown of the server. On L
| |
| 29 testserver_base.BrokenPipeHandlerMixIn, | 29 testserver_base.BrokenPipeHandlerMixIn, |
| 30 testserver_base.StoppableHTTPServer): | 30 BaseHTTPServer.HTTPServer): |
| 31 """An HTTP server that handles sync commands.""" | 31 """An HTTP server that handles sync commands.""" |
| 32 | 32 |
| 33 def __init__(self, server_address, xmpp_port, request_handler_class): | 33 def __init__(self, server_address, xmpp_port, request_handler_class): |
| 34 testserver_base.StoppableHTTPServer.__init__(self, | 34 BaseHTTPServer.HTTPServer.__init__(self, |
| 35 server_address, | 35 server_address, |
| 36 request_handler_class) | 36 request_handler_class) |
| 37 self._sync_handler = chromiumsync.TestServer() | 37 self._sync_handler = chromiumsync.TestServer() |
| 38 self._xmpp_socket_map = {} | 38 self._xmpp_socket_map = {} |
| 39 self._xmpp_server = xmppserver.XmppServer( | 39 self._xmpp_server = xmppserver.XmppServer( |
| 40 self._xmpp_socket_map, ('localhost', xmpp_port)) | 40 self._xmpp_socket_map, ('localhost', xmpp_port)) |
| 41 self.xmpp_port = self._xmpp_server.getsockname()[1] | 41 self.xmpp_port = self._xmpp_server.getsockname()[1] |
| 42 self.authenticated = True | 42 self.authenticated = True |
| 43 | 43 |
| 44 def GetXmppServer(self): | 44 def GetXmppServer(self): |
| 45 return self._xmpp_server | 45 return self._xmpp_server |
| 46 | 46 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 # removed from socket_map. | 85 # removed from socket_map. |
| 86 if xmpp_connection is None: | 86 if xmpp_connection is None: |
| 87 return | 87 return |
| 88 try: | 88 try: |
| 89 handler(xmpp_connection) | 89 handler(xmpp_connection) |
| 90 except (asyncore.ExitNow, KeyboardInterrupt, SystemExit): | 90 except (asyncore.ExitNow, KeyboardInterrupt, SystemExit): |
| 91 raise | 91 raise |
| 92 except: | 92 except: |
| 93 xmpp_connection.handle_error() | 93 xmpp_connection.handle_error() |
| 94 | 94 |
| 95 while True: | 95 self.stop = False |
|
pval...(no longer on Chromium)
2015/01/05 17:49:01
when/where can this be set to True?
sigbjorn
2015/01/06 08:11:27
This would be set to True from the calling thread.
maniscalco
2015/01/06 18:39:59
Maybe I'm missing something, why not create a Stop
sigbjorn
2015/01/07 09:26:34
The reason is compatibility. This is what Stoppabl
| |
| 96 while not self.stop: | |
| 96 read_fds = [ self.fileno() ] | 97 read_fds = [ self.fileno() ] |
| 97 write_fds = [] | 98 write_fds = [] |
| 98 exceptional_fds = [] | 99 exceptional_fds = [] |
| 99 | 100 |
| 100 for fd, xmpp_connection in self._xmpp_socket_map.items(): | 101 for fd, xmpp_connection in self._xmpp_socket_map.items(): |
| 101 is_r = xmpp_connection.readable() | 102 is_r = xmpp_connection.readable() |
| 102 is_w = xmpp_connection.writable() | 103 is_w = xmpp_connection.writable() |
| 103 if is_r: | 104 if is_r: |
| 104 read_fds.append(fd) | 105 read_fds.append(fd) |
| 105 if is_w: | 106 if is_w: |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 testserver_base.TestServerRunner.add_options(self) | 558 testserver_base.TestServerRunner.add_options(self) |
| 558 self.option_parser.add_option('--xmpp-port', default='0', type='int', | 559 self.option_parser.add_option('--xmpp-port', default='0', type='int', |
| 559 help='Port used by the XMPP server. If ' | 560 help='Port used by the XMPP server. If ' |
| 560 'unspecified, the XMPP server will listen on ' | 561 'unspecified, the XMPP server will listen on ' |
| 561 'an ephemeral port.') | 562 'an ephemeral port.') |
| 562 # Override the default logfile name used in testserver.py. | 563 # Override the default logfile name used in testserver.py. |
| 563 self.option_parser.set_defaults(log_file='sync_testserver.log') | 564 self.option_parser.set_defaults(log_file='sync_testserver.log') |
| 564 | 565 |
| 565 if __name__ == '__main__': | 566 if __name__ == '__main__': |
| 566 sys.exit(SyncServerRunner().main()) | 567 sys.exit(SyncServerRunner().main()) |
| OLD | NEW |