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

#include <TCPServer.h>

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

Public Member Functions

 TCPServer (EPoll &ePoll, IPAddress address, std::string delimiter=" ", int depth=10, std::string text="")
 
virtual ~TCPServer ()
 
virtual void sessionErrorHandler (std::string errorString, std::stringstream &out)
 
virtual TCPSessiongetSocketAccept (EPoll &epoll)
 
void removeFromSessionList (TCPSession *session)
 
void output (std::stringstream &out)
 Output the consoles array to the console.
 
void sendToAll (std::stringstream &out)
 
void sendToAll (std::stringstream &out, TCPSession &sender, SessionFilter filter)
 
void sendToAll (std::stringstream &out, TCPSession &sender)
 
- 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, std::string text="")
 
virtual ~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.

 
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 onRegistered ()
 Called after the socket has been registered with epoll processing.
 
virtual void onUnregister ()
 
virtual void onUnregistered ()
 Called when the socket has finished unregistering for the epoll processing. More...
 
bool needsToWrite ()
 

Public Attributes

std::vector< TCPSession * > sessions
 
CommandList commands
 
IPAddressListblackList
 
IPAddressListwhiteList
 
SubscriptionManager subscriptions
 
- Public Attributes inherited from core::TCPSocket
IPAddress ipAddress
 
- Public Attributes inherited from core::Socket
bool reset = false
 

Protected Member Functions

void onDataReceived (std::string data) override
 
int processCommand (coreutils::ZString &request, TCPSession &session) override
 
- Protected Member Functions inherited from core::Socket
void setBufferSize (int length)
 
int getBufferSize ()
 
virtual void onDataReceived (coreutils::ZString &data)
 
virtual void receiveData (coreutils::ZString &buffer)
 

Additional Inherited Members

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

Detailed Description

TCPServer

Manage a socket connection as a TCP server type. Connections to the socket are processed through the accept functionality.

A list of connections is maintained in a vector object.

This object extends the BMACommand object as well so it can be added to a Console object and process commands to display status information.

Constructor & Destructor Documentation

◆ TCPServer()

core::TCPServer::TCPServer ( EPoll ePoll,
IPAddress  address,
std::string  delimiter = " ",
int  depth = 10,
std::string  text = "" 
)

The constructor for the TCPServer object.

Parameters
ePollthe EPoll instance that manages the socket.
urlthe IP address for the socket to receive connection requests.
portthe port number that the socket will listen on.
commandNamethe name of the command used to invoke the status display for this object.

◆ ~TCPServer()

core::TCPServer::~TCPServer ( )
virtual

The destructor for this object.

Member Function Documentation

◆ getSocketAccept()

TCPSession * core::TCPServer::getSocketAccept ( EPoll epoll)
virtual

getSocketAccept is designed to allow a polymorphic extension of this object to return a type of object that extends the definition of the server socket. Returning the appropriate session object that extends from Session provides the mechanism where the server can select the protocol dialog for the desired service.

Reimplemented in core::ConsoleServer.

◆ onDataReceived()

void core::TCPServer::onDataReceived ( std::string  data)
overrideprotectedvirtual

Override the virtual dataReceived since for the server these are requests to accept the new connection socket. No data is to be read or written when this method is called. It is the response to the fact that a new connection is coming into the system

Parameters
datathe pointer to the buffer containing the received data.
lengththe length of the associated data buffer.

Reimplemented from core::Socket.

◆ processCommand()

int core::TCPServer::processCommand ( coreutils::ZString &  request,
TCPSession session 
)
overrideprotectedvirtual

This method is called when the Command associated with this object is requested because a user has typed in the associated command name on a command entry line.

Parameters
thesession object to write the output to.

Reimplemented from core::Command.

◆ sendToAll() [1/2]

void core::TCPServer::sendToAll ( std::stringstream &  out,
TCPSession sender 
)

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.

◆ sendToAll() [2/2]

void core::TCPServer::sendToAll ( std::stringstream &  out,
TCPSession sender,
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.

Member Data Documentation

◆ blackList

IPAddressList* core::TCPServer::blackList

If not NULL the blacklist object can be assigned to this server socket and the server IP addresses connecting to the server attempting to accept a socket are contained in this list then the connection is rejected and no accept is granted.

◆ commands

CommandList core::TCPServer::commands

The commands object is a CommandList and is used to store Command objects to be parsed and run as data comes into the session.

◆ sessions

std::vector<TCPSession *> core::TCPServer::sessions

The list of sessions that are currently open and being maintained by this object.

◆ subscriptions

SubscriptionManager core::TCPServer::subscriptions

The Subscription Manager tracks all subscriptions on the server.

◆ whiteList

IPAddressList* core::TCPServer::whiteList

If not NULL the blacklist object can be assigned to this server socket and the server IP addresses connecting to the server attempting to accept a socket are contained in this list then the connection is rejected and no accept is granted.


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