BMA Server Framework
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
BMASocket Class Referenceabstract

#include <BMASocket.h>

Inheritance diagram for BMASocket:
Inheritance graph
[legend]
Collaboration diagram for BMASocket:
Collaboration graph
[legend]

Public Member Functions

 BMASocket (BMAEPoll &ePoll)
 
void setDescriptor (int descriptor)
 Set the descriptor for the socket.
 
int getDescriptor ()
 Get the descriptor for the socket.
 
void eventReceived (struct epoll_event event)
 Parse epoll event and call specified callbacks. More...
 
void write (std::string data)
 
void write (char *buffer, int length)
 
void output (std::stringstream &out)
 
virtual void onRegistered ()
 Called when the socket has finished registering with the epoll processing. More...
 
virtual void onUnregistered ()
 Called when the socket has finished unregistering for the epoll processing. More...
 
void enable (bool mode)
 Enable the socket to read or write based upon buffer.
 

Public Attributes

class {
bufferSize
 
- Public Attributes inherited from BMAObject
std::string name
 
std::string tag
 

Protected Member Functions

void setBufferSize (int length)
 
virtual void onConnected ()
 Called when socket is open and ready to communicate. More...
 
virtual void onTLSInit ()
 
virtual void onDataReceived (std::string data)=0
 Called when data is received from the socket. More...
 
void shutdown ()
 
virtual void receiveData (char *buffer, int bufferLength)
 

Protected Attributes

BMAEPollePoll
 
bool shutDown = false
 

Detailed Description

BMASocket

The core component to managing a socket.

Hooks into the BMAEPoll through the registration and unregistration process and provides a communication socket of the specified protocol type. This object provides for all receiving data threading through use of the BMAEPoll object and also provides buffering for output data requests to the socket.

A program using a socket object can request to open a socket (file or network or whatever) and communicate through the streambuffer interface of the socket object.

The socket side of the BMASocket accepts EPOLLIN event and will maintain the data in a buffer for the stream readers to read. A onDataReceived event is then sent with the data received in the buffer that can be read through the stream.

When writing to the stream the data is written into a buffer and a EPOLLOUT is scheduled. Upon receiving the EPOLLOUT event then the buffer is written to the socket output.

Member Function Documentation

◆ eventReceived()

void BMASocket::eventReceived ( struct epoll_event  event)

Parse epoll event and call specified callbacks.

The event received from epoll is sent through the eventReceived method which will parse the event and call the read and write callbacks on the socket.

This method is called by the BMAEPoll object and should not be called from any user extended classes unless an epoll event is being simulated.

◆ onConnected()

void BMASocket::onConnected ( )
protectedvirtual

Called when socket is open and ready to communicate.

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.

Reimplemented in BMASession.

◆ onDataReceived()

virtual void BMASocket::onDataReceived ( std::string  data)
protectedpure virtual

Called when data is received from the socket.

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.

Implemented in BMATCPServerSocket, BMASession, and BMAUDPServerSocket.

◆ onRegistered()

void BMASocket::onRegistered ( )
virtual

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

The onRegistered method is called whenever the socket is registered with ePoll and socket communcation events can be started.

◆ onUnregistered()

void BMASocket::onUnregistered ( )
virtual

Called when the socket has finished unregistering for the epoll processing.

The onUnregistered method is called whenever the socket is unregistered with ePoll and socket communcation events will be stopped. The default method will close the socket and clean up the connection. If this is overridden by an extended object then the object should call this method to clean the socket up.

◆ receiveData()

void BMASocket::receiveData ( char *  buffer,
int  bufferLength 
)
protectedvirtual

receiveData will read the data from the socket and place it in the socket buffer. TLS layer overrides this to be able to read from SSL.

Reimplemented in BMATLSSession.

◆ write()

void BMASocket::write ( std::string  data)

Write data to the socket.


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