Skip to content

Commit

Permalink
enable listening on IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
toddjcrane committed Dec 12, 2016
1 parent 4c19dab commit b1f2f7d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bjoern.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ def bind_and_listen(host, port=None, reuse_port=False):
# UNIX socket: "unix:/tmp/foobar.sock"
sock = socket.socket(socket.AF_UNIX)
sock.bind(host[5:])
elif hasattr(socket, 'AF_INET6') and (len(host) == 0 or ':' in host):
#IPv6 socket
sock = socket.socket(socket.AF_INET6)
# Set SO_REUSEADDR to make the IP address available for reuse
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if reuse_port:
# Enable "receive steering" on FreeBSD and Linux >=3.9. This allows
# multiple independent bjoerns to bind to the same port (and ideally
# also set their CPU affinity), resulting in more efficient load
# distribution. https://lwn.net/Articles/542629/
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
sock.bind((host, port))
else:
# IP socket
sock = socket.socket(socket.AF_INET)
Expand Down

0 comments on commit b1f2f7d

Please sign in to comment.