class Net::SSH::Service::Forward

def prepare_client(client, channel, type)

and +type+ is an arbitrary string describing the type of the channel.
+client+ is a socket, +channel+ is the channel that was just created,
Perform setup operations that are common to all forwarded channels.
def prepare_client(client, channel, type)
  client.extend(Net::SSH::BufferedIo)
  client.extend(Net::SSH::ForwardedBufferedIo)
  client.logger = logger
  session.listen_to(client)
  channel[:socket] = client
  channel.on_data do |ch, data|
    debug { "data:#{data.length} on #{type} forwarded channel" }
    ch[:socket].enqueue(data)
  end
  channel.on_eof do |ch|
    debug { "eof #{type} on #{type} forwarded channel" }
    begin
      ch[:socket].send_pending
      ch[:socket].shutdown Socket::SHUT_WR
    rescue IOError => e
      if e.message =~ /closed/ then
        debug { "epipe in on_eof => shallowing exception:#{e}" }
      else
        raise
      end
    rescue Errno::EPIPE => e
      debug { "epipe in on_eof => shallowing exception:#{e}" }
    rescue Errno::ENOTCONN => e
      debug { "enotconn in on_eof => shallowing exception:#{e}" }
    end
  end
  channel.on_close do |ch|
    debug { "closing #{type} forwarded channel" }
    ch[:socket].close if !client.closed?
    session.stop_listening_to(ch[:socket])
  end
  channel.on_process do |ch|
    if ch[:socket].closed?
      ch.info { "#{type} forwarded connection closed" }
      ch.close
    elsif ch[:socket].available > 0
      data = ch[:socket].read_available(8192)
      ch.debug { "read #{data.length} bytes from client, sending over #{type} forwarded connection" }
      ch.send_data(data)
    end
  end
end