Share this page

# web_sync

Asynchronous Functions - C

Suspends the Vuser script execution until the specified parameter exists.

    int web_sync ( "ParamCreated=param_name", ["RetryIntervalMs=integer,] ["RetryTimeoutMs=integer,] LAST);

Argument | Description
--- | ---
ParamCreated | The name of a parameter.
RetryIntervalMs | The number of milliseconds to wait before a retry after a test of the condition yielded false. The default is 500. The default can be overridden by the "web_sync retry interval" runtime setting.
RetryTimeoutMs | The maximum number of milliseconds during which retries are allowed. The default is 30000. The default can be overridden by the "web_sync retry timeout" runtime setting. Regardless of the value of this argument or of the "web_sync retry timeout" runtime setting, the timeout never exceeds the value of the "Step download timeout" runtime setting.
LAST | A marker that indicates the end of the argument list.

## Return Values

This function returns LR_PASS (0) if the specified parameter exists, and LR_FAIL (1) if the step times out.

## Parameterization

The values of keyword-value pairs can be parameterized. For example, "ALT={altParam}".

## General Information

The parameter named in the `ParamCreated` argument is expected to be created by a concurrent activity, such as a poll or a push conversation. If the parameter has already been created when the function is invoked, it returns immediately. If not, the script run is suspended until either the parameter is created or the function times out.

## Example

In this example, web_sync is used to suspend the script run until the parameter is created in the call-back routine.

Copy code

    //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;
        }

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: