Class: Celluloid::TCPServer

Inherits:
Object show all
Includes:
IO
Defined in:
lib/vendor/celluloid/lib/celluloid/tcp_server.rb

Overview

A TCPServer that runs as an actor

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ TCPServer

Bind a TCP server to the given host and port



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

def initialize(host, port)
  @server = ::TCPServer.new host, port
  run!
end

Instance Method Details

#on_connect(connection) ⇒ Object

Called whenever a new connection is opened



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

def on_connect(connection)
  connection.close
end

#runObject

Run the TCP server event loop



15
16
17
18
19
20
# File 'lib/vendor/celluloid/lib/celluloid/tcp_server.rb', line 15

def run
  while true
    wait_readable(@server)
    on_connect @server.accept
  end
end

#terminateObject

Terminate this server



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

def terminate
  @server.close
  super
end