lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Receiving data with lwip raw API


From: Giuseppe Modugno
Subject: [lwip-users] Receiving data with lwip raw API
Date: Wed, 15 Nov 2017 10:43:05 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

I'm sorry if this question is very basic. I think this is discussed before, but I couldn't find the answer to my question.

I understood the receiving pattern at the application level could be very different from "data chunks" you would like to receive. For example, if I want to receive the string "Hello world", I have to consider receiving one pbuf ("Hello world"), one 2-pbuf-chain ("Hello "->"world") or two different pbufs by two call to the callback (first pbuf "Hello ", secondo pbuf "world").

I know it is realistically impossible with small chunks of data, however the receving handler should be robust and face the situation of split data.

So the question is: what is the best method to receive data that could be split in more pbufs, so they are stored in non-contiguous areas of memory? During parse I usually use strcmp/memcmp or similar functions, but they doesn't work with split data.

The solution I found is to copy every received pbuf payload to an application buffer and use strcmp/memcmp/... against this buffer. Is it correct? In this way, after copying the pbuf can be immediately freed with pbuf_free(). There's no reason to save the pbuf for later use.

I tried to study httpd code and it's not clear to me. If LWIP_HTTPD_SUPPORT_REQUESTLIST is defined, code that supports receving data in multiple pbufs is enabled. In http_parse_request() all received pbuf are enqueued in a pbuf chain and pbuf_ref() is called to avoid freeing the pbuf. The content of pbuf chain is copied to a static buffer httpd_req_buf and the parsing is made on this (so avoiding the problem of data splitted over more pbufs). If the received data is complete, all the pbuf is freed.

I don't understand why saving all the received pbufs until all data are received. Why don't copy all pbus payload, as they arrive, to a buffer associated to the connection (in struct http_state)? In this way the received pbufs can be always freed.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]