Class: FFWD::Plugin::Tunnel::BindTCP

Inherits:
Object
  • Object
show all
Defined in:
lib/ffwd/plugin/tunnel/bind_tcp.rb

Defined Under Namespace

Classes: Handle

Instance Method Summary collapse

Constructor Details

#initialize(port, family, tunnel, block) ⇒ BindTCP

Returns a new instance of BindTCP.



55
56
57
58
59
60
61
# File 'lib/ffwd/plugin/tunnel/bind_tcp.rb', line 55

def initialize port, family, tunnel, block
  @port = port
  @family = family
  @tunnel = tunnel
  @block = block
  @handles = {}
end

Instance Method Details

#close(addr) ⇒ Object



69
70
71
72
73
# File 'lib/ffwd/plugin/tunnel/bind_tcp.rb', line 69

def close addr
  raise "Not open: #{addr}" unless handle = @handles[addr]
  handle.recv_close
  @handles.delete addr
end

#data(addr, data) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/ffwd/plugin/tunnel/bind_tcp.rb', line 75

def data addr, data
  return if data.empty?

  unless handle = @handles[addr]
    raise "Not available: #{addr}"
  end

  handle.recv_data data
end

#open(addr) ⇒ Object



63
64
65
66
67
# File 'lib/ffwd/plugin/tunnel/bind_tcp.rb', line 63

def open addr
  raise "Already open: #{addr}" if @handles[addr]
  handle = @handles[addr] = Handle.new self, addr
  @block.call handle
end

#send_data(addr, data) ⇒ Object



85
86
87
# File 'lib/ffwd/plugin/tunnel/bind_tcp.rb', line 85

def send_data addr, data
  @tunnel.send_data Socket::SOCK_STREAM, @family, @port, addr, data
end