Class: AppProfiler::Server::ProfileServer::TCP

Inherits:
Transport
  • Object
show all
Defined in:
lib/app_profiler/server.rb

Constant Summary collapse

SERVER_ADDRESS =

it is ONLY safe to run this bound to localhost

"127.0.0.1"

Instance Attribute Summary

Attributes inherited from Transport

#socket

Instance Method Summary collapse

Constructor Details

#initialize(port = 0) ⇒ TCP

Returns a new instance of TCP.



242
243
244
245
# File 'lib/app_profiler/server.rb', line 242

def initialize(port = 0)
  @port_argument = port
  super()
end

Instance Method Details

#abandonObject



263
264
265
266
# File 'lib/app_profiler/server.rb', line 263

def abandon
  @port_file.close # NB: Tempfile finalizer checks Process.pid to avoid unlinking inherited IOs.
  @socket.close
end

#clientObject



254
255
256
# File 'lib/app_profiler/server.rb', line 254

def client
  TCPSocket.new(SERVER_ADDRESS, @port)
end

#startObject



247
248
249
250
251
252
# File 'lib/app_profiler/server.rb', line 247

def start
  FileUtils.mkdir_p(PROFILER_TEMPFILE_PATH)
  @socket = TCPServer.new(SERVER_ADDRESS, @port_argument)
  @port = @socket.addr[1]
  @port_file = Tempfile.new("profileserver-#{Process.pid}-port-#{@port}-", PROFILER_TEMPFILE_PATH)
end

#stopObject



258
259
260
261
# File 'lib/app_profiler/server.rb', line 258

def stop
  @port_file.unlink
  @socket.close
end