Adapt flash socket policy branch to new nova/wsgi.py refactoring

This commit is contained in:
Jimmy Bergman 2011-06-30 08:55:56 +02:00
parent cb1f9e011c
commit 3d69762740

View File

@ -67,6 +67,7 @@ class Server(object):
self.host = host or "0.0.0.0"
self.port = port or 0
self._server = None
self._tcp_server = None
self._socket = None
self._pool = eventlet.GreenPool(pool_size or self.default_pool_size)
self._logger = logging.getLogger("eventlet.wsgi.server")
@ -106,15 +107,16 @@ class Server(object):
"""
LOG.info(_("Stopping WSGI server."))
self._server.kill()
if self._tcp_server is not None:
LOG.info(_("Stopping raw TCP server."))
self._tcp_server.kill()
def start_tcp(self, listener, port, host='0.0.0.0', key=None, backlog=128):
"""Run a raw TCP server with the given application."""
arg0 = sys.argv[0]
logging.audit(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') % locals())
LOG.info(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') % locals())
socket = eventlet.listen((host, port), backlog=backlog)
self.pool.spawn_n(self._run_tcp, listener, socket)
if key:
self.socket_info[key] = socket.getsockname()
self._tcp_server = self._pool.spawn_n(self._run_tcp, listener, socket)
def wait(self):
"""Block, until the server has stopped.
@ -134,7 +136,7 @@ class Server(object):
while True:
try:
new_sock, address = socket.accept()
self.pool.spawn_n(listener, new_sock)
self._pool.spawn_n(listener, new_sock)
except (SystemExit, KeyboardInterrupt):
pass