Parent

Included Modules

Listen::TCP::Broadcaster

Public Class Methods

new(host, port) click to toggle source

Initializes a Celluloid::IO-powered TCP-broadcaster

@param [String] host to broadcast on @param [String] port to broadcast on

Note: Listens on all addresses when host is nil

# File lib/listen/tcp/broadcaster.rb, line 17
def initialize(host, port)
  @sockets = []
  @server = TCPServer.new(host, port)
rescue
  _log :error, "Broadcaster.initialize: #{$!.inspect}:#{$@.join("\n")}"
  raise
end

Public Instance Methods

broadcast(payload) click to toggle source

Broadcasts given payload to all connected sockets

# File lib/listen/tcp/broadcaster.rb, line 41
def broadcast(payload)
  active_sockets = @sockets.select do |socket|
    _unicast(socket, payload)
  end
  @sockets.replace(active_sockets)
end
finalize() click to toggle source

Cleans up sockets and server

# File lib/listen/tcp/broadcaster.rb, line 31
def finalize
  @sockets.map(&:close) if @sockets
  @sockets = nil

  return unless @server
  @server.close
  @server = nil
end
run() click to toggle source

Continuously accept and handle incoming connections

# File lib/listen/tcp/broadcaster.rb, line 49
def run
  while socket = @server.accept
    @sockets << socket
  end
rescue Celluloid::Task::TerminatedError
  _log :debug, "TCP adapter was terminated: #{$!.inspect}"
rescue
  _log :error, "Broadcaster.run: #{$!.inspect}:#{$@.join("\n")}"
  raise
end
start() click to toggle source

Asynchronously start accepting connections

# File lib/listen/tcp/broadcaster.rb, line 26
def start
  async.run
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.