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

Client communicating with an agent task using a UnixDomainBridge. More...

#include <unixdomainclient.h>

Public Member Functions

 UnixDomainClient (int peer_fd)
 Create client using one of a pair of Unix domain sockets.
 
std::string pollAgent ()
 Return a line of data from the agent. More...
 
std::string waitForMsgFromAgent (unsigned long timeout_us=0)
 
void pushToAgent (const std::string &msg)
 Send message to agent. More...
 
bool flushToAgent ()
 If there is unsent data, retry sending it to the agent. More...
 

Detailed Description

Client communicating with an agent task using a UnixDomainBridge.

This class is meant to be used only outside the event loop, i.e. from some other thread or process. It is used together with a UnixDomainBridge, which runs in the event loop. After creating the UnixDomainBridge object, call getClientSocket() on it to get a file descriptor which should be used as an argument to the constructor of this class. Then make sure the UnixDomainBridge object runs in an event loop, but not in the same thread or process as this class.

Member Function Documentation

◆ flushToAgent()

bool UnixDomainClient::flushToAgent ( )

If there is unsent data, retry sending it to the agent.

Return true if agent has received all messages we sent.

If the return value is false, you must call flushToAgent again at a later time (e.g. after 50ms, or preferably when the socket is found to be writable.)

◆ pollAgent()

std::string UnixDomainClient::pollAgent ( )

Return a line of data from the agent.

Will return an empty string if no message is available.

Poll regularly or monitor the socket descriptor.

◆ pushToAgent()

void UnixDomainClient::pushToAgent ( const std::string &  msg)

Send message to agent.

Note: If the message is large (perhaps >200KB), it's likely that the complete message can't be delivered to the agent immediately. In that case, it will be buffered and you may have to call pushToAgent (with new messages) or flushToAgent() repeatedly until the buffer is drained. (Of course, unless the agent actively reads the messages, the buffer can't be drained.)

◆ waitForMsgFromAgent()

std::string UnixDomainClient::waitForMsgFromAgent ( unsigned long  timeout_us = 0)

As UnixDomainClient::pollAgent, but block until a message is available or until timeout_us microseconds have passed (or forever, if timeout_us is 0).


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