Class Connection
In: lib/network/connection.rb
Parent: Session
Connection
Session
TopLevel

The connection class maintains a socket connection with a reactor and handles all events dispatched by the reactor.

Methods

Attributes

addr  [R] 
host  [R] 
inbuffer  [RW] 
initdone  [R] 
outbuffer  [RW] 
pstack  [R] 
server  [R] 
sockio  [R] 

Public Class methods

Create a new connection object

server
The reactor this connection is associated with.
sock
The socket for this connection.
returns
A connection object.

Public Instance methods

handle_close is called to when an close event occurs for this session.

handle_input is called to order a connection to process any input waiting on its socket. Input is parsed into lines based on the occurance of the CRLF terminator and pushed into a buffer which is a list of lines. The buffer expands dynamically as input is processed. Input that has yet to see a CRLF terminator is left in the connection’s inbuffer.

handle_oob is called when an out of band data event occurs for this session.

handle_output is called to order a connection to process any output waiting on its socket.

init is called before using the connection.

returns
true is connection is properly initialized
attrib
- A Symbol not handled here is assumed to be a query and
          its handling is delegated to the ProtocolStack, the result
          of which is a pair immediately sent back to as a message
          to the client.

        <pre>
        client -> us
            :echo
        us     -> ProtocolStack
            query(:echo)
        ProtocolStack -> us
            [:echo, true]
        us -> client
            [:echo, true]
        </pre>

sendmsg places a message on the Connection’s output buffer.

msg
The message, a reference to a buffer
+attrib,val+
- An Array not handled here is assumed to be a set command and
          its handling is delegated to the ProtocolStack.

        <pre>
        client -> us
            [:color, true]
        us     -> ProtocolStack
            set(:color, true)
        </pre>

This is called from TelnetFilter when we are done with negotiations. The event :initdone wakens observer to begin user activity

Update will be called when the object the connection is observing wants to notify us of a change in state or new message. When a new connection is accepted in acceptor that connection is passed to the observer of the acceptor which allows the client to attach an observer to the connection and make the connection an observer of that object. We need to keep both sides interest in each other limited to a narrow but flexible interface to prevent tight coupling.

This supports the following:

:quit
- This symbol message from the client is a request to
      close the Connection.  It is handled here.
String
- A String is assumed to be output and placed in our
  @outbuffer.

[Validate]