Socket.h
Go to the documentation of this file.
#ifndef __Socket_h__
#define __Socket_h__
#include "includes"
#include "Object.h"
namespace core {
class EPoll;
class Socket : public core::Object {
public:
Socket(EPoll &ePoll, std::string text = "");
~Socket();
void shutdown(std::string text = "unknown");
void setDescriptor(int descriptor);
int getDescriptor();
bool eventReceived(struct epoll_event event);
int write(std::string data);
void write(char *buffer, int length);
void output(std::stringstream &out);
virtual void onRegister();
virtual void onRegistered();
virtual void onUnregister();
virtual void onUnregistered();
bool needsToWrite();
bool reset = false;
protected:
EPoll &ePoll; // The EPoll control object.
bool shutDown = false;
void setBufferSize(int length);
int getBufferSize();
// virtual void onConnected(); ///< Called when socket is open and ready to communicate.
// virtual void onDisconnected(); ///< Called when socket is closing and no longer ready to communicate.
virtual void onDataReceived(std::string data);
virtual void onDataReceived(char *buffer, int len);
virtual void receiveData(char *buffer, int bufferLength);
private:
std::string text;
int descriptor = -1;
std::mutex lock;
std::mutex outlock;
bool readHangup = false;
// struct epoll_event event; // Event selection construction structure.
//-------------------------------------------------------------------------------------
// 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;
};
}
#endif
core::Socket::ePoll
EPoll & ePoll
Definition: Socket.h:117
core::EPoll
Definition: EPoll.h:31
core::Socket::receiveData
virtual void receiveData(char *buffer, int bufferLength)
Definition: Socket.cpp:110
core::Socket::onRegister
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:53
core::Socket::shutDown
bool shutDown
Definition: Socket.h:119
core::Socket::eventReceived
bool eventReceived(struct epoll_event event)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:61
core::Socket::getDescriptor
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:40
core::Socket
Definition: Socket.h:33
core::Socket::write
int write(std::string data)
Definition: Socket.cpp:155
core::Socket::onRegistered
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:55
core
Definition: Command.cpp:5
core::Object
Definition: Object.h:8
core::Socket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:24
core::Socket::setBufferSize
void setBufferSize(int length)
Definition: Socket.cpp:44
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:174
core::Socket::onDataReceived
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:102
core::Socket::~Socket
~Socket()
Definition: Socket.cpp:14
core::Socket::needsToWrite
bool needsToWrite()
Definition: Socket.cpp:169
Object.h
core::Socket::getBufferSize
int getBufferSize()
Definition: Socket.cpp:49
core::Socket::reset
bool reset
Definition: Socket.h:113
core::Socket::onUnregister
virtual void onUnregister()
Definition: Socket.cpp:57
core::Socket::output
void output(std::stringstream &out)
Definition: Socket.cpp:165
core::Socket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:59
core::Socket::Socket
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:8