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

Instance Method Summary collapse

Constructor Details

#initialize(hostname, port) ⇒ TCPServer

Returns a new instance of TCPServer.



10
11
12
# File 'lib/celluloid/io/tcp_server.rb', line 10

def initialize(hostname, port)
  @server = ::TCPServer.new(hostname, port)
end

Instance Method Details

#acceptObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/celluloid/io/tcp_server.rb', line 14

def accept
  actor = Thread.current[:actor]

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

#accept_nonblockObject



25
26
27
# File 'lib/celluloid/io/tcp_server.rb', line 25

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

#evented?Boolean

Are we inside a Celluloid ::IO actor?

Returns:

  • (Boolean)


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

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

#to_ioObject



29
30
31
# File 'lib/celluloid/io/tcp_server.rb', line 29

def to_io
  @server
end