Skip to content

Commit 9a139a5

Browse files
arcivanovmcipperly
authored andcommitted
Add compatibility for Ipv6 address
Signed-off-by: Matt Cipperly <mcipperly@fb.com>
1 parent 20b8fe7 commit 9a139a5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

fluent/sender.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ def close(self):
121121

122122
self._close()
123123
self.pendings = None
124+
125+
def _host_is_ipv6(self) :
126+
try :
127+
socket.inet_pton(socket.AF_INET6, self.host)
128+
return True
129+
except :
130+
try :
131+
socket.inet_aton(self.host)
132+
return False
133+
except Exception as e:
134+
raise e
124135

125136
def _make_packet(self, label, timestamp, data):
126137
if label:
@@ -203,7 +214,10 @@ def _reconnect(self):
203214
sock.settimeout(self.timeout)
204215
sock.connect(self.host[len('unix://'):])
205216
else:
206-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
217+
if self._host_is_ipv6() :
218+
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
219+
else :
220+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
207221
sock.settimeout(self.timeout)
208222
# This might be controversial and may need to be removed
209223
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='fluent-logger',
15-
version='0.9.2',
15+
version='0.9.3',
1616
description=desc,
1717
long_description=open(README).read(),
1818
package_dir={'fluent': 'fluent'},

0 commit comments

Comments
 (0)