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

Version Path
celluloid-io-0.17.1 examples/echo_unix_server.rb
celluloid-io-0.17.0 examples/echo_unix_server.rb
celluloid-io-0.16.5.pre0 examples/echo_unix_server.rb
celluloid-io-0.16.2 examples/echo_unix_server.rb
celluloid-io-0.16.1 examples/echo_unix_server.rb
celluloid-io-0.16.0 examples/echo_unix_server.rb
celluloid-io-0.16.0.pre2 examples/echo_unix_server.rb
celluloid-io-0.16.0.pre examples/echo_unix_server.rb
celluloid-io-0.15.0 examples/echo_unix_server.rb
celluloid-io-0.15.0.pre2 examples/echo_unix_server.rb
celluloid-io-0.15.0.pre examples/echo_unix_server.rb
celluloid-io-0.14.1 examples/echo_unix_server.rb
celluloid-io-0.14.0 examples/echo_unix_server.rb
celluloid-io-0.14.0.pre examples/echo_unix_server.rb