From 5598a8f88f5854d792428739ca7e67b67993f330 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sat, 28 Aug 2004 04:21:12 +0000 Subject: [PATCH] [project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-67] replay patch 63 (missing channel changes) i'm still getting the hang of tla/arch, obviously. replay patch 63, which was meant to be part of the later mega-patch, but apparently when i reversed it, i lost it entirely. --- paramiko/channel.py | 70 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/paramiko/channel.py b/paramiko/channel.py index b5fbde2..6aaed9e 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -81,6 +81,7 @@ class Channel (object): self.name = str(chanid) self.logger = logging.getLogger('paramiko.chan.' + str(chanid)) self.pipe_rfd = self.pipe_wfd = None + self.event = threading.Event() def __repr__(self): """ @@ -122,14 +123,21 @@ class Channel (object): m.add_byte(chr(MSG_CHANNEL_REQUEST)) m.add_int(self.remote_chanid) m.add_string('pty-req') - m.add_boolean(0) + m.add_boolean(True) m.add_string(term) m.add_int(width) m.add_int(height) # pixel height, width (usually useless) m.add_int(0).add_int(0) m.add_string('') - self.transport._send_message(m) + self.event.clear() + self.transport._send_user_message(m) + while 1: + self.event.wait(0.1) + if self.closed: + return False + if self.event.isSet(): + return True def invoke_shell(self): """ @@ -144,7 +152,14 @@ class Channel (object): m.add_int(self.remote_chanid) m.add_string('shell') m.add_boolean(1) - self.transport._send_message(m) + self.event.clear() + self.transport._send_user_message(m) + while 1: + self.event.wait(0.1) + if self.closed: + return False + if self.event.isSet(): + return True def exec_command(self, command): """ @@ -163,7 +178,14 @@ class Channel (object): m.add_string('exec') m.add_boolean(1) m.add_string(command) - self.transport._send_message(m) + self.event.clear() + self.transport._send_user_message(m) + while 1: + self.event.wait(0.1) + if self.closed: + return False + if self.event.isSet(): + return True def invoke_subsystem(self, subsystem): """ @@ -182,7 +204,14 @@ class Channel (object): m.add_string('subsystem') m.add_boolean(1) m.add_string(subsystem) - self.transport._send_message(m) + self.event.clear() + self.transport._send_user_message(m) + while 1: + self.event.wait(0.1) + if self.closed: + return False + if self.event.isSet(): + return True def resize_pty(self, width=80, height=24): """ @@ -204,7 +233,14 @@ class Channel (object): m.add_int(width) m.add_int(height) m.add_int(0).add_int(0) - self.transport._send_message(m) + self.event.clear() + self.transport._send_user_message(m) + while 1: + self.event.wait(0.1) + if self.closed: + return False + if self.event.isSet(): + return True def get_transport(self): """ @@ -301,11 +337,14 @@ class Channel (object): try: self.lock.acquire() if self.active and not self.closed: - self._send_eof() - m = Message() - m.add_byte(chr(MSG_CHANNEL_CLOSE)) - m.add_int(self.remote_chanid) - self.transport._send_message(m) + try: + self._send_eof() + m = Message() + m.add_byte(chr(MSG_CHANNEL_CLOSE)) + m.add_int(self.remote_chanid) + self.transport._send_user_message(m) + except EOFError: + pass self._set_closed() self.transport._unlink_channel(self.chanid) finally: @@ -425,7 +464,7 @@ class Channel (object): m.add_byte(chr(MSG_CHANNEL_DATA)) m.add_int(self.remote_chanid) m.add_string(s[:size]) - self.transport._send_message(m) + self.transport._send_user_message(m) self.out_window_size -= size if self.ultra_debug: self._log(DEBUG, 'window down to %d' % self.out_window_size) @@ -631,6 +670,7 @@ class Channel (object): def _request_success(self, m): self._log(DEBUG, 'Sesch channel %d request ok' % self.chanid) + self.event.set() return def _request_failed(self, m): @@ -702,7 +742,7 @@ class Channel (object): else: m.add_byte(chr(MSG_CHANNEL_FAILURE)) m.add_int(self.remote_chanid) - self.transport._send_message(m) + self.transport._send_user_message(m) def _handle_eof(self, m): try: @@ -748,7 +788,7 @@ class Channel (object): m = Message() m.add_byte(chr(MSG_CHANNEL_EOF)) m.add_int(self.remote_chanid) - self.transport._send_message(m) + self.transport._send_user_message(m) self.eof_sent = 1 self._log(DEBUG, 'EOF sent') return @@ -855,7 +895,7 @@ class Channel (object): m.add_byte(chr(MSG_CHANNEL_WINDOW_ADJUST)) m.add_int(self.remote_chanid) m.add_int(self.in_window_sofar) - self.transport._send_message(m) + self.transport._send_user_message(m) self.in_window_sofar = 0