Skip to content
Open
Changes from all commits
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
14 changes: 13 additions & 1 deletion fluent/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def close(self):
self._close()
self.pendings = None

def _is_ipv4_host(self):
try:
socket.getaddrinfo(self.host, None, socket.AF_INET)
return True
except socket.error:
return False

def _make_packet(self, label, timestamp, data):
if label:
tag = '.'.join((self.tag, label))
Expand Down Expand Up @@ -203,7 +210,12 @@ 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._is_ipv4_host():
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
else:
sock = socket.socket(socket.AF_INET6,
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