Sha256: 3cc7bcccd2f3a4d631d706f532dc8cf391ca6a958be939012321c44a2a8a9504

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'socket'

module Celluloid
  module IO
    # UNIXServer with combined blocking and evented support
    class UNIXServer < Socket
      extend Forwardable
      def_delegators :to_io, :listen, :sysaccept

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

      # @overload initialize(socket_path)
      #   @param socket_path [String]
      #
      # @overload initialize(socket)
      #   @param socket [::UNIXServer]
      def initialize(socket)
        if socket.kind_of? ::BasicSocket
          # socket
          fail ArgumentError, "wrong kind of socket (#{socket.class} for UNIXServer)" unless socket.kind_of? ::UNIXServer
          super(socket)
        else
          begin
            super(::UNIXServer.new(socket))
          rescue => ex
            # Translate the EADDRINUSE jRuby exception.
            raise unless RUBY_PLATFORM == 'java'
            if ex.class.name == "IOError" && # Won't agree to .is_a?(IOError)
               ex.message.include?("in use")
              raise Errno::EADDRINUSE.new(ex.message)
            end
            raise
          end
        end
      end

      def accept
        Celluloid::IO.wait_readable(to_io)
        accept_nonblock
      end

      def accept_nonblock
        Celluloid::IO::UNIXSocket.new(to_io.accept_nonblock)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celluloid-io-0.17.3 lib/celluloid/io/unix_server.rb