Class: Bridge::TCPServer
- Inherits:
-
Object
- Object
- Bridge::TCPServer
- 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
- #accept ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(cloud_host, cloud_port, listen_hosts = ['*'], listen_keys = []) ⇒ TCPServer
constructor
A new instance of TCPServer.
Constructor Details
#initialize(cloud_host, cloud_port, listen_hosts = ['*'], listen_keys = []) ⇒ TCPServer
Returns a new instance of 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
#accept ⇒ Object
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 |
#close ⇒ Object
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 |