Class: Revactor::TCP::Listener
- Inherits:
-
Rev::TCPListener
- Object
- Rev::TCPListener
- Revactor::TCP::Listener
- Defined in:
- lib/revactor/tcp.rb
Overview
TCP Listener returned from Revactor::TCP.listen
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
Instance Method Summary collapse
-
#accept ⇒ Object
Accept an incoming connection.
-
#active=(state) ⇒ Object
Change the default active setting for newly accepted connections.
-
#active? ⇒ Boolean
Will newly accepted connections be active?.
-
#initialize(host, port, options = {}) ⇒ Listener
constructor
Listen on the specified address and port.
- #inspect ⇒ Object
Constructor Details
#initialize(host, port, options = {}) ⇒ Listener
Listen on the specified address and port. Accepts the following options:
:active - Default active setting for new connections. See the
documentation Rev::TCP::Socket#active= for more info
:controller - The controlling actor, default Actor.current
:filter - An symbol/class or array of symbols/classes which implement
#encode and #decode methods to transform data sent and
received data respectively via Revactor::TCP::Socket.
See the "Filters" section in the README for more information
358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/revactor/tcp.rb', line 358 def initialize(host, port, = {}) super(host, port) opts = { :active => false, :controller => Actor.current }.merge() @active, @controller = opts[:active], opts[:controller] @filterset = [:filter] @accepting = false end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
344 345 346 |
# File 'lib/revactor/tcp.rb', line 344 def controller @controller end |
Instance Method Details
#accept ⇒ Object
Accept an incoming connection
394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/revactor/tcp.rb', line 394 def accept raise "another actor is already accepting" if @accepting @accepting = true @receiver = Actor.current enable Actor.receive do |filter| filter.when(T[:tcp_connection, self]) do |_, _, sock| @accepting = false return sock end end end |
#active=(state) ⇒ Object
Change the default active setting for newly accepted connections
376 377 378 379 380 381 382 |
# File 'lib/revactor/tcp.rb', line 376 def active=(state) unless [true, false, :once].include? state raise ArgumentError, "must be true, false, or :once" end @active = state end |
#active? ⇒ Boolean
Will newly accepted connections be active?
385 |
# File 'lib/revactor/tcp.rb', line 385 def active?; @active; end |
#inspect ⇒ Object
371 372 373 |
# File 'lib/revactor/tcp.rb', line 371 def inspect "#<#{self.class}:0x#{object_id.to_s(16)}>" end |