Class: Revactor::UNIX::Listener

Inherits:
Rev::UNIXListener
  • Object
show all
Defined in:
lib/revactor/unix.rb

Overview

UNIX Listener returned from Revactor::UNIX.listen

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Listener

Listen on the specified path. Accepts the following options:

:active - Default active setting for new connections.  See the
          documentation Rev::UNIX::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::UNIX::Socket.
          See the "Filters" section in the README for more information


327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/revactor/unix.rb', line 327

def initialize(path, options = {})
  super(path)
  opts = {
    :active     => false,
    :controller => Actor.current
  }.merge(options)

  @active, @controller = opts[:active], opts[:controller]
  @filterset = options[:filter]

  @accepting = false
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



313
314
315
# File 'lib/revactor/unix.rb', line 313

def controller
  @controller
end

Instance Method Details

#acceptObject

Accept an incoming connection



364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/revactor/unix.rb', line 364

def accept
  raise "another actor is already accepting" if @accepting

  @accepting = true
  @receiver = Actor.current
  enable

  Actor.receive do |filter|
    filter.when(T[:unix_connection, self]) do |_, _, sock|
      @accepting = false
      return sock
    end
  end
end

#active=(state) ⇒ Object

Change the default active setting for newly accepted connections



345
346
347
348
349
350
351
# File 'lib/revactor/unix.rb', line 345

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?

Returns:

  • (Boolean)


354
# File 'lib/revactor/unix.rb', line 354

def active?; @active; end

#inspectObject



340
341
342
# File 'lib/revactor/unix.rb', line 340

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}>"
end