Merge pull request #99 from tomerfiliba/patch-1

Make send() and recv() fail when channel is closed
This commit is contained in:
Jeff Forcier 2012-11-29 14:35:19 -08:00
commit 962d4a3cec
1 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import sys
import time
import threading
import socket
import errno
import os
from paramiko.common import *
@ -605,6 +606,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 +660,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 +717,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 +758,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 +800,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