def local( *args )
if args.length < 3 || args.length > 4
raise ArgumentError,
"expected 3 or 4 parameters, got #{args.length+1}"
end
bind_address = "127.0.0.1"
bind_address = args.shift if args.first.is_a? String
local_port = args.shift.to_i
remote_host = args.shift
remote_port = args.shift
key = [ local_port.to_i, bind_address ]
if @log.debug?
@log.debug "starting local forwarding server on " +
key.inspect
end
socket = TCPServer.new( bind_address, local_port )
Thread.new do
begin
@local_forwards[ key ] = { :thread => Thread.current,
:socket => socket }
if @log.debug?
@log.debug "listening for connections on #{key.inspect}"
end
while ( client = socket.accept )
@log.debug "#{key.inspect} received connection" if @log.debug?
direct_channel( local_port,
remote_host,
remote_port,
@handlers[:local].call( client ) )
end
rescue Exception => e
@log.error "error forwarding local connection: " +
"#{e.class} (#{e.message})\n " +
e.backtrace.join( "\n " )
end
end
end