MqConfig... or by using command-line arguments.PATH and additional arguments like a script name or required startup options. The startup-prefix is used for two different purpose:
struct MqBufferLS * init = MqInitCreate(); MqBufferLAppendC(init, "myExecutable"); MqBufferLAppendC(init, "myFirstArgument");
MQ_INT, get: MqConfigGetBuffersize (ctx) , set: MqConfigSetBuffersize (ctx, buffersize)The send and receive buffersize in bytes (default: 4KB)
MQ_INT, get: MqConfigGetDebug (ctx) , set: MqConfigSetDebug (ctx, debug)Debug a message-queue application. Valid values are 0 <= NUM <= 9 using 0 for "no debugging" and 9 for "maximum debugging". (default: 0)
MQ_TIME_T, get: MqConfigGetTimeout (ctx) , set: MqConfigSetTimeout (ctx, timeout)User defined timeout used for connection setup and data sending (default: 90 seconds)
MQ_CST, get: MqConfigGetName (ctx) , set: MqConfigSetName (ctx. name)Use STRING as basename of the new message-queue object. The name shows up in the debugging output and is used as prefix for the new created command. (default: the name of the executable)
MQ_CST, get: MqConfigGetSrvName (ctx) , set: MqConfigSetSrvName (ctx, srvName)Use STRING as a client specific prefix in the server debugging output. This is used to link debugging and error messages on the server to a specific client connection. (default: empty)
MQ_BOL, get: MqConfigGetIsSilent (ctx) , set: MqConfigSetIsSilent (ctx, isSilent)Write (MQ_NO) or don't write (MQ_YES) any output to stdout or stderr. (default: write to stdout or stderr)
MQ_BOL, get: MqConfigGetIsString (ctx) , set: MqConfigSetIsString (ctx, isString)Use (MQ_YES), as much as possible, strings in the data-package. Convert any native data-type, like integer or double, into a string (sending) and back to native (receiving). (default: use binary)
enum MqStartE, get: MqConfigGetStartAs (ctx) , set: MqConfigSetStartAs (ctx, startASStart a new server as thread or spawn a new process or fork a new process. This arguments are used with:
| [in] | startAs | 0=default, 1=fork, 2=thread and 3=spawn |
MQ_CST, get: NO , set: MqConfigSetDaemon (ctx, pidfile)Close all default IO (e.g stdout, stdin, stderr) and fork the server into the background. (default: no daemon)
| [in] | pidfile | the name of the file to write the PID into |
MQ_CST, get: MqConfigGetIoTcpHost/Port/MyHost/MyPort , set: MqConfigSetIoTcp (ctx,host,port,myhost,myport)Configure a tcp socket link.
| host | client: name of the remote host (default: localhost) server: name of the local interface (default: listen on all interfaces) | |
| port | client: name of the remote port server: name of the local port | |
| myhost | client: name of the local interface | |
| myport | client: name of the local port |
MQ_CST, get: MqConfigGetIoUdsFile , set: MqConfigSetIoUds (ctx, file)Use a uds (http://en.wikipedia.org/wiki/Unix_domain_socket) socket link. The uds communication is usually 50% faster than a local tcp communication but only available on UNIX.
| [in] | file | the name of the uds file |
MQ_SOCK, get: MqConfigGetIoPipeSocket , set: MqConfigSetIoPipe (ctx, socket)Start a pipe server to listen on socket. This is the default mode to start a server. The socket option is special because it is used for internal purpose to submit the socket from the client to the server started as pipe by the client.
| [in] | socket | the file-descriptor number. The only public usage for this option is to serve as interface for an existing tool like (x)inetd. The (x)inetd tool is a UNIX service to listen on a tcp/ip port and start for every connection the proper entry from the file /etc/(x)inetd.conf with the file-descriptor 0 as send/recv socket handle. |
MqC, get: MqConfigGetMaster (ctx) , set: SLAVE OBJECTreturn the master if ctx is a slave-context or NULL if ctx is not a slave-context. !Only a SLAVE has a master!
MQ_SIZE, get: MqConfigGetCtxId (ctx) , set: NO
return an identifier as integer and is unique per parent-context. The parent-context is always 0 and every new child-context get a new identifier by adding 1.
MQ_CST, get: MqConfigGetToken (ctx) , set: NOreturn the current TOKEN IDENTIFIER and is only useful in a service callback. This command is needed on the server to implement a generic service (A MqServiceCreate(ctx,token,fService,data,fFree) with different TOKEN IDENTIFIER but with the same service callback).
MQ_BOL, get: MqConfigGetIsConnected (ctx) , set: NOIs the libmsgque context connected ? A context is connected if the MqLinkCreate (ctx, args) command was successful and a context is NOT connected if a) the object has just been created or b) the link was deleted with MqLinkDelete(ctx)
MQ_BOL, get: MqConfigGetIsServer (ctx) , set: IServerSetup or IServerCleanupTrue if object is a server object (default: MQ_NO, be a client)
MQ_BOL, get: MqConfigGetIsParent (ctx) , set: NOTrue if object is a parent object (default: MQ_YES, be a parent)
MQ_BOL, get: MqConfigGetIsSlave (ctx) , set: NOTrue if object is a slave object (default: MQ_NO, not be a slave)
Interface, get: NO , set: MqConfigSetServerSetup (ctx, fFunc, data, fFree, fCopy)Interface to define a server libmsgque object. This Interface define the ServerSetup callback called at MqLinkCreate (ctx, args) to define the services or to initialize context specific variables. This interface set the isServer configuration value to MQ_YES.
Interface, get: NO , set: MqConfigSetServerCleanup (ctx, fFunc, data, fFree, fCopy)Interface to define a server libmsgque object. This Interface define the ServerCleanup callback called at MqLinkDelete(ctx) to free context specific variables. This interface set the isServer configuration value to MQ_YES.
Interface, get: NO , set: MqConfigSetFilterFTR (ctx, fFunc, data, fFree, fCopy)Interface required to define a filter data stream object. This Interface define the IFilterFTR callback. The callback is used to act on filter data rows. Every filter input data is a list of filter data rows and every row is a list of filter data columns. Every row is send from one filter-command to the following filter-command as FTR service request. This interface set the isServer configuration value to MQ_YES. (read more at: FILTER MODE)
Interface, get: NO , set: MqConfigSetFilterEOF (ctx, fFunc, data, fFree, fCopy)Interface required to define a filter data stream object. This Interface define the IFilterEOF callback. The callback is used to act on End-Of-Filter data and is called after all IFilterFTR data was send. Sometimes the filter data can not be served as IFilterFTR data (example: sorting of the input rows need to read all rows before the data can be send to the next filter command) and the IFilterEOF callback is used to continue send IFilterFTR data rows. This interface set the isServer configuration value to MQ_YES. (read more at: FILTER MODE)
Interface, get: NO , set: MqConfigSetFactory (ctx, fCreate, cData, fcFree, fcCopy, fDelete, dData, fdFree, fdCopy)The factory pattern is used to create a new application object (read more at: MqSetupS::Factory) Without the Factory pattern only the initial startup context is available to serve incoming requests. In general every server need to provide a Factory pattern.
Interface, get: NO , set: MqConfigSetBgError (ctx, fCreate, Data, fFree, fCopy)Define an asyncrone error handler. This handler is used for handle errors send with MqSendERROR(ctx). Use MQ_INT MqErrorGetNum(ctx) and MQ_CST MqErrorGetText(ctx) to access the error.
| [in] | ctx | the object from OBJECT CREATION AND DELETION |
| [in] | args | command-line arguments including the "@" item for the --pipe setup |
| [in] | ctx | the object from OBJECT CREATION AND DELETION |
| [in] | parent | the parent object |
| [in] | args | all command-line arguments including the "@" token |
enum MqErrorE ServerSetup(struct MqS * msgque) { MqErrorCheck(MqServiceCreate(msgque, "SRV1", SRV1, NULL, NULL)); return MQ_OK; error: return MqErrorStack(msgque->error); }
The callback is implemented as a set of functions and data suitable for MqCallbackS.
| [in] | timeout | don't wait more than TIMEOUT seconds to get an answer from the server. If no answer is available an error is raised. (default: command-line: --timeout) |
| [in] | MQ_WAIT | use flag value to define the action (default: NO)
|
SendSTART(ctx); MqSendI(ctx,num); MqSendL_START(ctx); MqSendD(ctx,balance); MqSendC(ctx,"name of the owner"); MqSendB(ctx,signature); MqSendL_END(ctx); MqErrorCheck(MqSendEND_AND_WAIT(ctx,"SRV1",MQ_TIMEOUT_USER))
MqErrorCheck(MqReadI(ctx, &i)); MqErrorCheck(MqReadL_START(ctx, NULL)); MqErrorCheck(MqReadD(ctx, &balance)); MqErrorCheck(MqReadC(ctx, &owner)); MqErrorCheck(MqReadB(ctx, &signature)); MqReadL_END(ctx);
| [in] | ctx | the master libmsgque object as SERVER-PARENT without a CHILD |
| [in] | id | an integer used as unique identifer for the master/slave link |
| [in] | args | command-line arguments passed to the worker-client or the worker-server. all arguments prior the first @ token are added to the worker-client and the other arguments to the worker-server. |
MqErrorCheck(MqSlaveWorker (ctx, 7, MqBufferLCreateArgsV(ctx, "--thread", "--silent", "@", "--name", "MyWorker", NULL) );
| [in] | ctx | the master libmsgque object as PARENT without a CHILD |
| [in] | id | an integer used as unique identifer for the master/slave link |
| [in] | slave | the slave libmsgque object as CLIENT-PARENT without a CHILD |
Y : 1 byte signed characterO : 1 byte boolean character using MQ_YES for yes or true or MQ_NO for no or wrongS : 2 byte signed shortI : 4 byte signed integerW : 8 byte signed long long integerF : 4 byte floatD : 8 byte doubleB : unsigned char array used for binary dataC : string data using a \0 at the endL : list type able to hold a list of all items from aboveU : typeless buffer able to hold a single item from above
if (MqErrorCheckI(MqReadI(ctx, &i))) { printf(MqErrorGetText(ctx)); }
command1 | command2 | command3
msgcmd1 @ msgcmd2 @ msgcmd3
#include "string.h" #include "msgque.h" static enum MqErrorE MMUL( struct MqS *ctx, MQ_PTR data) { MQ_DBL d1,d2; MqErrorCheck (MqSendSTART(ctx)); MqErrorCheck (MqReadD(ctx, &d1)); MqErrorCheck (MqReadD(ctx, &d2)); MqErrorCheck (MqSendD(ctx, d1*d2)); error: return MqSendRETURN(ctx); } static enum MqErrorE ServerSetup (struct MqS *ctx, MQ_PTR data) { return MqServiceCreate(ctx,"MMUL", MMUL, NULL, NULL); } int main (int argc, MQ_CST argv[]) { struct MqBufferLS * largv = MqBufferLCreateArgs(argc, argv); struct MqS * ctx = MqContextCreate(0, NULL); MqConfigSetName (ctx, "MyMulServer"); MqConfigSetServerSetup (ctx, ServerSetup, NULL, NULL, NULL); MqConfigSetDefaultFactory (ctx); MqErrorCheck (MqLinkCreate (ctx, &largv)); MqErrorCheck (MqCheckForLeftOverArguments(ctx, &largv)); MqErrorCheck (MqProcessEvent(ctx,MQ_TIMEOUT,MQ_WAIT_FOREVER)); error: MqExit(ctx); }
> mulserver --tcp --port 7777 --thread
#include "string.h" #include "msgque.h" int main (int argc, MQ_CST argv[]) { struct MqBufferLS * largv = MqBufferLCreateArgs(argc, argv); struct MqS * ctx = MqContextCreate(0, NULL); MQ_DBL d; MqConfigSetName (ctx, "MyMul"); MqErrorCheck (MqLinkCreate (ctx, &largv)); MqErrorCheck (MqCheckForLeftOverArguments(ctx, &largv)); MqSendSTART(ctx); MqSendD(ctx,3.67); MqSendD(ctx,22.3); MqSendEND_AND_WAIT(ctx, "MMUL", 10); MqErrorCheck (MqReadD(ctx, &d)); printf("%f\n", d); error: MqExit(ctx); }
> mulclient --tcp --port 7777
#include "string.h" #include "msgque.h" static enum MqErrorE FTR( struct MqS *ctx, MQ_PTR data) { MQ_CST str; MqSendSTART(ctx); while (MqReadItemExists(ctx)) { MqErrorCheck (MqReadC(ctx, &str)); MqBufferSetV(ctx->temp,"<%s>", str); MqSendU(ctx, ctx->temp); } return MqSendFTR(ctx, 10); error: return MqErrorStack (ctx); } int main (int argc, MQ_CST argv[]) { struct MqBufferLS * largv = MqBufferLCreateArgs(argc, argv); struct MqS * ctx = MqContextCreate(0, NULL); MqConfigSetName (ctx, "ManFilter"); MqConfigSetFilterFTR (ctx, FTR, NULL, NULL, NULL); MqErrorCheck (MqLinkCreate (ctx, &largv)); MqErrorCheck (MqCheckForLeftOverArguments(ctx, &largv)); MqErrorCheck (MqProcessEvent(ctx,MQ_TIMEOUT,MQ_WAIT_FOREVER)); error: MqExit(ctx); }
> echo -e "1:2:3\na:b:c" | atool split -d : @ manfilter @ atool join -d :
1.5.8