Exemplo n.º 1
0
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
    """Connect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.
    """

    msg = "getaddrinfo returns an empty list"
    host, port = address
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket(af, socktype, proto)
            if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                sock.settimeout(timeout)
            sock.connect(sa)
            return sock

        except error, msg:
            if sock is not None:
                sock.close()
Exemplo n.º 2
0
 def socketpair(*args):
     one, two = __original_socketpair__(*args)
     return socket(one), socket(two)
Exemplo n.º 3
0
 def fromfd(*args):
     return socket(__original_fromfd__(*args))
Exemplo n.º 4
0
 def socketpair(*args):
     one, two = __original_socketpair__(*args)
     return socket(one), socket(two)
Exemplo n.º 5
0
 def fromfd(*args):
     return socket(__original_fromfd__(*args))
Exemplo n.º 6
0
def fromfd(*args):
    return socket(__socket.fromfd(*args))