Class: KStor::Server

Inherits:
SocketServer show all
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

Methods inherited from SocketServer

#start

Constructor Details

#initialize(controller:, **args) ⇒ Server

Returns a new instance of Server.



18
19
20
21
# File 'lib/kstor/server.rb', line 18

def initialize(controller:, **args)
  @controller = controller
  super(**args)
end

Instance Method Details

#work(client) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kstor/server.rb', line 23

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