Esempio n. 1
0
    def __init__(self, loop=None, sock=None):
        super(Socket, self).__init__()
        self._socket = None
        self._loop = loop if loop is not None else instance()
        self._buffers = collections.deque()
        self._state = STATE_INITIALIZED
        self._connect_handler = None
        self._write_handler = None
        self._paused = False

        if sock is None:
            # create socket lazily
            pass
        else:
            # initialize using existing socket
            self._socket = sock
            sock.setblocking(False)
            self._init_streaming()
Esempio n. 2
0
    def __init__(self, loop=None, sock=None):
        super(Socket, self).__init__()
        self._socket = None
        self._loop = loop if loop is not None else instance()
        self._buffers = collections.deque()
        self._state = STATE_INITIALIZED
        self._connect_handler = None
        self._write_handler = None
        self._paused = False

        if sock is None:
            # create socket lazily
            pass
        else:
            # initialize using existing socket
            self._socket = sock
            sock.setblocking(False)
            self._init_streaming()
Esempio n. 3
0
    def __init__(self, address, loop=None):
        super(Server, self).__init__()
        self._address = address
        self._loop = loop if loop is not None else instance()
        self._socket = None

        addrs = socket.getaddrinfo(address[0], address[1], 0, 0, socket.SOL_TCP)
        # support both IPv4 and IPv6 addresses
        if addrs:
            addr = addrs[0]
            self._socket = socket.socket(addr[0], addr[1], addr[2])
            self._socket.setblocking(False)
            self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self._socket.bind(addr[4])
        else:
            self._error(Exception('can not resolve hostname %s' % address[0]))
            return

        self._state = STATE_INITIALIZED
Esempio n. 4
0
    def __init__(self, address, loop=None):
        super(Server, self).__init__()
        self._address = address
        self._loop = loop if loop is not None else instance()
        self._socket = None

        addrs = socket.getaddrinfo(address[0], address[1], 0, 0, socket.SOL_TCP)
        # support both IPv4 and IPv6 addresses
        if addrs:
            addr = addrs[0]
            self._socket = socket.socket(addr[0], addr[1], addr[2])
            self._socket.setblocking(False)
            self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self._socket.bind(addr[4])
        else:
            self._error(Exception("can not resolve hostname %s" % address[0]))
            return

        self._state = STATE_INITIALIZED