HTTP server stuck in function httpsrv_read() when receiving large data

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HTTP server stuck in function httpsrv_read() when receiving large data

1,112 Views
julie
Contributor I

I have a CW10.6 and MQX4.2 project which runs on K60F120M. I found that when large data(the size is greater than HTTPSRVCFG_RX_BUFFER_SIZE) is uploaded to the HTTP server, sometimes the server is stuck in httpsrv_read() function (in httpsrv_supp.c), the call to httpsrv_recv() returns 0 while (read<len), so the function is stuck forever while waiting for more data.

Here is the code snippet of httpsrv_read:

    /* If there is some space remaining in user buffer try to read from socket */
    while (read < len)
    {
        uint32_t received;

        received = httpsrv_recv(session, dst+read, len-read, 0);
        if ((uint32_t)RTCS_ERROR != received)
        {
            read += received;
        }
        else
        {
            break;
        }
    }

Before digging deeper into the RTCS code, I'd like to know if anybody else had the same problem? And if yes, how to solve it?

Thank you very much for your help,

Julie

Labels (1)
Tags (1)
0 Kudos
Reply
2 Replies

963 Views
Martin_
NXP Employee
NXP Employee

or, actually, maybe the code needs to add a check for zero bytes return value, to return to the caller in case of the receive timeout:

/* If there is some space remaining in user buffer try to read from socket */
    while (read < len)
    {
        uint32_t received;

        received = httpsrv_recv(session, dst+read, len-read, 0);
       
if (received && ((uint32_t)RTCS_ERROR != received))
        {
            read += received;
        }
        else
        {
            break;
        }
    }

0 Kudos
Reply

963 Views
Martin_
NXP Employee
NXP Employee

you might try to increase the OPT_RECEIVE_TIMEOUT session socket option. In case of timeout on the session socket (no incoming data) the recv() function returns with whatever data has been buffered, possibly zero.

HTTPSRVCFG_RECEIVE_TIMEOUT compile time macro, in milliseconds.

0 Kudos
Reply