MqMsgque PACKAGE - the package-main is a single piece of code evaluated only once at application startup … More...
Functions | |
MQ_EXTERN void | MqMain (void *code) |
Main entrypoint - start the application | |
MqMsgque PACKAGE - the package-main is a single piece of code evaluated only once at application startup …
Example from MyServer.c
→ The package-main configure the factory and start the server.
#include "common.h" // service to serve all incoming requests for token "HLWO" static enum MkErrorE MyFirstService ( MQ_SERVICE_CALL_ARGS ) { MqSendSTART_E (mqctx); MqSendV_E (mqctx, "%s World", MqReadSTR_e(mqctx)); error: return MqSendRETURN(mqctx); } // define a service as link between the token "HLWO" and the callback "MyFirstService" static enum MkErrorE ServerSetup ( MQ_SERVICE_CALL_ARGS ) { return MqServiceCreate(mqctx,"HLWO", MyFirstService, NULL, NULL, NULL); } // package-item enum MkErrorE MyServerFactory ( MQ_CALLBACK_FACTORY_CTOR_ARGS ) { MQ_CTX const mqctx = *contextP = MqContextCreate(NULL,tmpl); MqConfigSetServerSetup (mqctx, ServerSetup, NULL, NULL, NULL); return MK_OK; } // package-main int main (int argc, MK_STRN argv[]) { MqRtSetup_NULL; // setup commandline arguments for later use MK_BFL largv = MkBufferListCreateVC(argc, argv); MQ_CTX mqctx = NULL; // create "MyServer" factory… and make it to the default. MqFactoryDefault( MqFactoryAdd_2(MyServerFactory, "MyServer")); // inspect commandline-argument for the "factory" to choose… and create a object MqFactoryNew_E (MqFactoryGetCalledL(largv), NULL, &mqctx); // start listen for incoming call's MqLinkCreate_E (mqctx, largv); MqCheckForLeftOverArguments_E (mqctx, largv); MqProcessEvent_E (mqctx,MQ_WAIT_FOREVER,MK_TIMEOUT_DEFAULT); error: MkBufferListDelete(largv); MqExit_1(mqctx); }
MQ_EXTERN void MqMain | ( | void * | code | ) |
Main entrypoint - start the application
Tcl has a special requirement, for every new server-thread a new interpreter is created and
this interpreter source the toplevel file for initialization. This file is set on library startup and
can be changed with MqInitResetArg0. The problem is the server startup code from the toplevel. For internal
purpose this code should only be executed on application-startup (like the C main function)
and not for every thread again.