mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Make the interface/port to listen on an option
This commit is contained in:
parent
c75ec6358d
commit
113cc0cc0c
@ -274,7 +274,6 @@ class ServerLoop(object):
|
||||
def __init__(
|
||||
self,
|
||||
handler,
|
||||
bind_address=('localhost', 8080),
|
||||
opts=None,
|
||||
# A calibre logging object. If None, a default log that logs to
|
||||
# stdout is used
|
||||
@ -285,7 +284,7 @@ class ServerLoop(object):
|
||||
self.opts = opts or Options()
|
||||
self.log = log or ThreadSafeLog(level=ThreadSafeLog.DEBUG)
|
||||
|
||||
ba = tuple(bind_address)
|
||||
ba = (opts.listen_on, int(opts.port))
|
||||
if not ba[0]:
|
||||
# AI_PASSIVE does not work with host of '' or None
|
||||
ba = ('0.0.0.0', ba[1])
|
||||
|
@ -56,6 +56,16 @@ raw_options = (
|
||||
'worker_count', 10,
|
||||
None,
|
||||
|
||||
'The port on which to listen for connections',
|
||||
'port', 8080,
|
||||
None,
|
||||
|
||||
'The interface on which to listen for connections',
|
||||
'listen_on', '0.0.0.0',
|
||||
'The default is to listen on all available interfaces. You can change this to, for'
|
||||
' example, "127.0.0.1" to only listen for connections from the local machine, or'
|
||||
' to "::" to listen to all incoming IPv6 and IPv4 connections.',
|
||||
|
||||
'Use zero copy file transfers for increased performance',
|
||||
'use_sendfile', True,
|
||||
'This will use zero-copy in-kernel transfers when sending files over the network,'
|
||||
|
@ -38,10 +38,11 @@ class TestServer(Thread):
|
||||
from calibre.srv.loop import ServerLoop
|
||||
from calibre.srv.http_response import create_http_handler
|
||||
kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1)
|
||||
kwargs['listen_on'] = kwargs.get('listen_on', 'localhost')
|
||||
kwargs['port'] = kwargs.get('port', 0)
|
||||
self.loop = ServerLoop(
|
||||
create_http_handler(handler),
|
||||
opts=Options(**kwargs),
|
||||
bind_address=('localhost', 0),
|
||||
log=TestLog(level=ThreadSafeLog.WARN),
|
||||
)
|
||||
self.log = self.loop.log
|
||||
|
Loading…
x
Reference in New Issue
Block a user