Hot!HTTPPrint : MLA to Harmony

Page: 12 > Showing page 1 of 2
Author
Emcy
Super Member
  • Total Posts : 562
  • Reward points : 0
  • Joined: 2008/01/09 03:37:06
  • Location: 0
  • Status: offline
2018/06/20 09:07:17 (permalink)
0

HTTPPrint : MLA to Harmony

Hello,
 
For TCPIP_HTTP_NET_DynamicWrite() function, someone know what is "needAck" parameter for ? I don't know when I must set/clear it
 
In a TCPIP_HTTP_Print function, I can call several times TCPIP_HTTP_NET_DynamicWrite or must call it one time ?
ie : can I do it ?

 
 
 
TCPIP_HTTP_DYN_PRINT_RES TCPIP_HTTP_Print_hello_world(TCPIP_HTTP_NET_CONN_HANDLE connHandle, const TCPIP_HTTP_DYN_VAR_DCPT *vDcpt){
 
 
 
   TCPIP_HTTP_NET_DynamicWriteString(vDcpt, "Hello ", false);
 
 
 
   TCPIP_HTTP_NET_DynamicWriteString(vDcpt, "World !", false);
 
 
 
}
 
 
 

 
Thanks
 
post edited by Emcy - 2018/06/21 23:54:16
#1

29 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 5574
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/20 09:21:06 (permalink)
    0
    When I search the harmony dir for
     TCPIP_HTTP_NET_DynamicWriteString
    I see an entry describing the needAck parameter.
    #2
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/20 09:42:19 (permalink)
    0
    And you understand ? ... not me.
    #3
    Jim Nickerson
    User 452
    • Total Posts : 5574
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/20 09:53:18 (permalink)
    0
    Yes I do understand the need for it and how to use it.
    Though the Harmony Documentation is there in great detail it is often quite obtuse.
    Sometimes I find I must try the option and observe the results ( usually when I encounter something I have not seen/used before and I am impatient )
    There are samples that make use of it set both false and true.
     
     
    #4
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/20 13:23:50 (permalink)
    4 (1)
    From the header file explanation for the TCPIP_HTTP_NET_DynamicWrite (the same should be in the documentation, since it's derived from this):
    "The buffer passed in by the user with this call is queued internally using an available dynamic variable buffer descriptor. That means that the buffer has to be persistent. Once the buffer is processed and sent to output, the dynamicAck callback will be called, to inform the user that the corresponding buffer can be reused/freed."
     
    So, it may take a while until that buffer is processed.
    If you've passed in a constant buffer, for example, in ROM/flash, then it does not matter when it's been processed, there's nothing to do about it, so you can pass in "needAck == false".
    However, if you've allocated that buffer dynamically, or you use a pool of buffers which you share among various tasks, etc. you want to know that the buffer is now available to you and you can reuse it.
    I hope that clarifies it a bit.
     
    #5
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/21 00:39:51 (permalink)
    0
    OK, I thank you Smile: Smile
     
    #6
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/21 06:09:47 (permalink)
    0
    With MLA I used curHTTP.callbackPos as state machine to send a large amout of data :

     
     
     
    void HTTPPrint_bigData(void){
        char data[151];
        MAKEJSON_OBJ *jsonObj = curHTTP.data;

        if(curHTTP.callbackPos == 0){
            curHTTP.callbackPos = 1;
            initJson(jsonObj);
        }

        while(TCPIsPutReady(sktHTTP) > 150){
            switch(curHTTP.callbackPos){
                case 1:
                    getStringInfo1(data, jsonObj);
                    TCPPutString(sktHTTP, data);
                    break;

                case 2:
                    getStringInfo2(data, jsonObj);
                    TCPPutString(sktHTTP, data);
                    break;

                case 3:
                    getStringInfo3(data, jsonObj);
                    TCPPutString(sktHTTP, data);
                    break;

                default:
                    getStringInfo4(data, jsonObj);
                    TCPPutString(sktHTTP, data);
                    curHTTP.callbackPos = 0; // exit
                    return;
            }
            curHTTP.callbackPos++;
        }
    }
     

     
    I saw in Harmony I can use TCPIP_HTTP_NET_ConnectionCallbackPosGet() and TCPIP_HTTP_NET_ConnectionCallbackPosSet functions to replace curHTTP.callbackPos but they are legacy.
     
    What is the best practice to do it with Harmony ? Where can I find an exemple ?
     
    Also, I need persistant data during the HTTPPrint process (to jsonObj).
    curHTTP.data doesn't exist in Harmony : how can I do ?
    => can I use buffer returned by TCPIP_HTTP_NET_ConnectionDataBufferGet() ? I can write in this buffer (there is no conflict with cookie and POST ?) ?
    post edited by Emcy - 2018/06/21 08:00:46
    #7
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/21 11:42:05 (permalink)
    0
    The preferred Harmony mechanism is using TCPIP_HTTP_NET_DynPrint() and returning TCPIP_HTTP_DYN_PRINT_RES_PROCESS_AGAIN for as long as you have more data to send.
    Once you're done and print the last dynamic content, simply return TCPIP_HTTP_DYN_PRINT_RES_DONE.
     
    #8
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/21 23:51:28 (permalink)
    0
    Yes but how do you do to replace curHTTP.callbackPos state machine system ? ... You save state machine value in TCPIP_HTTP_NET_ConnectionDataBufferGet() buffer ?
    => problem is that TCPIP_HTTP_NET_ConnectionDataBufferGet() buffer isn't initialized to 0 for the first call of TCPIP_HTTP_Print function.
     
    Could you show me how do you do to change my code for Harmony ?
    post edited by Emcy - 2018/06/21 23:55:40
    #9
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/22 00:25:58 (permalink)
    0
     
    I changed HTTP_APP_GetDynamicBuffer() function but I'm not sure it is the best method :

     
     
     
    typedef struct {
        uint16_t    busy;           // buffer is currently in process
        uint16_t    bufferSize;     // size of the associated buffer
        uint32_t    sm;             // state machine value    
        
        TCPIP_HTTP_NET_CONN_HANDLE connHandle; // Leave this variable just before data to align dat address to void* pointer
        
        // buffer for writing the dynamic variable callback content
        // => address of this variable, must be void* pointer aligned !!!!!
        char        data[HTTP_APP_DYNVAR_BUFFER_SIZE];  
        
    }HTTP_APP_DYNVAR_BUFFER;
     
     
     
     
     
     
     
    // helper to get one of the application's dynamic buffer that are used in the
    // dynamic variables processing
    HTTP_APP_DYNVAR_BUFFER *HTTP_APP_GetDynamicBuffer(TCPIP_HTTP_NET_CONN_HANDLE connHandle){
        
        int ix;
        HTTP_APP_DYNVAR_BUFFER *pDynBuffer;
        HTTP_APP_DYNVAR_BUFFER *pNotUsedBuffer = NULL;

        pDynBuffer = httpDynVarBuffers;
        for(ix = 0; ix < sizeof(httpDynVarBuffers)/sizeof(*httpDynVarBuffers); ++ix, pDynBuffer++)
        {
            if(pDynBuffer->busy == 0){
                pNotUsedBuffer = pDynBuffer;
            } else {
                if(pDynBuffer->connHandle == connHandle){
                    return pDynBuffer;
                }
            }
        }
     
        if(pNotUsedBuffer){    
        if(pNotUsedBuffer->busy == 0){
            pNotUsedBuffer->busy = 1;
     
            pNotUsedBuffer->sm = 0;
     
            return pNotUsedBuffer;
        }
        }
        
        return 0; // No buffer available
    }
     

    post edited by Emcy - 2018/06/24 23:49:54
    #10
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/22 00:48:19 (permalink)
    0
    ... It isn't a good methode because when HTTP process acknowledge buffer, sm value is lost
    #11
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/22 10:20:01 (permalink)
    0
    You could store in your HTTP_APP_DYNVAR_BUFFER 2 other members:
    - the total number of bytes you want to send
    - the current number of bytes sent
    When you send the buffer you update the sent bytes and when you get the callback you know if you need to return AGAIN or DONE.
    You don't need to use the HTTP internal data for this.
    Is this what you want to achieve, sending a large number of bytes, or is it something else?
     
     
    #12
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/25 06:05:38 (permalink)
    0
    Hello,
     
    I'm not sure that I understood : when TCPIP_HTTP_NET_DynAcknowledge() is called, I must clear busy variable only if "the total number of bytes" = "the current number of bytes sent" ?
    But, If the connection is lost during the HTTPPrint process (ie : connection timeout), how must I do to clear the busy variable ?
     
     
    #13
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/25 09:26:58 (permalink)
    0
    What I'm trying to say is that you can use exactly the same logic that you had before with the callbackPos. But maintain your own variables rather than rely on the HTTP to provide storage for you.
    If the connection is lost, I guess the browser will reconnect and ask again for the pages. Not sure what you're trying to achieve here. Please give some more details.
    #14
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/26 01:06:23 (permalink)
    0
    My problem is that I don't see how to detect the first call of a TCPIP_HTTP_Print and the end of the connection or/and TCPIP_HTTP_Print process : it is mandatory to init and to free my variables.
    => I need for TCPIP_HTTP_NET_EventReport() function new event : connection close.
     
    If browser reconnect and ask again for the pages, I new HTTP handle will be open : if my variables aren't freed, I will have a memory overflow.
     
    Can you give me an exemple to manage a callbackPos variable in application code ?
     
    post edited by Emcy - 2018/06/26 05:08:21
    #15
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/26 09:52:37 (permalink)
    0
    I think I understand the situation that you're describing.
    Internally HTTP_NET detects a disconnect (timeout or remote connection closed, for example).
    A new disconnect event could be added to let you know that the corresponding connection is no longer active.
    That would allow you to free any previously allocated resources that are still waiting for processing.
     
    I'll post here an update of http_net file and you can give it a try and let me know if it works for you.
     
     
    #16
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/26 15:32:42 (permalink)
    5 (1)
    Please use the attached files and give it a try (remove the .txt extension).
    Few events have been added:
    TCPIP_HTTP_NET_EVENT_OPEN
    TCPIP_HTTP_NET_EVENT_CLOSE_DONE
    TCPIP_HTTP_NET_EVENT_CLOSE_TIMEOUT
    TCPIP_HTTP_NET_EVENT_CLOSE_POST_ERROR
    TCPIP_HTTP_NET_EVENT_CLOSE_REMOTE.
    Explanations are in the http_net.h but the names should be fairly clear.
    Pending some further validation the changes will be added to the trunk code.
    You should have all the events now to help with properly managing your resources.
    Let us know if any issues with the supplied code.
     
     
    #17
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/26 23:59:32 (permalink)
    0
    I thank you.
    I will test it.
    #18
    Emcy
    Super Member
    • Total Posts : 562
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/27 02:29:07 (permalink)
    0
    I have some doubts : for a connHandle, when you call TCPIP_HTTP_NET_DynamicWrite() in a TCPIP_HTTP_Print() function, is it possible that HTTP_NET call TCPIP_HTTP_Print() function before TCPIP_HTTP_NET_DynAcknowledge() or HTTP_NET wait that Dyn buffer has been acknowledged before recall TCPIP_HTTP_Print() function ?
    #19
    rainad
    Moderator
    • Total Posts : 1041
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_HTTP_NET_DynamicWrite : what is "needAck" parameter for ? 2018/06/27 10:31:45 (permalink)
    0
    If the underlying TCP transport is slow (network problems, etc.) and multiple dynamic buffers are queued with TCPIP_HTTP_NET_DynamicWrite() then I think it's possible to begin the processing of another dynamic variable before all the previous buffers went out and were acknowledged.
    Is this your question?
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5