Class: Bridge::TCPServer

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

Overview

server rather than a local interface. Otherwise attempts to have a mostly identical interface to ::TCPServer.

Instance Method Summary collapse

Constructor Details

#initialize(cloud_host, cloud_port, listen_hosts = ['*'], listen_keys = []) ⇒ TCPServer



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bridge/tcp_server.rb', line 115

def initialize(cloud_host, cloud_port, listen_hosts = ['*'], listen_keys = [])
  @cloud_host = cloud_host
  @cloud_port = cloud_port
  @listen_hosts = listen_hosts
  @listen_keys = listen_keys
  @closed = false
  begin
    TCPSocket.new(@cloud_host, @cloud_port, @listen_hosts, @listen_keys).verify
  rescue Errno::ECONNREFUSED
    raise "HTTP BRIDGE Error: No Bridge server at #{@cloud_host}:#{@cloud_port}"
   end
end

Instance Method Details

#acceptObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/bridge/tcp_server.rb', line 128

def accept()
  begin
    # Connect to the cloudbridge and let it know we're available for a connection.
    # This is all entirely syncronous.
    begin
      socket = TCPSocket.new(@cloud_host, @cloud_port, @listen_hosts, @listen_keys)
    rescue Errno::ECONNREFUSED
      sleep(0.5)
      retry
    end
    socket.setup
    return socket
  rescue RetryError => e
    sleep(e.timeout)
    retry
  end
end

#closeObject



146
147
148
# File 'lib/bridge/tcp_server.rb', line 146

def close()
  @closed = true
end

#closed?Boolean



150
151
152
# File 'lib/bridge/tcp_server.rb', line 150

def closed?()
 return @closed
end