dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
47 struct timeval now, last_snap;
49 gettimeofday( &now, NULL );
51 gettimeofday( &last_snap, NULL );
68 log_Debug(
"TCPServer::run notify wakeup " <<
87 log_Error(
"TCPServer::run handshake failure socket " <<
91 catch ( std::exception &e ) {
92 log_Error(
"TCPServer::run exception in handshake " << e.what()
96 log_Error(
"TCPServer::run unhandled exception in handshake " <<
107 ssize_t received = 0;
120 log_Error(
"TCPServer::run readSocket failure socket " <<
126 catch ( std::exception &e ) {
127 log_Error(
"TCPServer::run exception in ssReadSocket " << e.what()
131 log_Error(
"TCPServer::run unhandled exception in ssReadSocket socket " <<
146 catch ( std::exception &e ) {
147 log_Error(
"TCPServer::run exception in ssShutdown " << e.what()
151 log_Error(
"TCPServer::run unhandled exception in ssShutdown " <<
165 gettimeofday( &now, NULL );
168 gettimeofday( &last_snap, NULL );
174 catch (
const std::exception &e ) {
175 log_Fatal(
"TCPServer::run caught unhandled exception " << e.what() );
178 log_Fatal(
"TCPServer::run caught std::exception " );
185 gettimeofday( &tv, 0 );
@ ssReadSocket
The TCPServer is about to invoke readSocket(BaseSocket*).
TCPServer(TCPListener &listener)
Construct a TCPServer for the TCPListener.
double getIdleSeconds()
Get the number of secodns the TCPServer has been idle.
TCPConnectionData * data
Data context.
Address getPeerAddress() const
Get the peer (remote) address for this socket.
@ ssShutdown
The TCPServer is about to invoke shutdown(BaseSocket*).
SockState
BaseSocket lifecycle states.
virtual bool handShake(network::BaseSocket *socket, ssize_t &received, ssize_t &sent)=0
Override to perform a protocol handshake.
@ None
Undefined / initial.
bool request_stop_
If true, the TCPServer should stop.
std::string asString(bool withport=false) const
Return a string representation of this Address.
SockState state
State of the socket.
@ New
New connection, TCPServer::handShake() will be called.
@ ssAwoken
The TCPServer has woken up from a wait either due to an event or the wait timing out.
@ ssShutdownDone
ssShutdown completed.
@ Shut
BaseSocket is hung up or in error, TCPServer::shutDown() will be called.
@ ssHandshakeDone
ssHandshake completed.
bool has_stopped_
If true, the TCPServer has stopped.
@ ssHandshake
The TCPServer is about to invoke handShake(BaseSocket*).
virtual void run()
Run the TCPServer thread.
BaseSocket * socket
Pointer to the socket.
#define log_Fatal(what)
Macro to log Fatal.
void releaseWork(const SocketWork &work)
Called by a TCPServer to signal that the work has been handled and event detection on it can resume.
A C++ platform interface to lean Linux services tailored for containerized deployment.
#define log_Error(what)
Macro to log Error.
struct timeval last_active_
Time of last request handling.
bool waitForActivity(TCPServer *server)
Called by the TCPServer, enters wait state until woken up by either a timeout or a notify by TCPListe...
@ ssReleaseWork
The TCPServer is releasing the request.
SocketWork * popWork()
Pop work.
void snapRUsage()
Take a snapshot of the thread's resource usage.
@ Read
Data is ready to be read, TCPServer::readSocket() will be called.
@ ssWait
The TCPServer has entered waiting for activity or wait timeout.
int getFD() const
Return the socket file descriptor.
bool busy_
If true, the TCPServer is processing a request.
@ ecOK
0 Not an error, success
@ ssReadSocketDone
ssReadSocket completed.
double getSecondDiff(struct timeval &t1, struct timeval &t2)
Return difference in seconds as a double.
std::string debugString() const
Return the object dump to string.
common::SystemError readBuffer(BaseSocket *socket, ssize_t &received)
Reads and appends data to read_buffer.
@ ssReleaseWorkDone
ssReleaseWork completed.
BaseSocket socket and state pair.
void addReceivedSentBytes(ssize_t r, ssize_t s)
Add received bytes.
virtual common::SystemError readSocket(TCPListener::SocketWork &work, ssize_t &sent)=0
Override to perform a request-response cycle.
@ ecECONNABORTED
103 Software caused connection abort
ServerState state_
State of the TCPServer.
Linux system error primitive to provide a consistent interface to Linux error codes.
The TCPListener listens, accepts connections and generates socket events to produce TCP work to a poo...
virtual void shutDown(network::BaseSocket *socket)=0
Override to perform a shutdown.
TCPListener & listener_
The TCPListener the TCPServer is working for.
#define log_Debug(what)
Macro to log Debug.