Hi,

I'm intrigued by Ryan Dahl's tutorial on libuv:

http://vimeo.com/24713213

So, I tried creating a simple web api using libuv.
However, I am stuck on uv_write.
Ryan's example uses static response to the client:


#define RESPONSE \
  "HTTP/1.1 200 OK\r\n" \
  "Content-Type: text/plain\r\n" \
  "Content-Length: 12\r\n" "\r\n" \
  "hello world\n"

uv_buf_t resbuf;
resbuf.base = (char*) RESPONSE;
resbuf.len = sizeof(RESPONSE);
uv_write(&client->write_req, (uv_stream_t*)&client->handle, &resbuf,
1, after_write);


For dynamic response, I believe we have to allocate a response buffer
dynamically (in size).
I'd like to know whether there already exists a good buffer management
(besides simple malloc)?
How node currently uses uv_write efficiently? by buffering all
responses in memory and call uv_write() once?

AFAIK, all the responses must be written in the buffer before calling
uv_write() and the buffer must be valid until the callback is called.
What if we have a very large response that don't fit in memory? For
example, we want to generate a never ending response on the fly? Is it
possible to call uv_write multiple times and resume writing in the
after_write callback?

I think it would be better if libuv provides a FILE *stream so that we
can just use fprintf() to write the response? (and fflush)
Then, when we are done writing all the responses, we manually call
after_write() or whatever to close the connection.
This would make those two things above a lot easier for the user,
isn't it? (of course this means libuv must handle the allocation)


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