Class: AppProfiler::Server::ProfileServer::UNIX

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

Instance Attribute Summary

Attributes inherited from Transport

#socket

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Transport

#initialize

Constructor Details

This class inherits a constructor from AppProfiler::Server::ProfileServer::Transport

Class Method Details



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/app_profiler/server.rb', line 202

def unlink_socket(path, pid)
  ->(_) do
    if Process.pid == pid && File.exist?(path)
      begin
        File.unlink(path)
      rescue SystemCallError
        # Let not raise in a finalizer
      end
    end
  end
end

Instance Method Details

#abandonObject



234
235
236
# File 'lib/app_profiler/server.rb', line 234

def abandon
  @socket.close
end

#clientObject



223
224
225
# File 'lib/app_profiler/server.rb', line 223

def client
  UNIXSocket.new(@socket_file)
end

#startObject



215
216
217
218
219
220
221
# File 'lib/app_profiler/server.rb', line 215

def start
  FileUtils.mkdir_p(PROFILER_TEMPFILE_PATH)
  @socket_file = File.join(PROFILER_TEMPFILE_PATH, "app-profiler-#{Process.pid}.sock")
  File.unlink(@socket_file) if File.exist?(@socket_file) && File.socket?(@socket_file)
  @socket = UNIXServer.new(@socket_file)
  ObjectSpace.define_finalizer(self, self.class.unlink_socket(@socket_file, Process.pid))
end

#stopObject



227
228
229
230
231
232
# File 'lib/app_profiler/server.rb', line 227

def stop
  @socket.close
  File.unlink(@socket_file) if File.exist?(@socket_file) && File.socket?(@socket_file)
  ObjectSpace.undefine_finalizer(self)
  nil
end