Class: FtpProxy::Relay

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpproxy.rb

Overview

relay is used to proxy for the data channel

Direct Known Subclasses

ActiveRelay

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ Relay

Returns a new instance of Relay.



10
11
12
# File 'lib/ftpproxy.rb', line 10

def initialize left, right
	@left, @right = left, right
end

Instance Method Details

#closeObject



25
26
27
28
# File 'lib/ftpproxy.rb', line 25

def close
	@left.close if @left and !@left.closed?
	@right.close if @right and !@right.closed?
end

#relayObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/ftpproxy.rb', line 14

def relay
	# find out which way to relay
	(src, ), dst, ignore = IO.select [@left, @right], nil, nil, 60000
	raise 'timeout waiting for data' if !src
	dst,  = [@left, @right] - [src]
	while data = src.read(8192)
		dst.write data
	end
	close
end