/home/barant/Development/BMA/server_core/ServerCore/BMASocket.h
#ifndef __BMASocket_h__
#define __BMASocket_h__
#include "includes"
#include "BMAObject.h"
#include "BMAEvent.h"
#include "BMAProperty.h"
class BMAEPoll;
class BMASocket : public std::streambuf,
public BMAObject {
public:
BMASocket(BMAEPoll &ePoll);
~BMASocket();
void setDescriptor(int descriptor);
int getDescriptor();
class {
int value;
public:
int & operator = (const int &i) { return value = i; }
operator int () const { return value; }
} bufferSize;
void eventReceived(struct epoll_event event);
void write(std::string data);
void write(char *buffer, int length);
void output(std::stringstream &out);
virtual void onRegistered();
virtual void onUnregistered();
void enable(bool mode);
protected:
BMAEPoll &ePoll; // The EPoll control object.
bool shutDown = false;
void setBufferSize(int length);
virtual void onConnected();
virtual void onTLSInit();
// virtual void onDisconnected(); ///< Called when socket is closing and no longer ready to communicate.
virtual void onDataReceived(std::string data) = 0;
void shutdown();
virtual void receiveData(char *buffer, int bufferLength);
private:
int descriptor = -1;
std::mutex lock;
struct epoll_event event; // Event selection construction structure.
//--------------------------------------------------
// These are used to schedule the socket activity.
//--------------------------------------------------
void setRead();
void setWrite();
void setReadWrite();
void resetRead();
void resetWrite();;
void resetReadWrite(int x);
void clear();
//-------------------------------------------------------------------------------------
// the writeSocket is called when epoll has received a write request for a socket.
// Writing data to this socket is queued in the streambuf and permission is requested
// to write to the socket. This routine handles the writing of the streambuf data
// buffer to the socket.
//-------------------------------------------------------------------------------------
void writeSocket();
// int_type underflow();
// int_type uflow();
// int_type pbackfail(int_type ch);
// streamsize showmanyc();
char *buffer; // This is a pointer to the managed buffer space.
int length; // This is the length of the buffer.
// const char * const begin_;
// const char * const end_;
// const char * const current_;
std::queue<std::string> fifo;
bool active = false;
};
#endif
BMASocket
Definition: BMASocket.h:31
BMASocket::eventReceived
void eventReceived(struct epoll_event event)
Parse epoll event and call specified callbacks.
Definition: BMASocket.cpp:46
BMASocket::onConnected
virtual void onConnected()
Called when socket is open and ready to communicate.
Definition: BMASocket.cpp:116
BMASocket::getDescriptor
int getDescriptor()
Get the descriptor for the socket.
Definition: BMASocket.cpp:27
BMASocket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: BMASocket.cpp:42
BMAEPoll
Definition: BMAEPoll.h:29
BMASocket::onRegistered
virtual void onRegistered()
Called when the socket has finished registering with the epoll processing.
Definition: BMASocket.cpp:38
BMASocket::write
void write(std::string data)
Definition: BMASocket.cpp:129
BMASocket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: BMASocket.cpp:19
BMASocket::enable
void enable(bool mode)
Enable the socket to read or write based upon buffer.
Definition: BMASocket.cpp:72
BMASocket::receiveData
virtual void receiveData(char *buffer, int bufferLength)
Definition: BMASocket.cpp:84
BMAObject
Definition: BMAObject.h:6
BMASocket::onDataReceived
virtual void onDataReceived(std::string data)=0
Called when data is received from the socket.