Sha256: bc4cf7ce8758620ecf555d01b2591cf8fcd49186ca78bdec79638ffa44e35077
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# coding: utf-8 # frozen_string_literal: true require 'celluloid/current' require 'celluloid/io' module MicroRb module Servers class TCP include Celluloid::IO attr_reader :server, :service_config finalizer :shutdown def initialize(service_config) @service_config = service_config @server = TCPServer.new(service_config.host, service_config.port) end def shutdown @server&.close end def start! service_config.register! loop { async.handle_connection @server.accept } end private def handle_connection(socket) _, port, host = socket.peeraddr MicroRb.logger.debug("*** Received connection from #{host}:#{port}") loop do request = socket.readpartial(4096) response = service_config.request_manager.handle_request(request) socket.write(response) socket.flush end rescue EOFError => e MicroRb.logger.debug("*** #{host}:#{port} disconnected", e) socket.close end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
micro-rb-0.1.0.rc3 | lib/micro/servers/tcp.rb |