From 6214d1ec6796ffab41b9413840e733a1d5cf70dd Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 5 Apr 2008 22:03:06 -0600 Subject: concurrent session limiting --- lib/net/ssh/multi/channel_proxy.rb | 26 +++++++++++ lib/net/ssh/multi/pending_connection.rb | 77 +++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 lib/net/ssh/multi/channel_proxy.rb create mode 100644 lib/net/ssh/multi/pending_connection.rb diff --git a/lib/net/ssh/multi/channel_proxy.rb b/lib/net/ssh/multi/channel_proxy.rb new file mode 100644 index 0000000..99f7986 --- /dev/null +++ b/lib/net/ssh/multi/channel_proxy.rb @@ -0,0 +1,26 @@ +module Net; module SSH; module Multi + class ChannelProxy + attr_reader :on_confirm + + def initialize(&on_confirm) + @on_confirm = on_confirm + @recordings = [] + @channel = nil + end + + def delegate_to(channel) + @channel = channel + @recordings.each do |sym, args, block| + @channel.__send__(sym, *args, &block) + end + end + + def method_missing(sym, *args, &block) + if @channel + @channel.__send__(sym, *args, &block) + else + @recordings << [sym, args, block] + end + end + end +end; end; end \ No newline at end of file diff --git a/lib/net/ssh/multi/pending_connection.rb b/lib/net/ssh/multi/pending_connection.rb new file mode 100644 index 0000000..fcebcba --- /dev/null +++ b/lib/net/ssh/multi/pending_connection.rb @@ -0,0 +1,77 @@ +require 'net/ssh/multi/channel_proxy' + +module Net; module SSH; module Multi + class PendingConnection + class ChannelOpenRecording #:nodoc: + attr_reader :type, :extras, :channel + + def initialize(type, extras, channel) + @type, @extras, @channel = type, extras, channel + end + + def replay_on(session) + real_channel = session.open_channel(type, *extras, &channel.on_confirm) + channel.delegate_to(real_channel) + end + end + + class SendGlobalRequestRecording #:nodoc: + attr_reader :type, :extra, :callback + + def initialize(type, extra, callback) + @type, @extra, @callback = type, extra, callback + end + + def replay_on(session) + session.send_global_request(type, *extra, &callback) + end + end + + attr_reader :server + + def initialize(server) + @server = server + @recordings = [] + end + + def replace_with(session) + @recordings.each { |recording| recording.replay_on(session) } + @server.replace_session(session) + end + + def open_channel(type="session", *extras, &on_confirm) + channel = ChannelProxy.new(&on_confirm) + @recordings << ChannelOpenRecording.new(type, extras, channel) + return channel + end + + def send_global_request(type, *extra, &callback) + @recordings << SendGlobalRequestRecording.new(type, extra, callback) + self + end + + def busy?(include_invisible=false) + true + end + + def close + self + end + + def channels + [] + end + + def preprocess + true + end + + def postprocess(readers, writers) + true + end + + def listeners + {} + end + end +end; end; end \ No newline at end of file -- cgit v1.2.1