Use StreamServerEndpointService (available since Twisted 10.2)
This commit is contained in:
parent
dc6416a257
commit
6aa8a47f9a
|
@ -1,27 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
from twisted.python import log
|
||||
from twisted.internet import defer
|
||||
from twisted.application import service
|
||||
|
||||
# this should probably live in Twisted
|
||||
|
||||
class ServerEndpointService(service.Service):
|
||||
def __init__(self, endpoint, factory):
|
||||
self.endpoint = endpoint
|
||||
self.factory = factory
|
||||
self._started = defer.Deferred()
|
||||
self._listeningport = None
|
||||
|
||||
def startService(self):
|
||||
d = self.endpoint.listen(self.factory)
|
||||
def _set_port(listeningport):
|
||||
self._listeningport = listeningport
|
||||
self._started.callback(listeningport)
|
||||
d.addCallback(_set_port)
|
||||
d.addErrback(log.err)
|
||||
|
||||
def stopService(self):
|
||||
def _stop(port):
|
||||
return port.stopListening()
|
||||
self._started.addCallback(_stop)
|
||||
return self._started
|
|
@ -7,7 +7,6 @@ from twisted.internet import reactor, endpoints
|
|||
from twisted.application import service, internet
|
||||
from twisted.web import server, static, resource
|
||||
from autobahn.twisted.resource import WebSocketResource
|
||||
from .endpoint_service import ServerEndpointService
|
||||
from .. import __version__
|
||||
from .database import get_db
|
||||
from .rendezvous import Rendezvous
|
||||
|
@ -71,14 +70,14 @@ class RelayServer(service.MultiService):
|
|||
site.logRequests = False
|
||||
|
||||
r = endpoints.serverFromString(reactor, rendezvous_web_port)
|
||||
rendezvous_web_service = ServerEndpointService(r, site)
|
||||
rendezvous_web_service = internet.StreamServerEndpointService(r, site)
|
||||
rendezvous_web_service.setServiceParent(self)
|
||||
|
||||
if transit_port:
|
||||
transit = Transit(db, blur_usage)
|
||||
transit.setServiceParent(self) # for the timer
|
||||
t = endpoints.serverFromString(reactor, transit_port)
|
||||
transit_service = ServerEndpointService(t, transit)
|
||||
transit_service = internet.StreamServerEndpointService(t, transit)
|
||||
transit_service.setServiceParent(self)
|
||||
|
||||
self._stats_file = stats_file
|
||||
|
|
Loading…
Reference in New Issue
Block a user