>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?

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)
}


Felix Halim


On Tue, Jul 24, 2012 at 10:35 AM, Felix Halim <[email protected]> wrote:
> In the uv_read_start() documentation, it says that the on_alloc and
> on_read can be called many times.
> However, it doesn't specify the order.
> Is it like:
>
> on_alloc() on_read()
> on_alloc() on_read()
> ...
> on_alloc() on_read()
>
>
> Or it can interleave?
>
> I am asking this because I am planning to only use one buffer for the
> on_alloc().
> If it interleaves, then it can step toe one another.
>
>
> Felix Halim

-- 
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

Reply via email to