Class: Celluloid::IO::TCPServer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/celluloid/io/tcp_server.rb

Overview

TCPServer with combined blocking and evented support

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname_or_port, port = nil) ⇒ TCPServer

Returns a new instance of TCPServer


10
11
12
13
14
15
16
# File 'lib/celluloid/io/tcp_server.rb', line 10

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

Class Method Details

.from_ruby_server(ruby_server) ⇒ Object

Convert a Ruby TCPServer into a Celluloid::IO::TCPServer


32
33
34
35
36
# File 'lib/celluloid/io/tcp_server.rb', line 32

def self.from_ruby_server(ruby_server)
  server = allocate
  server.instance_variable_set(:@server, ruby_server)
  server
end

Instance Method Details

#acceptObject


18
19
20
21
# File 'lib/celluloid/io/tcp_server.rb', line 18

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

#accept_nonblockObject


23
24
25
# File 'lib/celluloid/io/tcp_server.rb', line 23

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

#to_ioObject


27
28
29
# File 'lib/celluloid/io/tcp_server.rb', line 27

def to_io
  @server
end