Ejemplo n.º 1
0
    def recvfrom_into (self, *args):
        if not self.uv_fd:
            raise socket.error(errno.EBADFD, 'invalid file descriptor')

        if not self.act_non_blocking:
            wait_read(self.uv_fd, self.gettimeout(), socket.timeout("timed out"))

        return self.uv_fd.recvfrom_into(*args)
Ejemplo n.º 2
0
    def recvfrom_into(self, *args):
        if not self.uv_fd:
            raise socket.error(errno.EBADFD, 'invalid file descriptor')

        if not self.act_non_blocking:
            wait_read(self.uv_fd, self.gettimeout(),
                      socket.timeout("timed out"))

        return self.uv_fd.recvfrom_into(*args)
Ejemplo n.º 3
0
 def recv (self, buflen):
     while True:
         try:
             data = _os_orig.read(self._fileno, buflen)
             return data
         except OSError, e:
             if get_errno(e) != errno.EAGAIN:
                 raise IOError(*e.args)
         wait_read(self)
Ejemplo n.º 4
0
    def recv_into (self, buf, nbytes = None, flags = None):
        if not self.uv_fd:
            raise socket.error(errno.EBADFD, 'invalid file descriptor')

        if not nbytes:
            nbytes = len(buf)

        if not flags:
            flags = 0

        if not self.act_non_blocking:
            wait_read(self.uv_fd, self.gettimeout(), socket.timeout("timed out"))

        return self.uv_fd.recv_into(buf, nbytes = nbytes, flags = flags)
Ejemplo n.º 5
0
    def recv_into(self, buf, nbytes=None, flags=None):
        if not self.uv_fd:
            raise socket.error(errno.EBADFD, 'invalid file descriptor')

        if not nbytes:
            nbytes = len(buf)

        if not flags:
            flags = 0

        if not self.act_non_blocking:
            wait_read(self.uv_fd, self.gettimeout(),
                      socket.timeout("timed out"))

        return self.uv_fd.recv_into(buf, nbytes=nbytes, flags=flags)
Ejemplo n.º 6
0
 def accept (self):
     """
     Accept a new connection when we are listening
     :return: a socket and remote address pair
     """
     if self.act_non_blocking:
         return self.uv_fd.accept()
     else:
         fd = self.uv_fd
         while True:
             res = socket_accept(fd)
             if not res:
                 wait_read(fd, self.gettimeout(), socket.timeout("timed out"))
             else:
                 client, addr = res
                 set_nonblocking(client)
                 return GreenSocket(client, _hub = self.uv_hub), addr
Ejemplo n.º 7
0
 def accept(self):
     """
     Accept a new connection when we are listening
     :return: a socket and remote address pair
     """
     if self.act_non_blocking:
         return self.uv_fd.accept()
     else:
         fd = self.uv_fd
         while True:
             res = socket_accept(fd)
             if not res:
                 wait_read(fd, self.gettimeout(),
                           socket.timeout("timed out"))
             else:
                 client, addr = res
                 set_nonblocking(client)
                 return GreenSocket(client, _hub=self.uv_hub), addr
Ejemplo n.º 8
0
            ## get the data we want from the read buffer, and keep the rest
            res, self.uv_recv_string = self.uv_recv_string[:buflen], self.uv_recv_string[buflen:]
            return res
        else:
            fd = self.uv_fd
            while True:
                try:
                    return fd.recv(buflen, flags)
                except socket.error, e:
                    if get_errno(e) in SOCKET_BLOCKING:
                        pass
                    elif get_errno(e) in SOCKET_CLOSED:
                        return ''
                    else:
                        raise
                wait_read(fd, self.gettimeout(), socket.timeout("timed out"))


    def send (self, data, flags = 0):
        """
        Send data to the socket. The socket must be connected to a remote socket. The optional
        flags argument has the same meaning as for recv() above. Returns the number of bytes sent.
        Applications are responsible for checking that all data has been sent; if only some of the
        data was transmitted, the application needs to attempt delivery of the remaining data.
        :param data: the data to send
        :param flags: modifier flags
        :return: the amount of data written to the socket
        """
        if self.act_non_blocking:
            return self.uv_fd.send(data, flags)
        elif self.uv_handle:
Ejemplo n.º 9
0
                                                           buflen], self.uv_recv_string[
                                                               buflen:]
            return res
        else:
            fd = self.uv_fd
            while True:
                try:
                    return fd.recv(buflen, flags)
                except socket.error, e:
                    if get_errno(e) in SOCKET_BLOCKING:
                        pass
                    elif get_errno(e) in SOCKET_CLOSED:
                        return ''
                    else:
                        raise
                wait_read(fd, self.gettimeout(), socket.timeout("timed out"))

    def send(self, data, flags=0):
        """
        Send data to the socket. The socket must be connected to a remote socket. The optional
        flags argument has the same meaning as for recv() above. Returns the number of bytes sent.
        Applications are responsible for checking that all data has been sent; if only some of the
        data was transmitted, the application needs to attempt delivery of the remaining data.
        :param data: the data to send
        :param flags: modifier flags
        :return: the amount of data written to the socket
        """
        if self.act_non_blocking:
            return self.uv_fd.send(data, flags)
        elif self.uv_handle:
            did_write = Event()