Class: KStor::Server
- Inherits:
-
SocketServer
- Object
- SocketServer
- KStor::Server
- Defined in:
- lib/kstor/server.rb
Overview
Listen for clients and respond to their requests.
Constant Summary
Constants inherited from SocketServer
KStor::SocketServer::GRACEFUL_TIMEOUT
Instance Method Summary collapse
-
#initialize(controller:, **args) ⇒ KStor::Server
constructor
Create a new server object.
-
#work(client) ⇒ Object
Implement KStor::SocketServer#work to actually serve clients.
Methods inherited from SocketServer
Constructor Details
#initialize(controller:, **args) ⇒ KStor::Server
Create a new server object.
25 26 27 28 |
# File 'lib/kstor/server.rb', line 25 def initialize(controller:, **args) @controller = controller super(**args) end |
Instance Method Details
#work(client) ⇒ Object
Implement KStor::SocketServer#work to actually serve clients.
This method must read client request, write a response and close the socket.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kstor/server.rb', line 36 def work(client) client_data, = client.recvfrom(4096) Log.debug("server: read #{client_data.bytesize} bytes from client") server_data = handle_client_data(client_data) Log.debug("server: sending #{server_data.bytesize} bytes of response " \ 'to client') client.send(server_data, 0) rescue Errno::EPIPE Log.info('server: client unexpectedly broke connection') ensure client.close end |