Logo Search packages:      
Sourcecode: paramiko version File versions  Download package

def paramiko::channel::Channel::recv (   self,
  nbytes 
)

Receive data from the channel.  The return value is a string
representing the data received.  The maximum amount of data to be
received at once is specified by C{nbytes}.  If a string of length zero
is returned, the channel stream has closed.

@param nbytes: maximum number of bytes to read.
@type nbytes: int
@return: data.
@rtype: str

@raise socket.timeout: if no data is ready before the timeout set by
    L{settimeout}.

Definition at line 502 of file channel.py.

00502                           :
        """
        Receive data from the channel.  The return value is a string
        representing the data received.  The maximum amount of data to be
        received at once is specified by C{nbytes}.  If a string of length zero
        is returned, the channel stream has closed.

        @param nbytes: maximum number of bytes to read.
        @type nbytes: int
        @return: data.
        @rtype: str
        
        @raise socket.timeout: if no data is ready before the timeout set by
            L{settimeout}.
        """
        out = ''
        self.lock.acquire()
        try:
            if len(self.in_buffer) == 0:
                if self.closed or self.eof_received:
                    return out
                # should we block?
                if self.timeout == 0.0:
                    raise socket.timeout()
                # loop here in case we get woken up but a different thread has grabbed everything in the buffer
                timeout = self.timeout
                while (len(self.in_buffer) == 0) and not self.closed and not self.eof_received:
                    then = time.time()
                    self.in_buffer_cv.wait(timeout)
                    if timeout != None:
                        timeout -= time.time() - then
                        if timeout <= 0.0:
                            raise socket.timeout()
            # something in the buffer and we have the lock
            if len(self.in_buffer) <= nbytes:
                out = self.in_buffer
                self.in_buffer = ''
                if self.pipe is not None:
                    # clear the pipe, since no more data is buffered
                    self.pipe.clear()
            else:
                out = self.in_buffer[:nbytes]
                self.in_buffer = self.in_buffer[nbytes:]
            ack = self._check_add_window(len(out))
        finally:
            self.lock.release()

        # no need to hold the channel lock when sending this
        if ack > 0:
            m = Message()
            m.add_byte(chr(MSG_CHANNEL_WINDOW_ADJUST))
            m.add_int(self.remote_chanid)
            m.add_int(ack)
            self.transport._send_user_message(m)

        return out

    def recv_stderr_ready(self):


Generated by  Doxygen 1.6.0   Back to index