-
Notifications
You must be signed in to change notification settings - Fork 191
Add private data support for deferred_response #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #144 +/- ##
==========================================
- Coverage 96.46% 96.42% -0.04%
==========================================
Files 34 34
Lines 2995 2997 +2
==========================================
+ Hits 2889 2890 +1
- Misses 106 107 +1
Continue to review full report at Codecov.
|
| }; | ||
|
|
||
| typedef ssize_t(*cycle_callback_ptr)(char*, size_t); | ||
| typedef ssize_t(*cycle_callback_ptr)(void*, char*, size_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was thinking about this feature, I tried to figure how we could avoid the "void*" for the type.
To be honest this is probably one of those cases where "seeing it after it is written might help".
I was thinking we could use a template type to define the first parameter and a "shared_ptr" to pass it through. This would save us from having to use the "void*" and, ideally, from having the cleanup function entirely.
To be honest, I would convert the currently existing "char*" into a shared_ptr if we are perturbing the interface.
| const shared_ptr<http_response> render_GET(const http_request& req) | ||
| { | ||
| return shared_ptr<deferred_response>(new deferred_response(test_callback, "cycle callback response")); | ||
| return shared_ptr<deferred_response>(new deferred_response(test_callback, nullptr, nullptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a separate resource and a separate that is used to verify that the new functionality is working fine.
|
|
||
| ssize_t test_callback (char* buf, size_t max) { | ||
| if (counter == 2) { | ||
| typedef struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for typedefs - we can just have a named struct
| const std::shared_ptr<http_response> render_GET(const http_request& req) { | ||
| return std::shared_ptr<deferred_response>(new deferred_response(test_callback, "cycle callback response")); | ||
| // private data of new connections | ||
| auto priv_data = new connection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, refrain from using "auto" for now
|
Hey, thanks for your first contribution. I left you some comments on the code - hopefully, we can work out a good solution for this (it is something I was looking at given a previous pull request). Besides the comments, can you please follow one of the templates for the pull request? |
|
I have an implementation of this that I completed over the weekend (see: #145 ) - let me know if there is still something I am missing from your use-case. |
This is a PR for additional private data support for deferred_response, it is necessary to carry private information so that cycle_callback could tell different HTTP connections by the customized data. cleanup_callback is used to clean up private data allocated by users.