summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2008-04-05 22:03:06 -0600
committerJamis Buck <jamis@37signals.com>2008-04-05 22:03:06 -0600
commit6214d1ec6796ffab41b9413840e733a1d5cf70dd (patch)
tree45e4404653ff3ee69b72a060ab6e22c2db926f4f
parentef95839f420e93f85e179a43bb4e28cb39de0de7 (diff)
downloadnet-ssh-multi-6214d1ec6796ffab41b9413840e733a1d5cf70dd.tar.gz
concurrent session limiting
-rw-r--r--lib/net/ssh/multi/channel_proxy.rb26
-rw-r--r--lib/net/ssh/multi/pending_connection.rb77
2 files changed, 103 insertions, 0 deletions
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