Bredbandskollen CLI  1.2
Asynchronous network task engine
Public Member Functions | Static Public Member Functions | List of all members
Engine Class Reference

The network engine. More...

#include <engine.h>

Inheritance diagram for Engine:
Inheritance graph
[legend]
Collaboration diagram for Engine:
Collaboration graph
[legend]

Public Member Functions

bool addClient (SocketConnection *conn)
 
void addConnected (SocketConnection *conn)
 
bool addServer (ServerSocket *conn)
 
 Engine (std::string label)
 
 ~Engine ()
 Will kill all remaining connections.
 
void terminate (unsigned int max_time_ms)
 
void childProcessCloseSockets ()
 Call this in child process to close all redundant sockets after fork.
 
bool run (double max_time)
 Run the "event loop" for at most max_time seconds. More...
 
void deleteConnByTask (const Task *task)
 Remove all connections owned by the task.
 
std::set< Socket * > findSockByTask (const Task *t) const
 
void wakeUpByTask (Task *t)
 Wake up all idle connections belonging to t:
 
bool wakeUpConnection (SocketConnection *s)
 Wake up connection s if it is idle, return false otherwise.
 
void cancelConnection (SocketConnection *s)
 
bool connActive (const Socket *conn) const
 
void resetDeadline (const TimePoint &t)
 Call this to make the Engine::run method return earlier.
 
bool setCABundle (const std::string &path)
 Set path to file containing chain of trust for SSL certificate.
 
bool tlsSetKey (ServerSocket *conn, const std::string &crt_path, const std::string &key_path, const std::string &password)
 Use SSL certificate for a listening socket.
 
- Public Member Functions inherited from Logger
 Logger (std::string label)
 
std::string label () const
 Return the object's log label.
 
void resetLabel (const std::string &new_label)
 Modify the object's log label.
 

Static Public Member Functions

static void yield ()
 Call this to make the Engine::run method return prematurely.
 
static void notifyOutOfFds ()
 Call this to enter a recovery mode if no more file descriptors could be created.
 
- Static Public Member Functions inherited from Logger
static void setLogFile (std::ostream &stream)
 Set global log destination. More...
 
static void reopenLogFile (const std::string &filename)
 If current log is a file (ofstream), reopen it with new filename:
 
static void setLogLimit (unsigned int loglines=0, unsigned int warnlines=0, unsigned int errlines=0)
 Set max number of lines of info/warn/err log. More...
 
static void sayTime (std::ostream &stream)
 Write current local time to the given stream.
 
static bool inError ()
 Return true if any error has been logged (globally since start)
 
static std::ostream & err_log (const std::string &label)
 Write a line of error log. More...
 
static std::ostream & warn_log (const std::string &label)
 Write a line of warning log. More...
 
static std::ostream & log (const std::string &label)
 Write a line of info log. More...
 
static void flushLogFile ()
 
static void pauseLogging ()
 Disable all log output until next call to Logger::setLogFile.
 
static double secondsSince (const TimePoint &t)
 
static double secondsTo (const TimePoint &t)
 
static int64_t msSince (const TimePoint &t)
 
static int64_t msTo (const TimePoint &t)
 
static bool hasExpired (const TimePoint &t)
 Return true if current time is after the given TimePoint.
 
static TimePoint timeNow ()
 Return current time.
 
static TimePoint timeAfter (double s)
 Return current time plus s seconds.
 
static TimePoint timeMax ()
 Return a very distant time.
 
static std::chrono::microseconds toUs (double t)
 Convert s (seconds) to std::chrono::microseconds.
 
static std::string dateString (time_t t=0)
 Return local time, formatted as 2023-10-14T09:38:47+0200.
 
static std::string dateString2 (time_t t=0)
 Return local time, formatted as Sat, 14 Oct 2023 09:38:47.
 
static std::string createHashKey (unsigned int length=20)
 Return a random string. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Logger
std::ostream & errno_log () const
 Write a line of error log after a failed system call has set the global errno to a non-zero value. More...
 
std::ostream & err_log () const
 Write a line of error log. More...
 
std::ostream & warn_log () const
 Write a line of warning log. More...
 
std::ostream & log () const
 Write a line of info log. More...
 
std::ostream & dbg_log () const
 Write a line of debug log. More...
 

Detailed Description

The network engine.

Cannot be used directly. Will be managed by the EventLoop class.

Member Function Documentation

◆ connActive()

bool Engine::connActive ( const Socket conn) const
inline

Return true if connection still exists. Note! We cannot use conn if it has been deleted!

◆ run()

bool Engine::run ( double  max_time)

Run the "event loop" for at most max_time seconds.

Will return when all connections have been closed, when a fatal error has occurred, or when max_time has passed. Return value is false on fatal error, otherwise true. You should call this function repetedly until you're done.

Don't set max_time > 2000 on 32-bit platforms.

◆ terminate()

void Engine::terminate ( unsigned int  max_time_ms)

Close all connections, giving them at most max_time_ms milliseconds to finish what's already written to them.


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