Class: TunnelRb::Server::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tunnel_rb/server/client.rb

Overview

Server-side view of a connected tunnel client. Owns the control socket and per-connection state (read buffer, ping bookkeeping, write mutex).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subdomain:, socket:, token:) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
# File 'lib/tunnel_rb/server/client.rb', line 14

def initialize(subdomain:, socket:, token:)
  @subdomain = subdomain
  @socket = socket
  @token = token
  @write_mutex = Mutex.new
  @read_buffer = String.new(encoding: Encoding::ASCII_8BIT)
  @missed_pongs = 0
  @pong_received = true
end

Instance Attribute Details

#missed_pongsObject

Returns the value of attribute missed_pongs.



12
13
14
# File 'lib/tunnel_rb/server/client.rb', line 12

def missed_pongs
  @missed_pongs
end

#pong_receivedObject

Returns the value of attribute pong_received.



12
13
14
# File 'lib/tunnel_rb/server/client.rb', line 12

def pong_received
  @pong_received
end

#read_bufferObject (readonly)

Returns the value of attribute read_buffer.



11
12
13
# File 'lib/tunnel_rb/server/client.rb', line 11

def read_buffer
  @read_buffer
end

#socketObject (readonly)

Returns the value of attribute socket.



11
12
13
# File 'lib/tunnel_rb/server/client.rb', line 11

def socket
  @socket
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



11
12
13
# File 'lib/tunnel_rb/server/client.rb', line 11

def subdomain
  @subdomain
end

#tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/tunnel_rb/server/client.rb', line 11

def token
  @token
end

Instance Method Details

#send_message(payload) ⇒ Object



24
25
26
# File 'lib/tunnel_rb/server/client.rb', line 24

def send_message(payload)
  @write_mutex.synchronize { @socket.puts(payload.to_json) }
end