summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTomer Filiba <tomerfiliba@gmail.com>2012-10-26 15:44:34 +0300
committerJeff Forcier <jeff@bitprophet.org>2012-11-29 14:38:23 -0800
commitbc3674d0f0c61b5c7af9cfbc9248cf574d0998b0 (patch)
treeb9d65a69bbb0feee3b9b6378571c0fd46ec01b6e
parent2832f3c60fdf078066a266cd32027a0b8ed65ce9 (diff)
Make send() and recv() fail when channel is closed
``sendall()`` was checking if the channel has been closed, and failed accordingly, but ``send()`` and ``recv()`` did not. This meant that ``chan.send("foo")`` when the channel was already closed, just blocked forever.
-rw-r--r--paramiko/channel.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/paramiko/channel.py b/paramiko/channel.py
index 534f8d7c..35991deb 100644
--- a/paramiko/channel.py
+++ b/paramiko/channel.py
@@ -605,6 +605,10 @@ class Channel (object):
@raise socket.timeout: if no data is ready before the timeout set by
L{settimeout}.
"""
+ if self.closed:
+ # this doesn't seem useful, but it is the documented behavior of Socket
+ raise socket.error(errno.EBADF, 'Socket is closed')
+
try:
out = self.in_buffer.read(nbytes, self.timeout)
except PipeTimeout, e:
@@ -655,6 +659,10 @@ class Channel (object):
@since: 1.1
"""
+ if self.closed:
+ # this doesn't seem useful, but it is the documented behavior of Socket
+ raise socket.error(errno.EBADF, 'Socket is closed')
+
try:
out = self.in_stderr_buffer.read(nbytes, self.timeout)
except PipeTimeout, e:
@@ -708,6 +716,10 @@ class Channel (object):
@raise socket.timeout: if no data could be sent before the timeout set
by L{settimeout}.
"""
+ if self.closed:
+ # this doesn't seem useful, but it is the documented behavior of Socket
+ raise socket.error(errno.EBADF, 'Socket is closed')
+
size = len(s)
self.lock.acquire()
try:
@@ -745,6 +757,10 @@ class Channel (object):
@since: 1.1
"""
+ if self.closed:
+ # this doesn't seem useful, but it is the documented behavior of Socket
+ raise socket.error(errno.EBADF, 'Socket is closed')
+
size = len(s)
self.lock.acquire()
try:
@@ -783,9 +799,6 @@ class Channel (object):
This is irritating, but identically follows python's API.
"""
while s:
- if self.closed:
- # this doesn't seem useful, but it is the documented behavior of Socket
- raise socket.error('Socket is closed')
sent = self.send(s)
s = s[sent:]
return None