mirror of
https://github.com/django/daphne.git
synced 2024-11-22 07:56:34 +03:00
build_endpoint_description_string is now a normal function
This commit is contained in:
parent
76b441ecdf
commit
5ea0749c5f
|
@ -2,7 +2,7 @@ import sys
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import importlib
|
import importlib
|
||||||
from .server import Server
|
from .server import Server, build_endpoint_description_strings
|
||||||
from .access import AccessLogGenerator
|
from .access import AccessLogGenerator
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,19 +165,24 @@ class CommandLineInterface(object):
|
||||||
elif args.port and not args.host:
|
elif args.port and not args.host:
|
||||||
args.host = DEFAULT_HOST
|
args.host = DEFAULT_HOST
|
||||||
|
|
||||||
# Run server
|
# build endpoint description strings from (optional) cli arguments
|
||||||
logger.info(
|
endpoints = build_endpoint_description_strings(
|
||||||
"Starting server at %s, channel layer %s",
|
|
||||||
(args.unix_socket if args.unix_socket else "%s:%s" % (args.host, args.port)),
|
|
||||||
args.channel_layer,
|
|
||||||
)
|
|
||||||
self.server = Server(
|
|
||||||
channel_layer=channel_layer,
|
|
||||||
host=args.host,
|
host=args.host,
|
||||||
port=args.port,
|
port=args.port,
|
||||||
unix_socket=args.unix_socket,
|
unix_socket=args.unix_socket,
|
||||||
file_descriptor=args.file_descriptor,
|
file_descriptor=args.file_descriptor
|
||||||
endpoints=args.socket_strings,
|
)
|
||||||
|
endpoints = sorted(
|
||||||
|
args.socket_strings + endpoints
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
'Starting server at %s, channel layer %s.' %
|
||||||
|
(endpoints.join(', '), args.channel_layer)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.server = Server(
|
||||||
|
channel_layer=channel_layer,
|
||||||
|
endpoints=endpoints,
|
||||||
http_timeout=args.http_timeout,
|
http_timeout=args.http_timeout,
|
||||||
ping_interval=args.ping_interval,
|
ping_interval=args.ping_interval,
|
||||||
ping_timeout=args.ping_timeout,
|
ping_timeout=args.ping_timeout,
|
||||||
|
|
|
@ -33,13 +33,19 @@ class Server(object):
|
||||||
verbosity=1
|
verbosity=1
|
||||||
):
|
):
|
||||||
self.channel_layer = channel_layer
|
self.channel_layer = channel_layer
|
||||||
|
self.endpoints = endpoints
|
||||||
|
|
||||||
self.endpoints = sorted(endpoints + self.build_endpoint_description_strings(
|
if any([host, port, unix_socket, file_descriptor]):
|
||||||
host=host,
|
raise DeprecationWarning('''
|
||||||
port=port,
|
The host/port/unix_socket/file_descriptor keyword arguments to %s are deprecated.
|
||||||
unix_socket=unix_socket,
|
''' % self.__class__.__name__)
|
||||||
file_descriptor=file_descriptor
|
# build endpoint description strings from deprecated kwargs
|
||||||
))
|
self.endpoints = sorted(self.endpoints + build_endpoint_description_strings(
|
||||||
|
host=host,
|
||||||
|
port=port,
|
||||||
|
unix_socket=unix_socket,
|
||||||
|
file_descriptor=file_descriptor
|
||||||
|
))
|
||||||
|
|
||||||
if len(self.endpoints) == 0:
|
if len(self.endpoints) == 0:
|
||||||
raise UserWarning("No endpoints. This server will not listen on anything.")
|
raise UserWarning("No endpoints. This server will not listen on anything.")
|
||||||
|
@ -163,29 +169,31 @@ class Server(object):
|
||||||
self.factory.check_timeouts()
|
self.factory.check_timeouts()
|
||||||
reactor.callLater(2, self.timeout_checker)
|
reactor.callLater(2, self.timeout_checker)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def build_endpoint_description_strings(
|
def build_endpoint_description_strings(
|
||||||
host=None,
|
host=None,
|
||||||
port=None,
|
port=None,
|
||||||
unix_socket=None,
|
unix_socket=None,
|
||||||
file_descriptor=None
|
file_descriptor=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Build a list of twisted endpoint description strings that the server will listen on
|
Build a list of twisted endpoint description strings that the server will listen on.
|
||||||
"""
|
This is to streamline the generation of twisted endpoint description strings from easier
|
||||||
socket_descriptions = []
|
to use command line args such as host, port, unix sockets etc.
|
||||||
if host and port:
|
"""
|
||||||
socket_descriptions.append('tcp:port=%d:interface=%s' % (int(port), host))
|
socket_descriptions = []
|
||||||
elif any([host, port]):
|
if host and port:
|
||||||
raise ValueError('TCP binding requires both port and host kwargs.')
|
socket_descriptions.append('tcp:port=%d:interface=%s' % (int(port), host))
|
||||||
|
elif any([host, port]):
|
||||||
|
raise ValueError('TCP binding requires both port and host kwargs.')
|
||||||
|
|
||||||
if unix_socket:
|
if unix_socket:
|
||||||
socket_descriptions.append('unix:%s' % unix_socket)
|
socket_descriptions.append('unix:%s' % unix_socket)
|
||||||
|
|
||||||
if file_descriptor:
|
if file_descriptor:
|
||||||
socket_descriptions.append('fd:domain=INET:fileno=%d' % int(file_descriptor))
|
socket_descriptions.append('fd:domain=INET:fileno=%d' % int(file_descriptor))
|
||||||
|
|
||||||
return socket_descriptions
|
return socket_descriptions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user