Example #1
0
    def connect(self, address):
        """
        Connects to a remote address
        :param address: the remote address, as a IP and port tuple
        """
        if self.act_non_blocking:
            return self.uv_fd.connect(address)
        elif self.uv_handle:
            try:
                did_connect = Event()

                def connect_callback(tcp_handle, error):
                    try:
                        if error:
                            did_connect.send_exception(
                                last_socket_error(error, msg='connect error'))
                        else:
                            did_connect.send(0)
                    except Exception, e:
                        did_connect.send_exception(e)

                self.uv_handle.connect(resolve_address(address),
                                       connect_callback)
                did_connect.wait(self.gettimeout(),
                                 socket.timeout(errno.ETIME, "timed out"))
            except pyuv.error.TCPError, e:
                raise socket.error(
                    *last_socket_error(e.args[0], msg='connect error'))
Example #2
0
    def connect (self, address):
        """
        Connects to a remote address
        :param address: the remote address, as a IP and port tuple
        """
        if self.act_non_blocking:
            return self.uv_fd.connect(address)
        elif self.uv_handle:
            try:
                did_connect = Event()

                def connect_callback (tcp_handle, error):
                    try:
                        if error:
                            did_connect.send_exception(
                                last_socket_error(error, msg = 'connect error'))
                        else:
                            did_connect.send(0)
                    except Exception, e:
                        did_connect.send_exception(e)

                self.uv_handle.connect(resolve_address(address), connect_callback)
                did_connect.wait(self.gettimeout(), socket.timeout(errno.ETIME, "timed out"))
            except pyuv.error.TCPError, e:
                raise socket.error(*last_socket_error(e.args[0], msg = 'connect error'))
Example #3
0
 def write_callback (handle, error):
     try:
         if error:
             did_write.send_exception(last_socket_error(error, msg = 'write error'))
         else:
             did_write.send(write_len)
     except Exception, e:
         did_write.send_exception(e)
Example #4
0
 def connect_callback (tcp_handle, error):
     try:
         if error:
             did_connect.send_exception(
                 last_socket_error(error, msg = 'connect error'))
         else:
             did_connect.send(0)
     except Exception, e:
         did_connect.send_exception(e)
Example #5
0
 def write_callback(handle, error):
     try:
         if error:
             did_write.send_exception(
                 last_socket_error(error, msg='write error'))
         else:
             did_write.send(write_len)
     except Exception, e:
         did_write.send_exception(e)
Example #6
0
 def connect_callback(tcp_handle, error):
     try:
         if error:
             did_connect.send_exception(
                 last_socket_error(error, msg='connect error'))
         else:
             did_connect.send(0)
     except Exception, e:
         did_connect.send_exception(e)
Example #7
0
 def bind (self, address):
     """
     Binds to a particular address and port
     :param address: the address, as a pair of IP and port
     """
     if not self.uv_handle:
         return self.uv_fd.bind(address)
     else:
         try:
             self.uv_handle.bind(resolve_address(address))
         except ValueError, e:
             raise OverflowError(e)
         except pyuv.error.TCPError, e:
             raise socket.error(*last_socket_error(e.args[0], msg = 'bind error'))
Example #8
0
 def bind(self, address):
     """
     Binds to a particular address and port
     :param address: the address, as a pair of IP and port
     """
     if not self.uv_handle:
         return self.uv_fd.bind(address)
     else:
         try:
             self.uv_handle.bind(resolve_address(address))
         except ValueError, e:
             raise OverflowError(e)
         except pyuv.error.TCPError, e:
             raise socket.error(
                 *last_socket_error(e.args[0], msg='bind error'))
Example #9
0
                def read_callback (handle, data, error):
                    try:
                        self.uv_handle.stop_read()
                        if error:
                            if pyuv.errno.errorcode[error] == 'UV_EOF':
                                did_read.send(GreenSocket.EOF)
                            else:
                                did_read.send_exception(
                                    last_socket_error(error, msg = 'read error'))
                        elif data is None or len(data) == 0:
                            did_read.send(GreenSocket.EOF)
                        else:
                            ## append the data to the buffer and, maybe, stop reading...
                            self.uv_recv_string += data
                            did_read.send()

                    except Exception, e:
                        did_read.send_exception(e)
Example #10
0
                def read_callback(handle, data, error):
                    try:
                        self.uv_handle.stop_read()
                        if error:
                            if pyuv.errno.errorcode[error] == 'UV_EOF':
                                did_read.send(GreenSocket.EOF)
                            else:
                                did_read.send_exception(
                                    last_socket_error(error, msg='read error'))
                        elif data is None or len(data) == 0:
                            did_read.send(GreenSocket.EOF)
                        else:
                            ## append the data to the buffer and, maybe, stop reading...
                            self.uv_recv_string += data
                            did_read.send()

                    except Exception, e:
                        did_read.send_exception(e)
Example #11
0
 def connect_ex (self, address):
     """
     Connects to a remote address not raising exceptions
     :param address: the remote address, as a IP and port tuple
     :return: 0 if successful, or an error code otherwise
     """
     if self.act_non_blocking:
         return self.uv_fd.connect_ex(address)
     elif self.uv_handle:
         try:
             self.connect(address)
             return 0
         except (socket.timeout, Timeout):
             return errno.ETIME
         except pyuv.error.TCPError, e:
             raise socket.error(*last_socket_error(e.args[0], msg = 'connect error'))
         except Exception, e:
             code = e.args[0]
             return code
Example #12
0
 def connect_ex(self, address):
     """
     Connects to a remote address not raising exceptions
     :param address: the remote address, as a IP and port tuple
     :return: 0 if successful, or an error code otherwise
     """
     if self.act_non_blocking:
         return self.uv_fd.connect_ex(address)
     elif self.uv_handle:
         try:
             self.connect(address)
             return 0
         except (socket.timeout, Timeout):
             return errno.ETIME
         except pyuv.error.TCPError, e:
             raise socket.error(
                 *last_socket_error(e.args[0], msg='connect error'))
         except Exception, e:
             code = e.args[0]
             return code
Example #13
0
 def getpeername (self):
     if self.uv_handle:
         try:
             return self.uv_handle.getpeername()
         except pyuv.error.TCPError, e:
             raise socket.error(*last_socket_error(e.args[0]))
Example #14
0
 def getpeername(self):
     if self.uv_handle:
         try:
             return self.uv_handle.getpeername()
         except pyuv.error.TCPError, e:
             raise socket.error(*last_socket_error(e.args[0]))