TCPSession.h
Go to the documentation of this file.
#ifndef __Session_h__
#define __Session_h__
#include "TCPSocket.h"
#include "SessionFilter.h"
namespace core {
class Command;
class TCPServer;
class TCPSession : public TCPSocket {
public:
TCPSession(EPoll &ePoll, TCPServer &server, std::string text = "");
~TCPSession();
Command *grab = NULL;
virtual void output(std::stringstream &data);
std::stringstream out;
void send();
void sendToAll();
void sendToAll(SessionFilter filter);
void terminate();
TCPServer &server;
protected:
virtual void onRegistered() override;
virtual void onDataReceived(char *data, int len) override;
virtual void onLineReceived(std::string line);
virtual void onBlockReceived(std::string block);
virtual void onConnected();
virtual void protocol(std::string data);
void setMode(Mode mode, int size = 0);
private:
char *lineBuffer = NULL;
int lineBufferSize = 0;
std::mutex mtx;
bool term = false;
enum Mode {LINE, BLOCK};
enum Mode mode = LINE;
int blockSize;
};
}
#endif
core::TCPSocket
Definition: TCPSocket.h:20
core::TCPSession::onBlockReceived
virtual void onBlockReceived(std::string block)
core::Socket::ePoll
EPoll & ePoll
Definition: Socket.h:117
TCPSocket.h
core::EPoll
Definition: EPoll.h:31
core::TCPSession::terminate
void terminate()
Definition: TCPSession.cpp:104
core::TCPSession::setMode
void setMode(Mode mode, int size=0)
core::TCPServer
Definition: TCPServer.h:24
core::TCPSession::onRegistered
virtual void onRegistered() override
Called after the socket has been registered with epoll processing.
Definition: TCPSession.cpp:24
core::SessionFilter
Definition: SessionFilter.h:10
core::TCPSession::protocol
virtual void protocol(std::string data)
Definition: TCPSession.cpp:18
core::TCPSession::onLineReceived
virtual void onLineReceived(std::string line)
Definition: TCPSession.cpp:74
core::TCPSession::grab
Command * grab
Definition: TCPSession.h:41
core::TCPSession::output
virtual void output(std::stringstream &data)
Definition: TCPSession.cpp:14
core::TCPSession
Definition: TCPSession.h:25
core::TCPSession::sendToAll
void sendToAll()
Definition: TCPSession.cpp:83
core
Definition: Command.cpp:5
core::Command
Definition: Command.h:22
core::TCPSession::out
std::stringstream out
Definition: TCPSession.h:49
core::TCPSession::TCPSession
TCPSession(EPoll &ePoll, TCPServer &server, std::string text="")
Definition: TCPSession.cpp:8
core::TCPSession::~TCPSession
~TCPSession()
Definition: TCPSession.cpp:10
core::TCPSession::onDataReceived
virtual void onDataReceived(char *data, int len) override
Definition: TCPSession.cpp:34
core::TCPSession::server
TCPServer & server
Definition: TCPSession.h:83
SessionFilter.h
core::TCPSession::send
void send()
Definition: TCPSession.cpp:98
core::TCPSession::onConnected
virtual void onConnected()
Definition: TCPSession.cpp:32