Class: KStor::SocketServer
- Inherits:
-
Object
- Object
- KStor::SocketServer
- Defined in:
- lib/kstor/socket_server.rb
Overview
Serve clients on UNIX sockets.
Direct Known Subclasses
Constant Summary collapse
- GRACEFUL_TIMEOUT =
Wait this number of seconds for worker threads to terminate before killing them without mercy.
10
Instance Method Summary collapse
-
#initialize(socket_path:, nworkers:) ⇒ SocketServer
constructor
Create a new server.
-
#start ⇒ Object
Start serving clients.
-
#work(client) ⇒ Object
abstract
Do some work for a client and write a response.
Constructor Details
#initialize(socket_path:, nworkers:) ⇒ SocketServer
Create a new server.
20 21 22 23 24 25 |
# File 'lib/kstor/socket_server.rb', line 20 def initialize(socket_path:, nworkers:) @path = socket_path @nworkers = nworkers @client_queue = Queue.new @workers = [] end |
Instance Method Details
#start ⇒ Object
Start serving clients.
Send interrupt signal to cleanly stop.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kstor/socket_server.rb', line 30 def start start_workers server = server_socket Systemd.service_ready Log.info('socket_server: started') loop do maintain_workers @client_queue.enq(server.accept.first) end rescue Interrupt stop(server) Log.info('socket_server: stopped.') end |
#work(client) ⇒ Object
This method is abstract.
Do some work for a client and write a response.
46 47 48 49 |
# File 'lib/kstor/socket_server.rb', line 46 def work(client) # Abstract method. client.close end |