diff options
| author | delano <delano@solutious.com> | 2010-03-16 11:18:55 -0400 |
|---|---|---|
| committer | delano <delano@solutious.com> | 2010-03-16 11:18:55 -0400 |
| commit | 4192c2b22fdb748d47845301f63dad74f90656e5 (patch) | |
| tree | f6a4ad6734e2664be428dcaee437a1fc8157a517 /lib | |
| parent | 8a9a93d6d3144bb68077fc0ef00b696b46f72de0 (diff) | |
| download | net-ssh-4192c2b22fdb748d47845301f63dad74f90656e5.tar.gz | |
Moved ForwardedBufferedIo to lib/net/ssh/buffered_io.rb
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/net/ssh/buffered_io.rb | 48 | ||||
| -rw-r--r-- | lib/net/ssh/service/forward.rb | 39 |
2 files changed, 51 insertions, 36 deletions
diff --git a/lib/net/ssh/buffered_io.rb b/lib/net/ssh/buffered_io.rb index e48a8dc..9d6ea07 100644 --- a/lib/net/ssh/buffered_io.rb +++ b/lib/net/ssh/buffered_io.rb @@ -147,4 +147,52 @@ module Net; module SSH end end + + + # Fixes for two issues by Miklós Fazekas: + # + # * if client closes a forwarded connection, but the server is + # reading, net-ssh terminates with IOError socket closed. + # * if client force closes (RST) a forwarded connection, but + # server is reading, net-ssh terminates with [an exception] + # + # See: + # + # http://net-ssh.lighthouseapp.com/projects/36253/tickets/7 + # http://github.com/net-ssh/net-ssh/tree/portfwfix + # + module ForwardedBufferedIo + def fill(n=8192) + begin + super(n) + rescue Errno::ECONNRESET => e + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + rescue IOError => e + if e.message =~ /closed/ then + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + else + raise + end + end + end + + def send_pending + begin + super + rescue Errno::ECONNRESET => e + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + rescue IOError => e + if e.message =~ /closed/ then + debug { "connection was reset => shallowing exception:#{e}" } + return 0 + else + raise + end + end + end + end + end; end diff --git a/lib/net/ssh/service/forward.rb b/lib/net/ssh/service/forward.rb index 67b12ba..024a9cb 100644 --- a/lib/net/ssh/service/forward.rb +++ b/lib/net/ssh/service/forward.rb @@ -193,47 +193,13 @@ module Net; module SSH; module Service end private - - module ForwardedBufferedIo - def fill(n=8192) - begin - super(n) - rescue Errno::ECONNRESET => e - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - rescue IOError => e - if e.message =~ /closed/ then - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - else - raise - end - end - end - - def send_pending - begin - super - rescue Errno::ECONNRESET => e - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - rescue IOError => e - if e.message =~ /closed/ then - debug { "connection was reset => shallowing exception:#{e}" } - return 0 - else - raise - end - end - end - end - + # Perform setup operations that are common to all forwarded channels. # +client+ is a socket, +channel+ is the channel that was just created, # and +type+ is an arbitrary string describing the type of the channel. def prepare_client(client, channel, type) client.extend(Net::SSH::BufferedIo) - client.extend(ForwardedBufferedIo) + client.extend(Net::SSH::ForwardedBufferedIo) client.logger = logger session.listen_to(client) @@ -244,6 +210,7 @@ module Net; module SSH; module Service ch[:socket].enqueue(data) end + # Handles server close on the sending side by Miklós Fazekas channel.on_eof do |ch| debug { "eof #{type} on #{type} forwarded channel" } ch[:socket].send_pending |
