-
-
Save teh/66b3ccca73abf962cada to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 6ea4937943d2f4a21a8e724151f49cd0fccdd5b4 Mon Sep 17 00:00:00 2001 | |
From: Thomas Hunger <[email protected]> | |
Date: Sun, 18 Mar 2012 00:13:06 +0000 | |
Subject: [PATCH] Prefer IPv4 over IPv6 when connecting. | |
--- | |
desir/desir.py | 5 ++++- | |
1 files changed, 4 insertions(+), 1 deletions(-) | |
diff --git a/desir/desir.py b/desir/desir.py | |
index dbe4d0f..c25d772 100644 | |
--- a/desir/desir.py | |
+++ b/desir/desir.py | |
@@ -431,7 +431,10 @@ class Node(object): | |
if self._sock: | |
return | |
- family, _, _, _, _ = socket.getaddrinfo(self.host, self.port)[0] | |
+ addrinfo = socket.getaddrinfo(self.host, self.port) | |
+ addrinfo.sort(key=lambda x: 0 if x[0] == socket.AF_INET else 1) | |
+ family, _, _, _, _ = addrinfo[0] | |
+ | |
sock = socket.socket(family, socket.SOCK_STREAM) | |
try: | |
sock.connect((self.host, self.port)) | |
-- | |
1.7.2.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment