Class: Uninterruptible::FileDescriptorServer
- Inherits:
-
Object
- Object
- Uninterruptible::FileDescriptorServer
- Defined in:
- lib/uninterruptible/file_descriptor_server.rb
Instance Attribute Summary collapse
-
#io_object ⇒ Object
readonly
Returns the value of attribute io_object.
-
#socket_server ⇒ Object
readonly
Returns the value of attribute socket_server.
Instance Method Summary collapse
-
#close ⇒ Object
Close the socket server and tidy up any created files.
-
#initialize(io_object) ⇒ FileDescriptorServer
constructor
Creates a new FileDescriptorServer and starts a listenting socket server.
-
#serve_file_descriptor ⇒ Object
Accept the next client connection and send it the file descriptor.
-
#socket_path ⇒ String
Location on disk where socket server is listening.
Constructor Details
#initialize(io_object) ⇒ FileDescriptorServer
Creates a new FileDescriptorServer and starts a listenting socket server
11 12 13 14 15 |
# File 'lib/uninterruptible/file_descriptor_server.rb', line 11 def initialize(io_object) @io_object = io_object start_socket_server end |
Instance Attribute Details
#io_object ⇒ Object (readonly)
Returns the value of attribute io_object.
6 7 8 |
# File 'lib/uninterruptible/file_descriptor_server.rb', line 6 def io_object @io_object end |
#socket_server ⇒ Object (readonly)
Returns the value of attribute socket_server.
6 7 8 |
# File 'lib/uninterruptible/file_descriptor_server.rb', line 6 def socket_server @socket_server end |
Instance Method Details
#close ⇒ Object
Close the socket server and tidy up any created files
34 35 36 37 38 39 |
# 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 ⇒ Object
Accept the next client connection and send it the file descriptor
25 26 27 28 29 30 31 |
# 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 ⇒ String
Returns Location on disk where socket server is listening.
18 19 20 |
# File 'lib/uninterruptible/file_descriptor_server.rb', line 18 def socket_path @socket_path ||= File.join(socket_directory, 'fd.sock') end |