core::TCPSession Class Reference

`#include <TCPSession.h>`

Inheritance diagram for core::TCPSession:
[legend]
Collaboration diagram for core::TCPSession:
[legend]

## Public Member Functions

| TCPSession (EPoll &ePoll, TCPServer &server, std::string text="")
| ~TCPSession ()
virtual void | output (std::stringstream &data)
void | send ()
void | sendToAll ()
void | sendToAll (SessionFilter filter)
void | terminate ()
Public Member Functions inherited from core::TCPSocket
| TCPSocket (EPoll &ePoll)
| TCPSocket (EPoll &ePoll, std::string text)
| ~TCPSocket ()
void | connect (IPAddress &address)
Public Member Functions inherited from core::Socket
| Socket (EPoll &ePoll, std::string text="")
| ~Socket ()
void | shutdown (std::string text="unknown")
void | setDescriptor (int descriptor)
| Set the descriptor for the socket. More...
int | getDescriptor ()
| Get the descriptor for the socket. More...
bool | eventReceived (struct epoll_event event)
| Parse epoll event and call specified callbacks. More...
int | write (std::string data)
void | write (char *buffer, int length)
void | output (std::stringstream &out)
virtual void | onRegister ()
| Called before the socket has registered with the epoll processing. More...
virtual void | onUnregister ()
virtual void | onUnregistered ()
| Called when the socket has finished unregistering for the epoll processing. More...
bool | needsToWrite ()

## Public Attributes

Command * | grab = NULL
std::stringstream | out
TCPServer & | server
Public Attributes inherited from core::TCPSocket
IPAddress | ipAddress
Public Attributes inherited from core::Socket
bool | reset = false
Public Attributes inherited from core::Object
std::string | name
std::string | tag

## Protected Member Functions

virtual void | onRegistered () override
| Called after the socket has been registered with epoll processing. More...
virtual void | onDataReceived (char *data, int len) override
virtual void | onLineReceived (std::string line)
virtual void | onBlockReceived (std::string block)
virtual void | onConnected ()
virtual void | protocol (std::string data)
void | setMode (Mode mode, int size=0)
Protected Member Functions inherited from core::Socket
void | setBufferSize (int length)
int | getBufferSize ()
virtual void | onDataReceived (std::string data)
| Called when data is received from the socket. More...
virtual void | receiveData (char *buffer, int bufferLength)

## Additional Inherited Members

Protected Attributes inherited from core::Socket
EPoll & | ePoll
bool | shutDown = false

## Detailed Description

TCPSession

TCPSession defines the nature of the interaction with the client and stores persistent data for a defined session. TCPSession objects are not sockets but instead provide a communications control mechanism. Protocol conversations are provided through extensions from this object.

## Constructor & Destructor Documentation

## TCPSession()

core::TCPSession::TCPSession | ( | EPoll & | ePoll,
|  | TCPServer & | server,
|  | std::string | text = `""`
| ) |  |

## ~TCPSession()

core::TCPSession::~TCPSession | ( |  | ) |

## Member Function Documentation

## onBlockReceived()

virtual void core::TCPSession::onBlockReceived | ( | std::string | block | ) |

protectedvirtual

Override the onBlockReceived method to receive a string of characters that represents a single block of data of length determined by the block length value. If onDataReceived was overriden this method will not be called unless the onDataReceived calls this method explicitly using the class and member name.

## onConnected()

void core::TCPSession::onConnected | ( |  | ) |

protectedvirtual

This method is called from within the protocol method when protocol is called on the initial connection where the data is an empty string. Use this method to deliver a message to the connection upon connection.

## onDataReceived()

void core::TCPSession::onDataReceived | ( | char * | data,
|  | int | len
| ) |  |

overrideprotectedvirtual

Override this method to receive data directly from the socket as data is received. If you need data split by line termination characters then override the onLineReceived method instead.

Reimplemented from core::Socket.

## onLineReceived()

void core::TCPSession::onLineReceived | ( | std::string | line | ) |

protectedvirtual

Override the onLineReceived method to receive a string of characters that represents a single line of data terminated by a LF or CRLF. If onDataReceived was overriden this method will not be called unless the onDataReceived calls this method explicitly using the class and member name.

## onRegistered()

void core::TCPSession::onRegistered | ( |  | ) |

overrideprotectedvirtual

Called after the socket has been registered with epoll processing.

Reimplemented from core::Socket.

Reimplemented in core::TLSSession.

## output()

void core::TCPSession::output | ( | std::stringstream & | out | ) |

virtual

The output method is called by a socket session (BMASession) and will output the detail information for the client socket. When extending BMATCPSocket or BMASession you can override the method to add attributes to the list.

Reimplemented from core::TCPSocket.

Reimplemented in core::TLSSession.

## protocol()

void core::TCPSession::protocol | ( | std::string | data = `""` | ) |

protectedvirtual

Override the protocol method to manage and control the session communications in your inherited session. If you do not override this method then the Session default will process the 'commands' added to the server object using the processRequest method on the session input.

When data is received within the session two modes are available to pass the data through the protocol method: LINE or BLOCK.

Reimplemented in core::TLSSession, and core::ConsoleSession.

## send()

void core::TCPSession::send | ( |  | ) |

The send method is used to output the contents of the out stream to the session containing the stream.

## sendToAll() [1/2]

void core::TCPSession::sendToAll | ( |  | ) |

Use this sendToAll method to output the contents of the out stream to all the connections on the server excluding the sender session.

## sendToAll() [2/2]

void core::TCPSession::sendToAll | ( | SessionFilter | filter | ) |

Use this sendToAll method to output the contents of the out stream to all the connections on the server excluding the sender session and the entries identified by the passed in filter object.

## setMode()

void core::TCPSession::setMode | ( | Mode | mode,
|  | int | size = `0`
| ) |  |

protected

Use the setMode method to set the receiving mode for the data on this socket. Data can be received in LINE mode, which will receive data from the socket one line at a time, or BLOCK mode where a certain specified data block is received before calling the onBlockReceived method.

## terminate()

void core::TCPSession::terminate | ( |  | ) |

Use this method to terminate this TCPSession.

## Member Data Documentation

## grab

Command* core::TCPSession::grab = NULL

## out

std::stringstream core::TCPSession::out

Use out to send data to the session socket or other session sockets.

## server

TCPServer& core::TCPSession::server

The documentation for this class was generated from the following files:

- TCPSession.h
- TCPSession.cpp