Is it possible to process POST messages that exceed the packet pool size?

yoji sato 281 Reputation points
2022-02-07T10:35:19.797+00:00

When using the HTTP server function of NetXduo, is it possible to receive and process POST messages
that exceed the size of the packet pool registered by nx_packet_pool_create()?

If it is possible, could you please introduce a sample of how to do so?

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
330 questions
{count} votes

Accepted answer
  1. Tiejun Zhou 1,126 Reputation points Microsoft Employee
    2022-02-10T03:31:13.757+00:00

    It is possible to receive and process POST messages that exceeds the size of packet payload. Here is a piece of sample to show how to process post data.

    #define BUFFER_SIZE 10240
    UCHAR      buffer[BUFFER_SIZE];
    static UINT server_request_callback(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr)
    {
    ULONG      offset;
    ULONG      length = 0;
    UINT       i = 0, actual_size;
    UINT       status;
    
        if(request_type == NX_WEB_HTTP_SERVER_POST_REQUEST)
        {
    
            nx_web_http_server_content_length_get(packet_ptr, &length);
            if (length > sizeof(buffer))
            {
                error_counter++;
                return(NX_SUCCESS);
            }
    
            offset = 0;
    
            while (offset < length)
            {
                status = nx_web_http_server_content_get_extended(server_ptr, packet_ptr, total_length + offset, &buffer[offset], sizeof(pkt) - offset, &actual_size);
                offset += actual_size;
    
                if (actual_size == 0)
                {
                    break;
                }
            }
    
            if (offset != length)
            {
                error_counter++;
                return(NX_SUCCESS);
            }
    
            /* Generate HTTP header.  */
            status = nx_web_http_server_callback_response_send_extended(server_ptr, NX_WEB_HTTP_STATUS_OK, sizeof(NX_WEB_HTTP_STATUS_OK) - 1, 
                                                                        "hello", 5, NX_NULL, 0);
            if(status)
            {
                error_counter++;
            }
        }
        else
        {
            return(NX_SUCCESS);
        }
    
        return(NX_WEB_HTTP_CALLBACK_COMPLETED);
    }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful