WSWaitForLinkActivityWithCallback (C Function)

int WSWaitForLinkActivityWithCallback(WSLINK l, WSLinkWaitCallBackObject callback)

does not return until the WSTP connection specified by l has data to read, but periodically calls back to the function passed as callback.

Details

  • Use WSWaitForLinkActivityWithCallback() on a background thread that needs to wait for data in order not to block any user interface or main threads of the application.
  • Use WSWaitForLinkActivityWithCallback() (or the related function WSWaitForLinkActivity()) when needing to wait for link activity on a link that is enabled for logging.
  • WSWaitForLinkActivityWithCallback() returns WSWAITERROR in the event of an error and WSWAITSUCCESS if the function succeeds.
  • WSLinkWaitCallBackObject is a pointer to a function of the form int function(WSLINK, void *). The second argument is reserved for future use. If the function returns 1, WSWaitForLinkActivityWithCallback() will return WSWAITCALLBACKABORTED.
  • MWaitForLinkActivityWithCallback() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (1)

#include "wstp.h"

/* A function for WSTP to call back to while waiting */
int WaitFunction(WSLINK l, void *future)
{
    /* By default do not back out of
        WSWaitForLinkActivityWithCallback(). */
    return 0;
}


/* A function for waiting for link activity */

void f(WSLINK l)
{
    switch(WSWaitForLinkActivityWithCallBack(l, WaitFunction))
    {
        case WSWAITERROR:
            /* Handle the error */
            break;
        case WSWAITSUCCESS:
            /* Now read incoming data */
            break;
        case WSWAITCALLBACKABORTED:
        default:
            /* WaitFunction decided to abort the wait. */
    }
}