diff options
author | Jan Kundrát <jkt@kde.org> | 2014-11-20 04:36:36 +0100 |
---|---|---|
committer | Jan Kundrát <jkt@kde.org> | 2014-11-20 18:46:55 +0100 |
commit | 508eacdd00b41242ce2cc36e995531633c35b1df (patch) | |
tree | 69eabac6cc78f00095245183bab55ff54348937d | |
parent | 7bad8c1b9275bfacc47e7d5b8ba5abb6204a0c21 (diff) | |
download | gear-508eacdd00b41242ce2cc36e995531633c35b1df.tar.gz |
Support binding to a specified host name or address
As it happens, my CentOS7 system has broken getaddrinfo which apparently
prefers IPv4-only sockets:
>>> socket.getaddrinfo(None, 12345, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
[(2, 1, 6, '', ('0.0.0.0', 12345)),
(10, 1, 6, '', ('::', 12345, 0, 0))]
That's kind of a bummer on a host which is supposed to be reachable only
through IPv6.
I don't feel like waiting for
https://sourceware.org/bugzilla/show_bug.cgi?id=9981 to get fixed, and
binding to a correct socket sounds like a good idea anyway, hence this
patch. I'll be extending zuul with the same feature as well.
Change-Id: I884e0ddcaac9c7de35b913dc967a47ee854d0a8a
-rw-r--r-- | gear/__init__.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/gear/__init__.py b/gear/__init__.py index fd8ad09..13d5c9d 100644 --- a/gear/__init__.py +++ b/gear/__init__.py @@ -2236,11 +2236,13 @@ class Server(BaseClientServer): gear.Server.server_id). Defaults to None (unused). :arg ACL acl: An :py:class:`ACL` object if the server should apply access control rules to its connections. + :arg str host: Host name or IPv4/IPv6 address to bind to. Defaults + to "whatever getaddrinfo() returns", which might be IPv4-only. """ def __init__(self, port=4730, ssl_key=None, ssl_cert=None, ssl_ca=None, statsd_host=None, statsd_port=8125, statsd_prefix=None, - server_id=None, acl=None): + server_id=None, acl=None, host=None): self.port = port self.ssl_key = ssl_key self.ssl_cert = ssl_cert @@ -2258,7 +2260,7 @@ class Server(BaseClientServer): if all([self.ssl_key, self.ssl_cert, self.ssl_ca]): self.use_ssl = True - for res in socket.getaddrinfo(None, self.port, socket.AF_UNSPEC, + for res in socket.getaddrinfo(host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): af, socktype, proto, canonname, sa = res |