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):
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 )
You can’t perform that action at this time.
0 commit comments