File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,17 @@ def close(self):
121
121
122
122
self ._close ()
123
123
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
124
135
125
136
def _make_packet (self , label , timestamp , data ):
126
137
if label :
@@ -203,7 +214,10 @@ def _reconnect(self):
203
214
sock .settimeout (self .timeout )
204
215
sock .connect (self .host [len ('unix://' ):])
205
216
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 )
207
221
sock .settimeout (self .timeout )
208
222
# This might be controversial and may need to be removed
209
223
sock .setsockopt (socket .IPPROTO_TCP , socket .TCP_NODELAY , 1 )
You can’t perform that action at this time.
0 commit comments