bitprophet/ssh — Issue #2: Do not raise socket.timeout in a non-blocking channel
Author: turicas
Created: 2011-11-17 21:54:50+00:00
State: open

Actually the method `Channel.recv` raises `socket.timeout` if the channel is on non-blocking mode. I think it:

- On non-blocking mode:
- Should return `''` (empty string) if no data received;
- Should raises `IOError` if socket/channel is closed;
- Should return the data received independent on `self.timeout`.
- On blocking-mode:
- Should raises `socket.timeout` if `self.timeout` is set and greater than zero;
- Should raises `IOError` if socket/channel is closed;
- Should return the data if any.

The code:

try:
out = self.in_buffer.read(nbytes, self.timeout)
except PipeTimeout, e:
raise socket.timeout()

on file `ssh/channel.py`, should be changed to something like this:

try:
out = self.in_buffer.read(nbytes, self.timeout)
except PipeTimeout, e:
if self.blocking and self.timeout:
raise socket.timeout('Timeout when reading blocking channel.')