Example: web_sync
In this example, web_sync is used to suspend the script run until the parameter is created in the call-back routine.
//Register a polling pattern
web_reg_async_attributes("ID=LongPoll_0",
"URL/IC=http://my_server/cgi-bin/SLEEP_random_TIME.asp?1332922209853",
"Pattern=LongPoll",
"RequestCB=LongPoll_0_RequestCB",
"ResponseBodyBufferCB=LongPoll_0_ResponseBodyBufferCB",
"ResponseCB=LongPoll_0_ResponseCB",
LAST);
//Start the polling pattern
web_url("sleep_random_time.asp",
"URL=http://my_server/cgi-bin/sleep_random_time.asp?1332922209853",
"Resource=0",
"RecContentType=text/html",
"Referer=http://my_server/webgui/polling/xmlhttprequest_long_polling_async_get.html",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
//Start the transaction
lr_start_transaction("long poll");
//Wait for parameter to be created (see below in AsyncCallbacks.c)
web_sync("ParamCreated=ready","RetryIntervalMs=3000","RetryTimeoutMs=120000",LAST);
wait_time = lr_get_transaction_duration("long poll");
lr_end_transaction("long poll", LR_AUTO);
web_stop_async("ID=LongPoll_0",
LAST);
lr_free_parameter("ready");
From AsyncCallbacks.c
//The response call-back is called after each long-polling response is received.
int LongPoll_0_ResponseCB(
const char * aResponseHeadersStr,
int aResponseHeadersLen,
const char * aResponseBodyStr,
int aResponseBodyLen,
int aHttpStatusCode)
{
//enter your implementation for ResponseCB() here
//Increment long-polling response counter
counter++;
lr_output_message("@@@ Long poll response received in [%s] ms", aResponseBodyStr);
//Set parameter value to indicate that 10 long-polling responses were received.
if (counter>10 || (strcmp(aResponseBodyStr,"6000")==0))
lr_save_string("OK","ready");
return WEB_ASYNC_CB_RC_OK;
}

