Easy Simple Network Library  0.3.7
Public Member Functions | Static Public Member Functions | List of all members
esnlib::StringHandler Class Reference

String Handler class, an event handler who can handle network IO events for string message(ends with specific char) More...

#include <StringHandler.h>

Inheritance diagram for esnlib::StringHandler:
esnlib::IoHandler

Public Member Functions

virtual int OnRead (SessionPtr session, IoBufferPtr data)
 
virtual int OnWrite (SessionPtr session, IoBufferPtr data)
 
virtual void OnConnect (SessionPtr session)
 
virtual void OnDisconnect (SessionPtr session)
 
virtual void OnIdle (SessionPtr session, int idleType)
 
virtual void OnError (SessionPtr session, int errorType, int errorCode, const std::string &errorMsg)
 
virtual void HandleString (SessionPtr session, const std::string &str)
 

Static Public Member Functions

static int SplitStr (const std::string &src, const std::string &delims, std::vector< std::string > &strs)
 
static std::string TrimStr (std::string const &source, char const *spacechars=" \t\r\n")
 
static std::string GetDateTimeStr ()
 
static std::string GetTimeStr ()
 

Detailed Description

String Handler class, an event handler who can handle network IO events for string message(ends with specific char)

Member Function Documentation

static std::string esnlib::StringHandler::GetDateTimeStr ( )
static

Get current date and time in string format

Returns
Current date and time in string format
static std::string esnlib::StringHandler::GetTimeStr ( )
static

Get current time in string format

Returns
Current time in string format
virtual void esnlib::StringHandler::HandleString ( SessionPtr  session,
const std::string &  str 
)
virtual

Handle incoming string

Parameters
sessionCurrent session
strThe incoming string
virtual void esnlib::StringHandler::OnConnect ( SessionPtr  session)
virtual

The callback function for the OnConnect event

Parameters
sessionCurrent session

Implements esnlib::IoHandler.

virtual void esnlib::StringHandler::OnDisconnect ( SessionPtr  session)
virtual

The callback function for the OnDisconnect event

Parameters
sessionCurrent session

Implements esnlib::IoHandler.

virtual void esnlib::StringHandler::OnError ( SessionPtr  session,
int  errorType,
int  errorCode,
const std::string &  errorMsg 
)
virtual

The callback function for the OnError event

Parameters
sessionCurrent session
errorTypeThe error type (1 for read error, 2 for write error, 0 for connect error)
errorCodeThe error code (if error type == 0 and error code == 0, that means connect timeout)
errorMsgThe error message

Implements esnlib::IoHandler.

virtual void esnlib::StringHandler::OnIdle ( SessionPtr  session,
int  idleType 
)
virtual

The callback function for the OnIdle event

Parameters
sessionCurrent session
idleTypeThe idle type (1 for read idle, 2 for write idle, 0 for both)

Implements esnlib::IoHandler.

virtual int esnlib::StringHandler::OnRead ( SessionPtr  session,
IoBufferPtr  data 
)
virtual

The callback function for the OnRead event

Parameters
sessionCurrent session
dataThe buffer pointer of the useful data read
Returns
Whether need to take back the memory of the useful data

Implements esnlib::IoHandler.

virtual int esnlib::StringHandler::OnWrite ( SessionPtr  session,
IoBufferPtr  data 
)
virtual

The callback function for the OnWrite event

Parameters
sessionCurrent session
dataThe buffer pointer of the data written
Returns
Whether need to take back the memory of the data written

Implements esnlib::IoHandler.

static int esnlib::StringHandler::SplitStr ( const std::string &  src,
const std::string &  delims,
std::vector< std::string > &  strs 
)
static

Split the string

Parameters
srcThe original string
delimsThe delimiters
strsThe vector used to save the strings after splitting
Returns
How many strings you will get after splitting
static std::string esnlib::StringHandler::TrimStr ( std::string const &  source,
char const *  spacechars = " \t\r\n" 
)
static

Trim the string

Parameters
sourceThe original string
spacecharsThe space characters
Returns
The string after trimming

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