Sha256: 266534fd90c4a458c19969bf2d5e19d4470caac7f82bca849cf8af133b32e4a4

Contents?: true

Size: 941 Bytes

Versions: 6

Compression:

Stored size: 941 Bytes

Contents

require 'socket'

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

      def initialize(hostname_or_port, port = nil)
        if port.nil?
          @server = ::TCPServer.new(hostname_or_port)
        else
          @server = ::TCPServer.new(hostname_or_port, port)
        end
      end

      def accept
        Celluloid::IO.wait_readable(@server)
        accept_nonblock
      end

      def accept_nonblock
        Celluloid::IO::TCPSocket.new(@server.accept_nonblock)
      end

      def to_io
        @server
      end

      # Convert a Ruby TCPServer into a Celluloid::IO::TCPServer
      def self.from_ruby_server(ruby_server)
        server = allocate
        server.instance_variable_set(:@server, ruby_server)
        server
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
celluloid-io-0.17.2 lib/celluloid/io/tcp_server.rb
celluloid-io-0.17.1 lib/celluloid/io/tcp_server.rb
celluloid-io-0.17.0 lib/celluloid/io/tcp_server.rb
celluloid-io-0.16.5.pre0 lib/celluloid/io/tcp_server.rb
celluloid-io-0.16.2 lib/celluloid/io/tcp_server.rb
celluloid-io-0.16.1 lib/celluloid/io/tcp_server.rb