0

Just now started using C APISolac. But I found that application will be multithread if I am using solac. I have C Application which is single thread and have multiple connections (eg, TCP,UDP, FILE, timerfd) I am polling using epoll. which have dependency on each other. I wanted to use Solac as another connection on epoll. I want to keep my application as single thread cause it have dependencies. Please someone help me if it possible to use Solac connection in single thread.

Regards, Sayed Momeen

  • Do you mean Solace API? https://docs.solace.com/API-Developer-Online-Ref-Documentation/c/index.html – Tarik Sep 03 '18 at 10:29

1 Answers1

0

Having a separate context thread for FD processing and all things internal to the Solace C API is the default behaviour.

This can be changed in various ways, but do read up on "Selecting a Threading Model" and "File Descriptor Management" in https://docs.solace.com/Solace-PubSub-Messaging-APIs/Developer-Guide/C-API-Best-Practices.htm

Assuming that you want to run epoll_wait() yourself and manage the API's FDs, below is a guideline of what is needed. This assumes a single context.

  1. Disable automatic creation of the context thread.

    contextProps[ctxtIndex++] = SOLCLIENT_CONTEXT_PROP_CREATE_THREAD; 
    contextProps[ctxtIndex++] = SOLCLIENT_PROP_DISABLE_VAL;
    
  2. Fill solClient_context_createFuncInfo_t in solClient_context_create() with your own FD management functions:

    • solClient_context_registerFdFunc_t and
    • solClient_context_unregisterFdFunc_t.

    The former is for EPOLL_CTL_ADD/MOD and registering callback function, the latter is for EPOLL_CTL_DEL/MOD. Note:

    • SOLCLIENT_FD_EVENT_ALL ~ EPOLLIN | EPOLLOUT
    • SOLCLIENT_FD_EVENT_READ ~ EPOLLIN
    • SOLCLIENT_FD_EVENT_WRITE ~ EPOLLOUT

    The Solace C API will register its own FD event callbacks through those defined functions.

  3. In your main epoll loop:

    • epoll_wait() with timeout = SOLCLIENT_CONTEXT_PROP_DEFAULT_TIME_RES_MS
    • call solClient_context_timerTick() every epoll_wait() timeout
    • make callbacks to FD events

Look up the Solace C API reference for more details on the symbols stated in this answer: https://docs.solace.com/API-Developer-Online-Ref-Documentation/c/index.html

Wai Leong
  • 328
  • 2
  • 7