Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for Ipv6 address #138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion fluent/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def close(self):

self._close()
self.pendings = None

def _host_is_ipv6(self) :
try :
socket.inet_pton(socket.AF_INET6, self.host)
return True
except :
Copy link
Member

@arcivanov arcivanov Apr 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. PEP8 issue. Formatting all over the place. Bare except is generally frowned upon as it intercepts SystemExit and KeyboardInterrupt.

try :
socket.inet_aton(self.host)
return False
except Exception as e:
raise e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what if host is FQDN???


def _make_packet(self, label, timestamp, data):
if label:
Expand Down Expand Up @@ -203,7 +214,10 @@ def _reconnect(self):
sock.settimeout(self.timeout)
sock.connect(self.host[len('unix://'):])
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self._host_is_ipv6() :
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
else :
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.timeout)
# This might be controversial and may need to be removed
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
Expand Down