Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Amend HTTP request answering strings #519

Open
YingHan-Chen opened this issue Mar 16, 2020 · 3 comments
Open

Amend HTTP request answering strings #519

YingHan-Chen opened this issue Mar 16, 2020 · 3 comments
Assignees
Labels
A-router Area - API routes C-refactor Category - Improvement help wanted Community contributors are welcome

Comments

@YingHan-Chen
Copy link
Contributor

Currently, we allocate memory from the heap for the response pages, but it will fail when the system out of memory.

We could const char* string for the response pages.
Reference example code https://www.gnu.org/software/libmicrohttpd/tutorial.html#Example-programs

@howjmay
Copy link
Contributor

howjmay commented Mar 17, 2020

See discussion in #516 (comment)

@howjmay howjmay added A-router Area - API routes C-bug Category - Something isn't working help wanted Community contributors are welcome C-refactor Category - Improvement and removed C-bug Category - Something isn't working labels Mar 17, 2020
YingHan-Chen added a commit to YingHan-Chen/tangle-accelerator that referenced this issue Apr 2, 2020
YingHan-Chen added a commit to YingHan-Chen/tangle-accelerator that referenced this issue Apr 5, 2020
Set the MHD response mode to MHD_RESPMEM_PERSISTENT to indicate that buffer is a persistent (static/global) buffer that won't change for at least the lifetime of the response, MHD should just use it, not free it.

Close DLTcollab#519
@marktwtn marktwtn self-assigned this Apr 6, 2020
@marktwtn
Copy link
Contributor

First of all, the HTTP request answering strings has 2 types.

  • Fixed length
  • Unfixed length

For fixed length type, we can create a memory space with pre-defined maximum size.
The memory space can be on the stack or heap. It should be pre-allocated and reused.

For unfixed length type, allocate the memory on the heap.
If the memory is not enough, print the OOM error message.
However, we would not be able to know the exact message from answering strings.
Hence we should classify the HTTP request answering strings and print out the type of it.

@marktwtn
Copy link
Contributor

After some code checking, the memory of HTTP request answering string should be allocated from the heap, no matter the length is fixed or not.
The reason is we have to free the memory space at the last step.
Free the memory space from the stack causes undefined behavior.

The new implementation would be quite simple.
Just log the error message out of memory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-router Area - API routes C-refactor Category - Improvement help wanted Community contributors are welcome
Projects
None yet
3 participants