Class SuperSocket
#include <SuperSocket.h >
Super class: Socket
This class handles the communication layer between a MAE daemon/app and CommHub.
The challenge that this class faces is that CommHub communicates asynchronously with its client daemons/app, so an app may have sent a DB request (for example) and while wating for the DB response, it may receive some messages, an RPC request, or control message (perhaps initiated by the user). So, this class has to remember those messages and then process them after the DB response arrives.
Internally, SuperSocket discerns these logical communication categories:
int outDBs |
count of outbound DB messages |
int outMsgs |
count of outbound msgbroker messages |
int outRPCs |
count of outbound RPC messages |
int outOther |
count of outbound other (non-DB/Msg/Rpc) messages |
int inDBs |
count of inbound DB messages |
int inMsgs |
count of inbound msgbroker messages |
int inRPCs |
count of inbound RPC messages |
int inOther |
count of inbound other (non-DB/Msg/Rpc) messages |
static Timer timer |
Useful timer for performing time triggered activities without interferring with commhub communication. |
string host |
The hostname to connect to (if empty, then localhost) |
int port |
The remote TCP port to connect to |
Prepare for a TCP socket connection
Return value: instance of Socket to open(). If FALSE, check errno().
Construct anempty SuperSocket.
string text |
text to send |
Send text to commhub
Any \n will be converted to text (and later back)
Return value: true upon success, false upon failure
Read any inbound text.
Use its callback (if defined) to process the inbound text.
Return value: socket status (-1 EOF)
bool wait |
block until we have input from commhub Default value: false |
bool rcLineOnly |
wait until we get a response line (starts with + or -) and return that; other lines are queued Default value: false |
Wait for text from commhub.
Read text up to a newline.
Return value: the string read. If empty, check errno().
bool wait |
Default value: false |
bool lockoutCallbacks |
Default value: false |
Wait for DB response.
Read DB response text up to a newline.
Return value: the string read. If empty, check errno().
bool wait |
Set to true to wait until there's valid input, false if just checking quickly Default value: false |
bool queueOk |
Set to true if it's OK to pull queued/pending messages (this is normal/default) Default value: true |
Wait for text message.
Read a Message text up to a newline.
Return value: the string read. If empty, check errno().
bool wait |
Set to true to wait until there's valid input, false if just checking quickly Default value: false |
bool lockoutCallbacks |
Set to prevent other requests from being serviced while waiting Default value: false |
bool queueOk |
Set to true if it's OK to pull queued/pending messages (this is normal/default) Default value: true |
Wait for text message.
Read an RPC text up to a newline.
Return value: the string read. If empty, check errno().
bool includingCommHub |
Default value: true |
Return true if commhub command queue has a command ready to be processed
Return value: true if there's 1+ backlog commands
Return true if DB command queue has a command ready to be processed
Return value: true if there's 1+ backlog commands
Return true if msgbroker message command queue has a command ready to be processed
Return value: true if there's 1+ backlog commands
Return true if RPC command queue has a command ready to be processed
Return value: true if there's 1+ backlog commands
Get size of msg backlog queue
Return value: size of the queue
Get size of db backlog queue
Return value: size of the queue
Get size of rpc backlog queue
Return value: size of the queue
SuperSocketFN cb |
callback function Default value: NULL |
void* data |
callback data Default value: NULL |
Setup the commhub callback
SuperSocketFN cb |
callback function Default value: NULL |
void* data |
callback data Default value: NULL |
Setup the DB callback
SuperSocketFN cb |
callback function Default value: NULL |
void* data |
callback data Default value: NULL |
Setup the msgbroker message callback
SuperSocketFN cb |
callback function Default value: NULL |
void* data |
callback data Default value: NULL |
Setup the RPC request callback
SuperSocketFN cb |
callback function Default value: NULL |
void* data |
callback data Default value: NULL |
Setup the RPC response callback
Get the msgbroker message callback method
Return value: the msgbroker message callback method
string prefix |
the new prefix |
If a different DB prefix hapens, configure new prefix here
string prefix |
the new prefix |
If a different msgbroker message prefix hapens, configure new prefix here
string prefix |
the new prefix |
If a different RPC prefix hapens, configure new prefix here
FILE* tap |
Default value: NULL |
Useful for monitoring all socket communication - a socket tap
will record all read/write activity (set to NULL to disable)
query the tap's pointer
Determine if tap is active
const string& line |
the line from commhub to process |
bool lockoutCallbacks |
true if no callbacks should be called to immediately handle a message Default value: false |
Put line into right queue or send to callback (if not locked out/blocked)
Get # of lines received
static queue <string > commhub |
Queue of backlog commands from commhub |
static queue <string > db |
Queue of backlog commands from dbbroker |
static vector <string > msg |
Queue of backlog commands from msgbroker |
static vector <string > rpc |
Queue of backlog commands from rpcbroker |
SuperSocketFN cbfnCommHub |
Callback method to handle commhub messages |
SuperSocketFN cbfnDB |
Callback method to handle DB responses |
SuperSocketFN cbfnMsg |
Callback method to handle inbound messages from msgbroker |
SuperSocketFN cbfnRpc |
Callback method to handle rpcbroker requests |
SuperSocketFN cbfnRpcResp |
Callback method to handle rpcbroker responese |
void* cbdataCommHub |
Callback data for commhub message callback |
void* cbdataDB |
Callback data for database message callback |
void* cbdataMsg |
Callback data for msgbroker message callback |
void* cbdataRpc |
Callback data for RPC request callback |
void* cbdataRpcResp |
Callback data for RPC response callback |
static string dbPrefix |
Prefix characters of DbBroker commands |
static string msgPrefix |
Prefix characters of MsgBroker commands |
static string rpcPrefix |
Prefix characters of RpcBroker commands |
int count |
The number of characters to read |
Read the specified number of characters from the socket
Return value: the string read. If empty, check errno().
bool wait |
Default value: false |
bool lockoutCallbacks |
Default value: false |
Read text up to a newline.
Return value: true if something read
static Stopwatch time0 |
Time when socket opened |
static FILE* tapf |
if a socket tap is active, this points to the file where text is recorded |
bool send |
true is message is outbound, false if message is inbound |
const string& text |
the message |
Save a message out to tap file