em-ssh 0.3.0.pre0 → 0.3.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/em-ssh/shell.rb +37 -16
- data/lib/em-ssh/version.rb +1 -1
- metadata +2 -3
data/lib/em-ssh/shell.rb
CHANGED
@@ -73,6 +73,7 @@ module EventMachine
|
|
73
73
|
@parent = opts[:parent]
|
74
74
|
@children = []
|
75
75
|
@reconnect = opts[:reconnect]
|
76
|
+
@buffer = ''
|
76
77
|
|
77
78
|
if block_given?
|
78
79
|
Fiber.new { open(&blk).tap{|r| raise r if r.is_a?(Exception) } }.resume
|
@@ -137,28 +138,42 @@ module EventMachine
|
|
137
138
|
reconnect? ? open : raise(Disconnected) unless connected?
|
138
139
|
raise ClosedChannel if closed?
|
139
140
|
debug("wait_for(#{strregex.inspect}, #{opts})")
|
140
|
-
opts
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
141
|
+
opts = { :timeout => @timeout }.merge(opts)
|
142
|
+
found = nil
|
143
|
+
f = Fiber.current
|
144
|
+
trace = caller
|
145
|
+
timer = nil
|
146
|
+
data_callback = nil
|
147
|
+
matched = false
|
148
|
+
started = Time.new
|
146
149
|
|
147
150
|
timeout = proc do
|
148
|
-
|
149
|
-
f.resume(TimeoutError.new("#{host}: timeout while waiting for #{strregex.inspect}; received: #{buffer.inspect}"))
|
151
|
+
data_callback && data_callback.cancel
|
152
|
+
f.resume(TimeoutError.new("#{host}: inactivity timeout (#{opts[:timeout]}) while waiting for #{strregex.inspect}; received: #{@buffer.inspect}; waited total: #{Time.new - started}"))
|
150
153
|
end
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
if
|
154
|
+
|
155
|
+
data_callback = on(:data) do
|
156
|
+
timer && timer.cancel
|
157
|
+
if matched
|
158
|
+
debug("data_callback invoked when already matched")
|
159
|
+
next
|
160
|
+
end
|
161
|
+
matched = @buffer.match(strregex)
|
162
|
+
if matched
|
155
163
|
debug("data matched")
|
156
|
-
|
157
|
-
|
158
|
-
f.resume(
|
164
|
+
data_callback.cancel
|
165
|
+
@buffer=matched.post_match
|
166
|
+
f.resume(matched.pre_match + matched.to_s)
|
167
|
+
else
|
168
|
+
timer = EM::Timer.new(opts[:timeout], &timeout)
|
159
169
|
end
|
160
170
|
end
|
161
171
|
|
172
|
+
# Check against current buffer
|
173
|
+
EM::next_tick {
|
174
|
+
data_callback.call() if @buffer.length>0
|
175
|
+
}
|
176
|
+
|
162
177
|
timer = EM::Timer.new(opts[:timeout], &timeout)
|
163
178
|
debug("set timer: #{timer} for #{opts[:timeout]}")
|
164
179
|
res = Fiber.yield
|
@@ -201,7 +216,13 @@ module EventMachine
|
|
201
216
|
conerr && conerr.cancel
|
202
217
|
debug "***** shell open: #{shell}"
|
203
218
|
@closed = false
|
204
|
-
@shell
|
219
|
+
@shell = shell
|
220
|
+
@shell.on_data do |ch,data|
|
221
|
+
debug("data: #{@buffer.dump}")
|
222
|
+
@buffer += data
|
223
|
+
fire(:data)
|
224
|
+
end
|
225
|
+
|
205
226
|
Fiber.new { yield(self) if block_given? }.resume
|
206
227
|
f.resume(self)
|
207
228
|
end # |shell,success|
|
data/lib/em-ssh/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.
|
4
|
+
version: 0.3.0.pre1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -123,4 +123,3 @@ signing_key:
|
|
123
123
|
specification_version: 3
|
124
124
|
summary: An EventMachine compatible net-ssh
|
125
125
|
test_files: []
|
126
|
-
has_rdoc:
|