diff options
author | Olle Lundberg <geek@nerd.sh> | 2014-08-15 20:58:13 +0200 |
---|---|---|
committer | Olle Lundberg <geek@nerd.sh> | 2014-08-15 21:22:05 +0200 |
commit | 3ee78214809f76181907808f9f27ed33a110be44 (patch) | |
tree | f3704b6e837350b6ffa8328bbb4b2539f46f42c4 | |
parent | 12343df81cc07018a382bbe1ead102ca26c1d9d2 (diff) |
Add new _send method to reduce code duplication.
This method is the lowest _send related method on Channel and is
the place where we raise a socket is closed Excpetion.
-rw-r--r-- | paramiko/channel.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/paramiko/channel.py b/paramiko/channel.py index 145fac14..f5f86d7a 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -1070,6 +1070,25 @@ class Channel (object): ### internals... + def _send(self, s, m): + size = len(s) + self.lock.acquire() + try: + if self.closed: + # this doesn't seem useful, but it is the documented behavior of Socket + raise socket.error('Socket is closed') + size = self._wait_for_send_window(size) + if size == 0: + # eof or similar + return 0 + m.add_string(s[:size]) + finally: + self.lock.release() + # Note: We release self.lock before calling _send_user_message. + # Otherwise, we can deadlock during re-keying. + self.transport._send_user_message(m) + return size + def _log(self, level, msg, *args): self.logger.log(level, "[chan " + self._name + "] " + msg, *args) |