My Project
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
core::TCPSession Class Reference

#include <TCPSession.h>

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

Public Member Functions

 TCPSession (EPoll &ePoll, TCPServer &server)
 
 TCPSession (EPoll &ePoll, TCPServer &server, std::string text)
 
virtual void output (std::stringstream &data)
 
void send (std::string data)
 
void sendToAll (std::string data)
 
void sendToAll (SessionFilter filter, std::string data)
 
- Public Member Functions inherited from core::TCPSocket
 TCPSocket (EPoll &ePoll)
 
 TCPSocket (EPoll &ePoll, std::string text)
 
void connect (IPAddress &address)
 
- Public Member Functions inherited from core::Socket
 Socket (EPoll &ePoll)
 
 Socket (EPoll &ePoll, std::string text)
 
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.
 
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 onRegistered ()
 
virtual void onUnregister ()
 Called when the socket has finished unregistering for the epoll processing. More...
 
bool needsToWrite ()
 

Public Attributes

Commandgrab = NULL
 
TCPServerserver
 
- Public Attributes inherited from core::TCPSocket
IPAddress ipAddress
 
- Public Attributes inherited from core::Socket
class {
bufferSize
 
bool active = false
 
- Public Attributes inherited from core::Object
std::string name
 
std::string tag
 

Protected Member Functions

virtual void onDataReceived (std::string data) override
 Called when data is received from the socket. More...
 
virtual void onRegister () override
 Called when the socket has finished registering with the epoll processing. More...
 
virtual void onConnected (std::stringstream &out)
 
virtual void protocol (std::stringstream &out, std::string data)
 
- Protected Member Functions inherited from core::Socket
void setBufferSize (int length)
 
virtual void onDataReceived (char *buffer, int len)
 
virtual void receiveData (char *buffer, int bufferLength)
 

Additional Inherited Members

- Protected Attributes inherited from core::Socket
EPollePoll
 
bool shutDown = false
 

Detailed Description

TCPSession

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

Member Function Documentation

◆ onConnected()

void core::TCPSession::onConnected ( std::stringstream &  out)
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 ( std::string  data)
overrideprotectedvirtual

Called when data is received from the socket.

The onConnected method is called when the socket is ready to communicate. Writing to the socket can begin on this call to initiate a contact with the remote device. The onDataReceived method is called when the socket has received an event from epoll and there is data ready to be read from the socket. The default handler will pull the data and put it into the streambuf for the socket. EPOLLIN

Parameters
datathe data that has been received from the socket.

Reimplemented from core::Socket.

◆ onRegister()

void core::TCPSession::onRegister ( )
overrideprotectedvirtual

Called when the socket has finished registering with the epoll processing.

The onRegister method is called before the socket is registered with ePoll so objects extending the Socket definition can initialize the socket before receiving events. Evoked when the descriptor is set using setDescriptor for the socket.

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::stringstream &  out,
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.

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

◆ send()

void core::TCPSession::send ( std::string  data)

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 ( std::string  data)

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,
std::string  data 
)

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.


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