Class: RTunnel::ControlServer
- Inherits:
-
GServer
- Object
- GServer
- RTunnel::ControlServer
- Defined in:
- lib/server.rb
Constant Summary collapse
- @@control_connections =
[]
- @@remote_listen_servers =
[]
- @@m =
Mutex.new
Instance Attribute Summary collapse
-
#ping_interval ⇒ Object
Returns the value of attribute ping_interval.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ ControlServer
constructor
A new instance of ControlServer.
- #serve(sock) ⇒ Object
- #starting ⇒ Object
- #stopping ⇒ Object
Constructor Details
#initialize(*args) ⇒ ControlServer
Returns a new instance of ControlServer.
67 68 69 70 |
# File 'lib/server.rb', line 67 def initialize(*args) super @maxConnections = 1024 end |
Instance Attribute Details
#ping_interval ⇒ Object
Returns the value of attribute ping_interval.
65 66 67 |
# File 'lib/server.rb', line 65 def ping_interval @ping_interval end |
Class Method Details
.close_tunnel(conn_id) ⇒ Object
83 84 85 86 87 |
# File 'lib/server.rb', line 83 def close_tunnel(conn_id) D "sending close connection command" @@m.synchronize { control_connection_for(conn_id).write CloseConnectionCommand.new(conn_id) } end |
.new_tunnel(conn_id) ⇒ Object
73 74 75 76 77 |
# File 'lib/server.rb', line 73 def new_tunnel(conn_id) D "sending create connection command: #{conn_id}" @@m.synchronize { control_connection_for(conn_id).write CreateConnectionCommand.new(conn_id) } end |
.send_data(conn_id, data) ⇒ Object
79 80 81 |
# File 'lib/server.rb', line 79 def send_data(conn_id, data) @@m.synchronize { control_connection_for(conn_id).write SendDataCommand.new(conn_id, data) } end |
Instance Method Details
#serve(sock) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/server.rb', line 100 def serve(sock) D "new control connection" @@control_connections << sock sock.sync = true cmd_queue = "" sock.while_reading(cmd_queue = '') do while Command.match(cmd_queue) case cmd = Command.parse(cmd_queue) when RemoteListenCommand @@m.synchronize do addr, port = cmd.address.split(/:/) if rls = @@remote_listen_servers.detect {|s| s.port == port.to_i } rls.stop @@remote_listen_servers.delete rls end (new_rls = RemoteListenServer.new(port, addr, sock)).start @@remote_listen_servers << new_rls end D "listening for remote connections on #{cmd.address}" when SendDataCommand conn = RemoteListenServer::CONNECTIONS[cmd.conn_id] begin conn.write(cmd.data) if conn rescue Errno::EPIPE D "broken pipe on #{cmd.conn_id}" end when CloseConnectionCommand if connection = RemoteListenServer::CONNECTIONS[cmd.conn_id] D "closing remote connection: #{cmd.conn_id}" connection.close end else D "bad command received: #{cmd.inspect}" end end end rescue Errno::ECONNRESET D "client disconnected (conn reset)" rescue D $!.inspect D $@*"\n" raise ensure @@control_connections.delete sock end |
#starting ⇒ Object
96 97 98 |
# File 'lib/server.rb', line 96 def starting start_pinging end |
#stopping ⇒ Object
147 148 149 150 |
# File 'lib/server.rb', line 147 def stopping @ping_thread.kill @@remote_listen_server.stop end |