File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,13 @@ def close(self):
120120 self ._close ()
121121 self .pendings = None
122122
123+ def _is_ipv4_host (self ):
124+ try :
125+ socket .getaddrinfo (self .host , None , socket .AF_INET )
126+ return True
127+ except socket .error :
128+ return False
129+
123130 def _make_packet (self , label , timestamp , data ):
124131 if label :
125132 tag = '.' .join ((self .tag , label ))
@@ -201,7 +208,12 @@ def _reconnect(self):
201208 sock .settimeout (self .timeout )
202209 sock .connect (self .host [len ('unix://' ):])
203210 else :
204- sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
211+ if self ._is_ipv4_host ():
212+ sock = socket .socket (socket .AF_INET ,
213+ socket .SOCK_STREAM )
214+ else :
215+ sock = socket .socket (socket .AF_INET6 ,
216+ socket .SOCK_STREAM )
205217 sock .settimeout (self .timeout )
206218 # This might be controversial and may need to be removed
207219 sock .setsockopt (socket .IPPROTO_TCP , socket .TCP_NODELAY , 1 )
You can’t perform that action at this time.
0 commit comments