Skip to content

Commit

Permalink
Merge edebe05 into 7389fb6
Browse files Browse the repository at this point in the history
  • Loading branch information
koolok committed May 3, 2018
2 parents 7389fb6 + edebe05 commit fca3b30
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion fluent/sender.py
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

0 comments on commit fca3b30

Please sign in to comment.