Beispiel #1
0
        def _connect(self, address):
            """Connect the socket to a remote address."""
            addr = address.lock()
            res = _c.socketconnect(self.fd, addr, address.addrlen)
            address.unlock()
            errno = _c.geterrno()
            if self.timeout > 0.0 and res < 0 and errno == _c.EINPROGRESS:
                timeout = self._select(True)
                errno = _c.geterrno()
                if timeout == 0:
                    addr = address.lock()
                    res = _c.socketconnect(self.fd, addr, address.addrlen)
                    address.unlock()
                    if res < 0:
                        errno = _c.geterrno()
                        if errno == _c.EISCONN:
                            res = 0
                elif timeout == -1:
                    return (errno, False)
                else:
                    return (_c.EWOULDBLOCK, True)

            if res == 0:
                errno = 0
            return (errno, False)
Beispiel #2
0
        def _connect(self, address):
            """Connect the socket to a remote address."""
            addr = address.lock()
            res = _c.socketconnect(self.fd, addr, address.addrlen)
            address.unlock()
            errno = _c.geterrno()
            if self.timeout > 0.0 and res < 0 and errno == _c.EINPROGRESS:
                timeout = self._select(True)
                errno = _c.geterrno()
                if timeout == 0:
                    addr = address.lock()
                    res = _c.socketconnect(self.fd, addr, address.addrlen)
                    address.unlock()
                    if res < 0:
                        errno = _c.geterrno()
                        if errno == _c.EISCONN:
                            res = 0
                elif timeout == -1:
                    return (errno, False)
                else:
                    return (_c.EWOULDBLOCK, True)

            if res == 0:
                errno = 0
            return (errno, False)
Beispiel #3
0
 def connect(self, address):
     """Connect the socket to a remote address."""
     addr = address.lock()
     res = _c.socketconnect(self.fd, addr, address.addrlen)
     address.unlock()
     if self.timeout > 0.0:
         errno = _c.geterrno()
         if res < 0 and errno == _c.EINPROGRESS:
             timeout = self._select(True)
             if timeout == 0:
                 addr = address.lock()
                 res = _c.socketconnect(self.fd, addr, address.addrlen)
                 address.unlock()
             elif timeout == -1:
                 raise self.error_handler()
             else:
                 raise SocketTimeout
             
     if res != 0:
         raise self.error_handler()
Beispiel #4
0
    def connect(self, address):
        """Connect the socket to a remote address."""
        addr = address.lock()
        res = _c.socketconnect(self.fd, addr, address.addrlen)
        address.unlock()
        if self.timeout > 0.0:
            errno = _c.geterrno()
            if res < 0 and errno == _c.EINPROGRESS:
                timeout = self._select(True)
                if timeout == 0:
                    addr = address.lock()
                    res = _c.socketconnect(self.fd, addr, address.addrlen)
                    address.unlock()
                elif timeout == -1:
                    raise self.error_handler()
                else:
                    raise SocketTimeout

        if res != 0:
            raise self.error_handler()
Beispiel #5
0
 def connect_ex(self, address):
     """This is like connect(address), but returns an error code (the errno
     value) instead of raising an exception when an error occurs."""
     addr = address.lock()
     res = _c.socketconnect(self.fd, addr, address.addrlen)
     address.unlock()
     if self.timeout > 0.0:
         errno = _c.geterrno()
         if res < 0 and errno == _c.EINPROGRESS:
             timeout = self._select(True)
             if timeout == 0:
                 addr = address.lock()
                 res = _c.socketconnect(self.fd, addr, address.addrlen)
                 address.unlock()
             elif timeout == -1:
                 return _c.geterrno()
             else:
                 return _c.EWOULDBLOCK
             
     if res != 0:
         return _c.geterrno()
     return res
Beispiel #6
0
    def connect_ex(self, address):
        """This is like connect(address), but returns an error code (the errno
        value) instead of raising an exception when an error occurs."""
        addr = address.lock()
        res = _c.socketconnect(self.fd, addr, address.addrlen)
        address.unlock()
        if self.timeout > 0.0:
            errno = _c.geterrno()
            if res < 0 and errno == _c.EINPROGRESS:
                timeout = self._select(True)
                if timeout == 0:
                    addr = address.lock()
                    res = _c.socketconnect(self.fd, addr, address.addrlen)
                    address.unlock()
                elif timeout == -1:
                    return _c.geterrno()
                else:
                    return _c.EWOULDBLOCK

        if res != 0:
            return _c.geterrno()
        return res
Beispiel #7
0
        def _connect(self, address):
            """Connect the socket to a remote address."""
            addr = address.lock()
            res = _c.socketconnect(self.fd, addr, address.addrlen)
            address.unlock()
            errno = _c.geterrno()
            timeout = self.timeout
            if timeout > 0.0 and res < 0 and errno == _c.EWOULDBLOCK:
                tv = rffi.make(_c.timeval)
                rffi.setintfield(tv, 'c_tv_sec', int(timeout))
                rffi.setintfield(tv, 'c_tv_usec',
                                 int((timeout-int(timeout)) * 1000000))
                fds = lltype.malloc(_c.fd_set.TO, flavor='raw')
                _c.FD_ZERO(fds)
                _c.FD_SET(self.fd, fds)
                fds_exc = lltype.malloc(_c.fd_set.TO, flavor='raw')
                _c.FD_ZERO(fds_exc)
                _c.FD_SET(self.fd, fds_exc)
                null = lltype.nullptr(_c.fd_set.TO)

                try:
                    n = _c.select(self.fd + 1, null, fds, fds_exc, tv)

                    if n > 0:
                        if _c.FD_ISSET(self.fd, fds):
                            # socket writable == connected
                            return (0, False)
                        else:
                            # per MS docs, call getsockopt() to get error
                            assert _c.FD_ISSET(self.fd, fds_exc)
                            return (self.getsockopt_int(_c.SOL_SOCKET,
                                                        _c.SO_ERROR), False)
                    elif n == 0:
                        return (_c.EWOULDBLOCK, True)
                    else:
                        return (_c.geterrno(), False)

                finally:
                    lltype.free(fds, flavor='raw')
                    lltype.free(fds_exc, flavor='raw')
                    lltype.free(tv, flavor='raw')

            if res == 0:
                errno = 0
            return (errno, False)
Beispiel #8
0
        def _connect(self, address):
            """Connect the socket to a remote address."""
            addr = address.lock()
            res = _c.socketconnect(self.fd, addr, address.addrlen)
            address.unlock()
            errno = _c.geterrno()
            timeout = self.timeout
            if timeout > 0.0 and res < 0 and errno == _c.EWOULDBLOCK:
                tv = rffi.make(_c.timeval)
                rffi.setintfield(tv, 'c_tv_sec', int(timeout))
                rffi.setintfield(tv, 'c_tv_usec',
                                 int((timeout - int(timeout)) * 1000000))
                fds = lltype.malloc(_c.fd_set.TO, flavor='raw')
                _c.FD_ZERO(fds)
                _c.FD_SET(self.fd, fds)
                fds_exc = lltype.malloc(_c.fd_set.TO, flavor='raw')
                _c.FD_ZERO(fds_exc)
                _c.FD_SET(self.fd, fds_exc)
                null = lltype.nullptr(_c.fd_set.TO)

                try:
                    n = _c.select(self.fd + 1, null, fds, fds_exc, tv)

                    if n > 0:
                        if _c.FD_ISSET(self.fd, fds):
                            # socket writable == connected
                            return (0, False)
                        else:
                            # per MS docs, call getsockopt() to get error
                            assert _c.FD_ISSET(self.fd, fds_exc)
                            return (self.getsockopt_int(
                                _c.SOL_SOCKET, _c.SO_ERROR), False)
                    elif n == 0:
                        return (_c.EWOULDBLOCK, True)
                    else:
                        return (_c.geterrno(), False)

                finally:
                    lltype.free(fds, flavor='raw')
                    lltype.free(fds_exc, flavor='raw')
                    lltype.free(tv, flavor='raw')

            if res == 0:
                errno = 0
            return (errno, False)