Created
November 11, 2013 07:59
-
-
Save skabbes/7409493 to your computer and use it in GitHub Desktop.
How to allocate into a vector<char> in libuv?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| uv_buf_t alloc_buffer(uv_handle_t * handle, size_t suggested_size) { | |
| vector<char> * data = new vector<char>(suggested_size); | |
| return uv_buf_init(data->data(), suggested_size); | |
| } | |
| void on_read(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { | |
| vector<char> * data = reinterpret_cast<vector<char> * >(buf.__data); | |
| // do something else | |
| delete data; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The handle is the same across calls to
on_readthough right? so there's be no way to know whichon_readapplied to whichon_alloc