lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Dealloc in fs_close_custom()?


From: Giuseppe Modugno
Subject: Re: [lwip-users] Dealloc in fs_close_custom()?
Date: Mon, 26 Feb 2018 22:59:25 +0100

2018-02-26 19:45 GMT+01:00 address@hidden <address@hidden>:
On 26.02.2018 16:51, Giuseppe Modugno wrote:
I read the examples in lwip-contrib, mainly genfiles_example.c. The
dynamic memory allocated for the file content is freed in
fs_close_custom(). However I couldn't explain why.

Indeed, mostly if the content is small, it is completely sent in
http_recv()/http_send()/http_eof()/http_close_conn()/http_close_or_abort_conn()/http_state_free()/fs_close()/fs_close_custom().

tcp_write() is called in http_write() without TCP_WRITE_FLAG_COPY, at
least it seems so to me.

That's not fully correct. The default behaviour is that data is copied for dynamic files (where buf != NULL). This should cover SSI files as well as custom files, but it could be that it doesn't cover your setup of custom files.

You either can adjust the macro HTTP_IS_DATA_VOLATILE() in that case, or come up with a patch that would keep the file open until everything is ACKed.

#ifndef HTTP_IS_DATA_VOLATILE
#if LWIP_HTTPD_SSI
/* Copy for SSI files, no copy for non-SSI files */
#define HTTP_IS_DATA_VOLATILE(hs)   ((hs)->ssi ? TCP_WRITE_FLAG_COPY : 0)
#else /* LWIP_HTTPD_SSI */
/** Default: don't copy if the data is sent from file-system directly */
#define HTTP_IS_DATA_VOLATILE(hs) (((hs->file != NULL) && (hs->handle != NULL) && (hs->file == \
                                   (const char*)hs->handle->data + hs->handle->len - hs->left)) \
                                   ? 0 : TCP_WRITE_FLAG_COPY)
#endif /* LWIP_HTTPD_SSI */
#endif

First of all, are the results of HTTP_IS_DATA_VOLATILE() reversed when LWIP_HTTPD_SSI is reset? Indeed, when LWIP_HTTPD_SSI is defined, it returns TCP_WRITE_FLAG_COPY if the test condition is true. It returns the same value if the test condition is false, if LWIP_HTTPD_SSI is set. It seems one definition or the other is wrong.

I can't fully understand the test condition of the macro, I will try to understand what happens to hs->file pointer and hs->handle for normal files and custom files.


reply via email to

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