Class: RTunnel::Client::TunnelConnection

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
RTunnel, Logging
Defined in:
lib/rtunnel/client.rb

Overview

A connection to the tunnelled port.

Constant Summary

Constants included from RTunnel

DEFAULT_CONTROL_PORT, KEEP_ALIVE_INTERVAL, TUNNEL_TIMEOUT

Instance Method Summary collapse

Methods included from Logging

#D, #E, #F, #I, #W, #init_log

Methods included from RTunnel

resolve_address, run_client, run_server

Constructor Details

#initialize(connection_id, client) ⇒ TunnelConnection

Returns a new instance of TunnelConnection.



271
272
273
274
275
276
277
278
# File 'lib/rtunnel/client.rb', line 271

def initialize(connection_id, client)
  super()

  @connection_id = connection_id
  @backlog = ''
  @client = client
  init_log :to => @client
end

Instance Method Details

#post_initObject



294
295
296
297
298
# File 'lib/rtunnel/client.rb', line 294

def post_init
  D "Tunnel #{@connection_id} established"
  send_data @backlog unless @backlog.empty?
  @backlog = nil
end

#receive_data(data) ⇒ Object



300
301
302
303
# File 'lib/rtunnel/client.rb', line 300

def receive_data(data)
  D "Data: #{data.length} bytes from #{@connection_id}"
  server_connection.send_command SendDataCommand.new(@connection_id, data)
end

#server_connectionObject



280
281
282
# File 'lib/rtunnel/client.rb', line 280

def server_connection
  @client.server_connection
end

#tunnel_data(data) ⇒ Object



284
285
286
287
288
289
290
291
292
# File 'lib/rtunnel/client.rb', line 284

def tunnel_data(data)
  # if the connection hasn't been accepted, store the incoming data until
  # sending can happen
  if @backlog
    @backlog << data
  else
    send_data data
  end
end

#unbindObject



305
306
307
# File 'lib/rtunnel/client.rb', line 305

def unbind
  server_connection.data_connection_closed @connection_id
end