implement Happy Eyeballs
This allows OfflineIMAP to not stall on malfunctional IPv6 connections, and fall-back to a functional IPv4 connection, if faster, as described in RFC6555. Signed-off-by: Olivier Mehani <shtrom@ssji.net> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
06ed00a211
commit
0d5496ba0a
@ -19,6 +19,7 @@ import fcntl
|
|||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
import rfc6555
|
||||||
import socket
|
import socket
|
||||||
import errno
|
import errno
|
||||||
import zlib
|
import zlib
|
||||||
@ -78,8 +79,15 @@ class UsefulIMAPMixIn(object):
|
|||||||
def open_socket(self):
|
def open_socket(self):
|
||||||
"""open_socket()
|
"""open_socket()
|
||||||
Open socket choosing first address family available."""
|
Open socket choosing first address family available."""
|
||||||
|
if self.af == socket.AF_UNSPEC:
|
||||||
|
# happy-eyeballs!
|
||||||
|
return rfc6555.create_connection((self.host, self.port))
|
||||||
|
else:
|
||||||
|
return self._open_socket_for_af(self.af)
|
||||||
|
|
||||||
|
def _open_socket_for_af(self, af):
|
||||||
msg = (-1, 'could not open socket')
|
msg = (-1, 'could not open socket')
|
||||||
for res in socket.getaddrinfo(self.host, self.port, self.af, socket.SOCK_STREAM):
|
for res in socket.getaddrinfo(self.host, self.port, af, socket.SOCK_STREAM):
|
||||||
af, socktype, proto, canonname, sa = res
|
af, socktype, proto, canonname, sa = res
|
||||||
try:
|
try:
|
||||||
# use socket of our own, possiblly socksified socket.
|
# use socket of our own, possiblly socksified socket.
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
six
|
six
|
||||||
gssapi[kerberos]
|
gssapi[kerberos]
|
||||||
portalocker[cygwin]
|
portalocker[cygwin]
|
||||||
|
rfc6555
|
||||||
|
Loading…
Reference in New Issue
Block a user