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

 

  • 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);

     

  • 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

  • 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.
  • Thank you for your reply.You can see my comments below.

  • 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.