Class: TunnelRb::Server::PublicServer
- Inherits:
-
Object
- Object
- TunnelRb::Server::PublicServer
- Defined in:
- lib/tunnel_rb/server/public_server.rb
Overview
Public-facing HTTP edge: accepts browser connections, parses headers, asks the tunneled client to open a fresh data connection via PendingConnections, and proxies bytes both ways.
Constant Summary collapse
- POOL_SIZE =
200- QUEUE_SIZE =
200- READ_TIMEOUT_SEC =
5- BIND_WAIT_SEC =
10
Instance Method Summary collapse
-
#initialize(port:, registry:, pending_connections:, logger:) ⇒ PublicServer
constructor
A new instance of PublicServer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port:, registry:, pending_connections:, logger:) ⇒ PublicServer
Returns a new instance of PublicServer.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tunnel_rb/server/public_server.rb', line 22 def initialize(port:, registry:, pending_connections:, logger:) @port = port @registry = registry @pending_connections = pending_connections @logger = logger @pool = ThreadPool.new(POOL_SIZE, max_queue: QUEUE_SIZE) @stopping = false @server = nil end |
Instance Method Details
#start ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tunnel_rb/server/public_server.rb', line 33 def start @server = TCPServer.new("0.0.0.0", @port) @logger.info "🌍 Public server listening on #{@port}" loop do browser_socket = @server.accept @pool.submit { handle_request(browser_socket) } rescue IOError, Errno::EBADF break if @stopping raise end end |
#stop ⇒ Object
47 48 49 50 51 |
# File 'lib/tunnel_rb/server/public_server.rb', line 47 def stop @stopping = true @server&.close rescue nil @pool.shutdown end |