Highlighted
Visitor.
730 views

how to run an Asynchronous callback funtion on LR 12.55

I need to run a function defined in a dll file,the code  are as follows.The CreateClient function in Action connect the server and rigister a callback function RECV_DATA_FUNC. Then  DispatchGTP send the request,when the client received the reply ,callbakc function RECV_DATA_FUNC called.But now when RECV_DATA_FUNC  called ,LR must corruption.

void RECV_DATA_FUNC(int AccessID,const char* pBuffer,int buflen)
{
    lr_log_message("recieved reply");
}
Action()
{
    int count=10;
    lr_load_dll("CSDK.dll");
    CreateClient("127.0.0.1", "6666", "121212", "121212", "UserCert.der", RECV_DATA_FUNC);
    sleep(5000);
    while(count>0)
    {
        DispatchGTP("121212", "GTP1.0","T410","M30","a");
        sleep(1000);
        count--;
    }
    
}

 

0 Likes
5 Replies
Highlighted
Honored Contributor.
Honored Contributor.

Re: how to run an Asynchronous callback funtion on LR 12.55

Hello

I"m not sure i undertsand "LR must corruption" 

Do you mean that you want to stop the replay  ?   

If yes , you can call : 

  lr_exit(LR_EXIT_VUSER, LR_FAIL);

 

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: how to run an Asynchronous callback funtion on LR 12.55

A number of issues might play a role:

1. The call interface of your DLL, but when it is a C/C++ DLL is should be OK.

2. You cannot use a LR-based function as a call back.

3. You cannot call LR-functions from a call back.

It will esp. be an issue when the call back function runs on another thread than the main thread. I know from LR with Java that you can create multiple threads, but are not allowed to call LR methods from those self created threads. The execution of LR C-code is single threaded. I guess that you run into a reentrant issue.

You might try to to see if it works when you remove the lr_log_message() in the callback.

A solution that I used with Java is to put all messages of the extra threads on a concurrent queue and had my main loop (that was allowed to call lr-methods) read from the queue and performed the logging.

When your callback works without a lr-function call, you might try to write something in a buffer and read that buffer in your main loop. You have to think about synchronization. It might be possible to define voilatile variable. You can assume that writing an int/long is atomic.

Success, Erik

Signature:
Reward community members who take time to respond and help.
0 Likes
Highlighted
Visitor.

Re: how to run an Asynchronous callback funtion on LR 12.55

Thank you very much for your help.The call interfaces(CreateClient & DispatchGTP) are C/C++ interfaces.The request process works well ,the server can receive my request.Corruption occurred when RECV_DATA_FUNC was called(if replace RECV_DATA_FUNC with NULL in CreateClient,the program works well).I have tried romove lr_log_message() in RECV_DATA_FUNC ,but the problem still exists.
0 Likes
Highlighted
Visitor.

Re: how to run an Asynchronous callback funtion on LR 12.55

Thank you for your reply.You can see my comments below.

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: how to run an Asynchronous callback funtion on LR 12.55

So it looks like that LR cannot handle functions as callbacks from a DLL. Is there a possibility to retrieve the response via a waited or poll call i.s.o. a call back?

You seems to use only lr-functions and utilize the DLL for network communication. Do you have access to a Java based API? You might use that API with LR Java script. I know that this works, in our group we developed our own protocol that way.

Signature:
Reward community members who take time to respond and help.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.