コード例 #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()
コード例 #2
0
 def socketpair(*args):
     one, two = __original_socketpair__(*args)
     return socket(one), socket(two)
コード例 #3
0
 def fromfd(*args):
     return socket(__original_fromfd__(*args))
コード例 #4
0
 def socketpair(*args):
     one, two = __original_socketpair__(*args)
     return socket(one), socket(two)
コード例 #5
0
 def fromfd(*args):
     return socket(__original_fromfd__(*args))
コード例 #6
0
ファイル: socket.py プロジェクト: esh/invaders
def fromfd(*args):
    return socket(__socket.fromfd(*args))