eclipse-threadx / netxduo

Eclipse ThreadX - NetXDuo is an advanced, industrial-grade TCP/IP network stack designed specifically for deeply embedded real-time and IoT applications
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/index.md
MIT License
230 stars 131 forks source link

regression test netxduo/test/regression/web_test/netx_web_external_server_test.c only downloads 1 packet #219

Closed Alec-Davis-NZ closed 6 months ago

Alec-Davis-NZ commented 6 months ago

Describe the bug Reviewing netx_web_external_server_test.c it will only download the 1st packet of 1536 bytes

using httpbin.org you are able to define the number of bytes to downlaod so the example below requests 4096 bytes and when downloaded shows 4096 bytes were downloaded.

The download loop used in this example was adapted from nx_azure_iot_adu_agent_http_response_receive()

However some variable names are STM32CubeIDE names sorry.

...
#define HTTP_SERVER_ADDRESS  IP_ADDRESS(3,95,102,170)/* httpbin.org */
#define HOST_NAME "httpbin.org"
...

void download_test_3( void ) {
//  from netxduo/test/regression/web_test/netx_web_external_server_test.c

    UINT            i;
    UINT            status;
    NX_PACKET       *recv_packet;

    NX_PACKET  *data_packet;
    UINT        data_size;

    ULONG       total_bytes = 0;

    /* Set server IP address.  */
    server_ip_address.nxd_ip_address.v4 = HTTP_SERVER_ADDRESS;
    server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;

    /* First loop test HTTP, second loop test HTTPS.  */
//    for (i = 0; i < loop ; i++)
    for (i = 1; i < loop ; i++)  //Only do HTTPS
    {

        /* Create an HTTP client instance.  */
        status = nx_web_http_client_create(&WebHttpClient, "HTTP Client", &NetXDuoEthIpInstance, &NxAppPool, 1536);

        /* Check status.  */
        if (status)
            error_counter++;

        /* Send a GET request.  */
        if (i == 0)
        {
            status = nx_web_http_client_get_start(&WebHttpClient, &server_ip_address,
                                                  NX_WEB_HTTP_SERVER_PORT, "/bytes/4096",
                                                  HOST_NAME,
                                                  NX_NULL, NX_NULL, NX_WAIT_FOREVER);
        }
#ifdef NX_WEB_HTTPS_ENABLE
        else
        {
            status = nx_web_http_client_get_secure_start(&WebHttpClient, &server_ip_address,
                                                         NX_WEB_HTTPS_SERVER_PORT, "/bytes/4096",
                                                         HOST_NAME, NX_NULL, NX_NULL,
                                                         tls_setup_callback, NX_WAIT_FOREVER);
        }
#endif /* NX_WEB_HTTPS_ENABLE  */

        /* Check status.  */
        if (status)
            error_counter++;

        status = NX_SUCCESS;
        while (status != NX_WEB_HTTP_GET_DONE)
        {

            /* Get response from server.  */
            status = nx_web_http_client_response_body_get(&WebHttpClient, &recv_packet, 1 * NX_IP_PERIODIC_RATE);
            if ( (NX_SUCCESS == status) || (NX_WEB_HTTP_GET_DONE == status) || (status == NX_WEB_HTTP_STATUS_CODE_PARTIAL_CONTENT) )
            {

                /* Loop to write the data from packet into flash.  */
                data_packet = recv_packet;

#ifndef NX_DISABLE_PACKET_CHAIN
                while( data_packet ){
#endif /* NX_DISABLE_PACKET_CHAIN  */

                    /* Calculate the data size in current packet.  */
                    data_size = (UINT)(data_packet -> nx_packet_append_ptr - data_packet -> nx_packet_prepend_ptr);
                    /* Update received firmware size.  */
                    total_bytes += data_size;

#ifndef NX_DISABLE_PACKET_CHAIN
                    data_packet = data_packet -> nx_packet_next;
                }
#endif /* NX_DISABLE_PACKET_CHAIN  */
                nx_packet_release(recv_packet);
            }
            else
            {
                break;
            }

        }

        /* Check status.  */
        if (recv_packet)
            nx_packet_release(recv_packet);

        status = nx_web_http_client_delete(&WebHttpClient);
        if (status)
            error_counter++;
    }

    if(error_counter)
    {
        printf("ERROR!\n");
    }
    else
    {
        printf("SUCCESS! Total Bytes [ %lu ]\n", total_bytes);
    }

}
wenhui-xie commented 6 months ago

Sorry @Alec-Davis-NZ, this test case is only my local test which was pushed to GitHub by mistake. I'll delete it. And you can refer to nx_azure_iot_adu_agent_http_response_receive().

bo-ms commented 6 months ago

Closing