class Strum::Server::Session::Template

Public Class Methods

new(data = {}) click to toggle source

Creates a new Session Template object

# File lib/strum/server/session/template.rb, line 13
def initialize(data = {})
  self[:Socket]     = data[:Socket]
  self[:IP]         = data[:Socket].io.addr[-1]
  self[:InitTime]   = data[:InitTime]
  self[:BuildTime]  = data[:BuildTime]
  self[:Status]     = :ACTIVE
  self[:API] = Strum::Internal::Listener.instance
  self[:API].trigger_generic_events(self, Strum::Internal::Events::SessionBuildEvent)
end

Public Instance Methods

close!() click to toggle source

Closes this socket and marks this Generic as closed.

Calls superclass method Strum::Internal::Generic#close!
# File lib/strum/server/session/template.rb, line 51
def close!
  self[:API].trigger_events(Strum::Internal::Events::SessionClosedEvent)
  self[:Socket].close
  super
end
closed?() click to toggle source

Checks if this Session is (or should be) closed.

# File lib/strum/server/session/template.rb, line 58
def closed?
  true if self[:Status] == :CLOSED
  if self[:Socket].closed?
    close!
    true
  end
end
read(length) click to toggle source

Reads data from the underlying stream.

# File lib/strum/server/session/template.rb, line 39
def read(length)
  self[:API].trigger_events(Strum::Internal::Events::SessionReadEvent)
  unless closed?
    begin
      self[:Socket].read(length)
    rescue StreamError
      report "An error was encountered while reading from the stream of socket #{self[:IP]}"
    end
  end
end
write(data, &block) click to toggle source

Writes data to the underlying stream.

# File lib/strum/server/session/template.rb, line 24
def write(data, &block)
  self[:API].trigger_events(Strum::Internal::Events::SessionWriteEvent)
  unless closed?
    if data
      begin
        self[:Socket].write(data)
      rescue StreamError
        report "An error was encountered while writing to the stream of socket #{self[:IP]}"
      end
    end
  end
  block.call(self[:Socket]) if block_given?
end

Private Instance Methods

close() click to toggle source

Nothing to see here <.<

# File lib/strum/server/session/template.rb, line 67
def close; end