On Tue, Jul 24, 2012 at 11:29 AM, Felix Halim <[email protected]> wrote:
> From what I see in the ./src/unix/stream.c, on_read is called
> immediately after on_alloc.
> Is it guaranteed that it will always be the case? or it may change in
> the future?
It may change if the need arises.
> Since libuv is single threaded, the following code should work fine
> even there are concurrent requests, right?
>
>
> // a global variable for the read buffer
> char read_buf[64 * 1024];
>
> uv_buf_t on_alloc(uv_handle_t* h, size_t suggested_size) {
> client_t *c = (client_t*) h->data;
> uv_buf_t buf;
> buf.base = read_buf;
> buf.len = 64 * 1024;
> return buf;
> }
>
> void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
> // use the "buf", but no need to free(buf.base)
> }
>
Yes, that works. We use a similar approach in the libuv test suite.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en