fix thread rssh param, indentation, rescue close errors

git-svn-id: file:///home/svn/framework3/trunk@10581 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Joshua Drake 2010-10-07 00:12:12 +00:00
parent 352b4cf1c8
commit eb6da40f69
1 changed files with 41 additions and 39 deletions

View File

@ -25,58 +25,60 @@ class CommandStream
self.thread = Thread.new(ssh,cmd,cleanup) do |rssh,rcmd,rcleanup| self.thread = Thread.new(ssh,cmd,cleanup) do |rssh,rcmd,rcleanup|
begin begin
info = rssh.transport.socket.getpeername
self.lsock.peerinfo = "#{info[1]}:#{info[2]}"
info = ssh.transport.socket.getpeername info = rssh.transport.socket.getsockname
self.lsock.peerinfo = "#{info[1]}:#{info[2]}" self.lsock.localinfo = "#{info[1]}:#{info[2]}"
info = ssh.transport.socket.getsockname rssh.open_channel do |rch|
self.lsock.localinfo = "#{info[1]}:#{info[2]}" rch.exec(rcmd) do |c, success|
raise "could not execute command: #{rcmd.inspect}" unless success
rssh.open_channel do |rch| c[:data] = ''
rch.exec(rcmd) do |c, success|
raise "could not execute command: #{rcmd.inspect}" unless success
c[:data] = '' c.on_eof do
self.rsock.close rescue nil
self.ssh.close rescue nil
self.thread.kill
end
c.on_eof do c.on_close do
self.rsock.close self.rsock.close rescue nil
self.thread.kill self.ssh.close rescue nil
self.thread.kill
end
c.on_data do |ch,data|
self.rsock.write(data)
end
c.on_extended_data do |ch, ctype, data|
self.rsock.write(data)
end
self.channel = c
end end
c.on_close do
self.rsock.close
self.thread.kill
end
c.on_data do |ch,data|
self.rsock.write(data)
end
c.on_extended_data do |ch, ctype, data|
self.rsock.write(data)
end
self.channel = c
end end
end
self.monitor = Thread.new do self.monitor = Thread.new do
while(true) while(true)
next if not self.rsock.has_read_data?(1.0) next if not self.rsock.has_read_data?(1.0)
buff = self.rsock.sysread(16384) buff = self.rsock.sysread(16384)
break if not buff break if not buff
verify_channel verify_channel
self.channel.send_data(buff) if buff self.channel.send_data(buff) if buff
end
end end
end
while true while true
rssh.process(0.5) { true } rssh.process(0.5) { true }
end end
rescue ::Exception => e rescue ::Exception => e
self.error = e self.error = e
#::Kernel.warn "BOO: #{e.inspect}"
#::Kernel.warn e.backtrace.join("\n")
ensure ensure
self.monitor.kill if self.monitor self.monitor.kill if self.monitor
end end