Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.13k stars 93 forks source link

automatically free buffer when request is done #182

Closed mez0ru closed 1 year ago

mez0ru commented 1 year ago

This is a noob question, but I just could not find a great solution to it yet, so I will ask. I have a buffer of char*, I want to prevent copying the buffer to set_body. So my solution is to use string_view, which works great. However, the memory does not get freed. I have to manually free the buffer. The problem is, I can't free the buffer before the request is handled. Using done callback seems to suffer from a timing issue (funny enough it works well during debugging) but not on release. I had tried using smart pointers, but they get freed when they are out of scope before the request is handled. So is there any way to free the buffer right after the request is handled? I think, there could be another callback that I'm not aware of, but I tried searching through issues and methods on this repo with no luck. Thanks.

mez0ru commented 1 year ago

My bad, it turned out it's a bug in my code, sorry to waste your time. For anyone looking for a solution, I found this page too, although I will keep using done callback as a way to delete the buffer for now: restinio buffers tutorial