Sha256: b0139f12e954d0967e3deb83ecd4b0d81202a9895a690de6cd1354c4dd49620d
Contents?: true
Size: 819 Bytes
Versions: 14
Compression:
Stored size: 819 Bytes
Contents
require 'bundler/setup' require 'celluloid/io' class EchoUNIXServer include Celluloid::IO finalizer :finalize attr_reader :socket_path, :server def initialize(socket_path) puts "*** start server #{socket_path}" @socket_path = socket_path @server = UNIXServer.open(socket_path) async.run end def run loop { async.handle_connection @server.accept } end def handle_connection(socket) loop do data = socket.readline puts "*** gets data #{data}" socket.write(data) end rescue EOFError puts "*** disconnected" ensure socket.close end def finalize if @server @server.close File.delete(@socket_path) end end end supervisor = EchoUNIXServer.supervise("/tmp/sock_test") trap("INT") { supervisor.terminate; exit } sleep
Version data entries
14 entries across 14 versions & 1 rubygems