mirror of
				https://github.com/django/daphne.git
				synced 2025-11-04 01:27:33 +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',
 | 
			
		||||
            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(
 | 
			
		||||
            '-v',
 | 
			
		||||
            '--verbosity',
 | 
			
		||||
| 
						 | 
				
			
			@ -83,14 +90,14 @@ class CommandLineInterface(object):
 | 
			
		|||
            channel_layer = getattr(channel_layer, bit)
 | 
			
		||||
        # Run server
 | 
			
		||||
        logger.info(
 | 
			
		||||
            "Starting server on %s:%s, channel layer %s",
 | 
			
		||||
            args.host,
 | 
			
		||||
            args.port,
 | 
			
		||||
            "Starting server at %s, channel layer %s",
 | 
			
		||||
            (args.unix_socket if args.unix_socket else "%s:%s" % (args.host, args.port)),
 | 
			
		||||
            args.channel_layer,
 | 
			
		||||
        )
 | 
			
		||||
        Server(
 | 
			
		||||
            channel_layer=channel_layer,
 | 
			
		||||
            host=args.host,
 | 
			
		||||
            port=args.port,
 | 
			
		||||
            unix_socket=args.unix_socket,
 | 
			
		||||
            http_timeout=args.http_timeout,
 | 
			
		||||
        ).run()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ class Server(object):
 | 
			
		|||
        channel_layer,
 | 
			
		||||
        host="127.0.0.1",
 | 
			
		||||
        port=8000,
 | 
			
		||||
        unix_socket=None,
 | 
			
		||||
        signal_handlers=True,
 | 
			
		||||
        action_logger=None,
 | 
			
		||||
        http_timeout=120,
 | 
			
		||||
| 
						 | 
				
			
			@ -21,6 +22,7 @@ class Server(object):
 | 
			
		|||
        self.channel_layer = channel_layer
 | 
			
		||||
        self.host = host
 | 
			
		||||
        self.port = port
 | 
			
		||||
        self.unix_socket = unix_socket
 | 
			
		||||
        self.signal_handlers = signal_handlers
 | 
			
		||||
        self.action_logger = action_logger
 | 
			
		||||
        self.http_timeout = http_timeout
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +37,9 @@ class Server(object):
 | 
			
		|||
            timeout=self.http_timeout,
 | 
			
		||||
            websocket_timeout=self.websocket_timeout,
 | 
			
		||||
        )
 | 
			
		||||
        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(2, self.timeout_checker)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user