mirror of
https://github.com/django/daphne.git
synced 2024-11-25 17:23:43 +03:00
Allow binding to UNIX sockets instead of TCP address/port.
This commit is contained in:
parent
037f129117
commit
5cb28d1e10
|
@ -33,6 +33,13 @@ class CommandLineInterface(object):
|
||||||
help='The host/address to bind to',
|
help='The host/address to bind to',
|
||||||
default="127.0.0.1",
|
default="127.0.0.1",
|
||||||
)
|
)
|
||||||
|
self.parser.add_argument(
|
||||||
|
'-u',
|
||||||
|
'--unix-socket',
|
||||||
|
dest='unix_socket',
|
||||||
|
help='Bind to a UNIX socket rather than a TCP host/port',
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
self.parser.add_argument(
|
self.parser.add_argument(
|
||||||
'-v',
|
'-v',
|
||||||
'--verbosity',
|
'--verbosity',
|
||||||
|
@ -83,14 +90,14 @@ class CommandLineInterface(object):
|
||||||
channel_layer = getattr(channel_layer, bit)
|
channel_layer = getattr(channel_layer, bit)
|
||||||
# Run server
|
# Run server
|
||||||
logger.info(
|
logger.info(
|
||||||
"Starting server on %s:%s, channel layer %s",
|
"Starting server at %s, channel layer %s",
|
||||||
args.host,
|
(args.unix_socket if args.unix_socket else "%s:%s" % (args.host, args.port)),
|
||||||
args.port,
|
|
||||||
args.channel_layer,
|
args.channel_layer,
|
||||||
)
|
)
|
||||||
Server(
|
Server(
|
||||||
channel_layer=channel_layer,
|
channel_layer=channel_layer,
|
||||||
host=args.host,
|
host=args.host,
|
||||||
port=args.port,
|
port=args.port,
|
||||||
|
unix_socket=args.unix_socket,
|
||||||
http_timeout=args.http_timeout,
|
http_timeout=args.http_timeout,
|
||||||
).run()
|
).run()
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Server(object):
|
||||||
channel_layer,
|
channel_layer,
|
||||||
host="127.0.0.1",
|
host="127.0.0.1",
|
||||||
port=8000,
|
port=8000,
|
||||||
|
unix_socket=None,
|
||||||
signal_handlers=True,
|
signal_handlers=True,
|
||||||
action_logger=None,
|
action_logger=None,
|
||||||
http_timeout=120,
|
http_timeout=120,
|
||||||
|
@ -21,6 +22,7 @@ class Server(object):
|
||||||
self.channel_layer = channel_layer
|
self.channel_layer = channel_layer
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.unix_socket = unix_socket
|
||||||
self.signal_handlers = signal_handlers
|
self.signal_handlers = signal_handlers
|
||||||
self.action_logger = action_logger
|
self.action_logger = action_logger
|
||||||
self.http_timeout = http_timeout
|
self.http_timeout = http_timeout
|
||||||
|
@ -35,7 +37,10 @@ class Server(object):
|
||||||
timeout=self.http_timeout,
|
timeout=self.http_timeout,
|
||||||
websocket_timeout=self.websocket_timeout,
|
websocket_timeout=self.websocket_timeout,
|
||||||
)
|
)
|
||||||
reactor.listenTCP(self.port, self.factory, interface=self.host)
|
if self.unix_socket:
|
||||||
|
reactor.listenUNIX(self.unix_socket, self.factory)
|
||||||
|
else:
|
||||||
|
reactor.listenTCP(self.port, self.factory, interface=self.host)
|
||||||
reactor.callLater(0, self.backend_reader)
|
reactor.callLater(0, self.backend_reader)
|
||||||
reactor.callLater(2, self.timeout_checker)
|
reactor.callLater(2, self.timeout_checker)
|
||||||
reactor.run(installSignalHandlers=self.signal_handlers)
|
reactor.run(installSignalHandlers=self.signal_handlers)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user