Sha256: 2c9b7f9c62492b553eab2d9fa56abd16ce5435734f86a8a69d9786a88883d09e

Contents?: true

Size: 1001 Bytes

Versions: 6

Compression:

Stored size: 1001 Bytes

Contents

require 'socket'

module Celluloid
  module IO
    # UNIXServer with combined blocking and evented support
    class UNIXServer
      extend Forwardable
      def_delegators :@server, :listen, :sysaccept, :close, :closed?

      def self.open(socket_path)
        self.new(socket_path)
      end

      def initialize(socket_path)
        @server = ::UNIXServer.new(socket_path)
      end

      def accept
        actor = Thread.current[:actor]

        if evented?
          Celluloid.current_actor.wait_readable @server
          accept_nonblock
        else
          Celluloid::IO::UNIXSocket.from_ruby_socket @server.accept
        end
      end

      def accept_nonblock
        Celluloid::IO::UNIXSocket.from_ruby_socket @server.accept_nonblock
      end

      def to_io
        @server
      end

      # Are we inside a Celluloid ::IO actor?
      def evented?
        actor = Thread.current[:actor]
        actor && actor.mailbox.is_a?(Celluloid::IO::Mailbox)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eye-0.2.4 lib/eye/io/unix_server.rb
eye-0.2.3 lib/eye/io/unix_server.rb
eye-0.2.2 lib/eye/io/unix_server.rb
eye-0.2.1 lib/eye/io/unix_server.rb
eye-0.2 lib/eye/io/unix_server.rb
eye-0.1.11 lib/eye/io/unix_server.rb