[libuv] uv_write and uv_close

471 views
Skip to first unread message

Felix Halim

unread,
Jul 27, 2012, 3:38:45 AM7/27/12
to nod...@googlegroups.com
Is it mandatory to call uv_close in the callback of uv_write?

Or we can just write it like this (3 uv_writes, followed by one uv_close):

uv_write(&write_req, (uv_stream_t*)&handle, &resbuf, 1, 0);
uv_write(&write_req, (uv_stream_t*)&handle, &resbuf, 1, 0);
uv_write(&write_req, (uv_stream_t*)&handle, &resbuf, 1, 0);
uv_close((uv_handle_t*)req->handle, on_close);

Is it guaranteed that the close will happen after all writes are finished?

I couldn't find any info regarding this in the uv.h

Felix Halim

Ben Noordhuis

unread,
Jul 27, 2012, 8:00:17 AM7/27/12
to nod...@googlegroups.com
The handle gets closed, your callbacks get called with status=-1,
error code UV_EINTR. The data is not written.

I'll add it to uv.h if it isn't documented there yet.

Felix Halim

unread,
Jul 27, 2012, 8:19:12 AM7/27/12
to nod...@googlegroups.com
So, the only way to correctly call uv_close() is to wait until all
uv_write's callbacks have been called?

Why don't it get queued just like multiple_calls to uv_write() ?

(I am asking why it is designed that way)

Felix Halim

Ben Noordhuis

unread,
Jul 27, 2012, 8:27:18 AM7/27/12
to nod...@googlegroups.com
On Fri, Jul 27, 2012 at 2:19 PM, Felix Halim <felix...@gmail.com> wrote:
> So, the only way to correctly call uv_close() is to wait until all
> uv_write's callbacks have been called?
>
> Why don't it get queued just like multiple_calls to uv_write() ?
>
> (I am asking why it is designed that way)
>
> Felix Halim

You can figure this one out yourself. :-) How would you handle
timeouts if uv_close() worked like you describe?

Felix Halim

unread,
Jul 27, 2012, 9:57:22 AM7/27/12
to nod...@googlegroups.com
On Fri, Jul 27, 2012 at 8:00 PM, Ben Noordhuis <in...@bnoordhuis.nl> wrote:
I discovered that there is a problem in calling multiple uv_writes
using the SAME &write_req like the above example.
What happened is that the callback after_write get called infinitely
(endless loop).

Is it true that each uv_write() must be specified different uv_write_t,
and each uv_write_t variable must be valid until the callback is fired?
(thus, it is not dispose-able like uv_buf_t)

If that's true, then someone should insert an assertion there to catch on
the attempts to call uv_write with the same &write_req.
Also, please add that to the uv.h comments. Thanks.

Today, I spend all of my time just to understand these quirks -_-'

Felix Halim

Bry

unread,
Jul 27, 2012, 12:42:36 PM7/27/12
to nod...@googlegroups.com
Why don't you guys open up the Wiki section on the uv github so we can get some tuts rolling?

Ben Noordhuis

unread,
Jul 27, 2012, 1:58:38 PM7/27/12
to nod...@googlegroups.com
On Fri, Jul 27, 2012 at 6:42 PM, Bry <brandon...@gmail.com> wrote:
> Why don't you guys open up the Wiki section on the uv github so we can get
> some tuts rolling?

Done.
Reply all
Reply to author
Forward
0 new messages