class Uninterruptible::FileDescriptorServer
Attributes
io_object[R]
socket_server[R]
Public Class Methods
new(io_object)
click to toggle source
Creates a new FileDescriptorServer
and starts a listenting socket server
@param [IO] Any IO object that will be shared by this server
# File lib/uninterruptible/file_descriptor_server.rb, line 11 def initialize(io_object) @io_object = io_object start_socket_server end
Public Instance Methods
close()
click to toggle source
Close the socket server and tidy up any created files
# File lib/uninterruptible/file_descriptor_server.rb, line 34 def close socket_server.close File.delete(socket_path) Dir.rmdir(socket_directory) end
serve_file_descriptor()
click to toggle source
Accept the next client connection and send it the file descriptor
@raise [RuntimeError] Raises a runtime error if the socket server is closed
# File lib/uninterruptible/file_descriptor_server.rb, line 25 def serve_file_descriptor raise "File descriptor server has been closed" if socket_server.closed? client = socket_server.accept client.send_io(io_object.to_io) client.close end
socket_path()
click to toggle source
@return [String] Location on disk where socket server is listening
# File lib/uninterruptible/file_descriptor_server.rb, line 18 def socket_path @socket_path ||= File.join(socket_directory, 'fd.sock') end
Private Instance Methods
socket_directory()
click to toggle source
# File lib/uninterruptible/file_descriptor_server.rb, line 43 def socket_directory @socket_directory ||= Dir.mktmpdir('u-') end
start_socket_server()
click to toggle source
# File lib/uninterruptible/file_descriptor_server.rb, line 47 def start_socket_server @socket_server = UNIXServer.new(socket_path) end