class Faye::Engine::Connection

Attributes

socket[RW]

Public Class Methods

new(engine, id, options = {}) click to toggle source
# File lib/faye/engines/connection.rb, line 10
def initialize(engine, id, options = {})
  @engine  = engine
  @id      = id
  @options = options
  @inbox   = Set.new
end

Public Instance Methods

connect(options, &block) click to toggle source
# File lib/faye/engines/connection.rb, line 24
def connect(options, &block)
  options = options || {}
  timeout = options['timeout'] ? options['timeout'] / 1000.0 : @engine.timeout

  set_deferred_status(:unknown)
  callback(&block)

  begin_delivery_timeout
  begin_connection_timeout(timeout)
end
deliver(message) click to toggle source
# File lib/faye/engines/connection.rb, line 17
def deliver(message)
  message.delete('clientId')
  return @socket.send(message) if @socket
  return unless @inbox.add?(message)
  begin_delivery_timeout
end
flush() click to toggle source
# File lib/faye/engines/connection.rb, line 35
def flush
  remove_timeout(:connection)
  remove_timeout(:delivery)

  set_deferred_status(:succeeded, @inbox.entries)
  @inbox = []

  @engine.close_connection(@id) unless @socket
end

Private Instance Methods

begin_connection_timeout(timeout) click to toggle source
# File lib/faye/engines/connection.rb, line 52
def begin_connection_timeout(timeout)
  add_timeout(:connection, timeout) { flush }
end
begin_delivery_timeout() click to toggle source
# File lib/faye/engines/connection.rb, line 47
def begin_delivery_timeout
  return if @inbox.empty?
  add_timeout(:delivery, MAX_DELAY) { flush }
end