Hello Frank, Your reasoning is absolutely correct. `uv_write_t` instances should be alive up until the `uv_write_cb` will be called for each of them. In examples they are allocated on-stack, because `uv_run()` is called on the same stack as well, thus guaranteeing that `uv_write_t` won't fall out of scope until `uv_run()` will finish.
Hope this helps, Fedor. On Sat, Dec 5, 2015 at 9:46 PM, Frank <[email protected]> wrote: > Well my C is a little bit rusty but in the documentation for uv_write() > there's an example printed: > > uv_buf_t a[] = { > { .base = "1", .len = 1 }, > { .base = "2", .len = 1 } > }; > > uv_buf_t b[] = { > { .base = "3", .len = 1 }, > { .base = "4", .len = 1 } > }; > > uv_write_t req1; > uv_write_t req2; > > /* writes "1234" */ > uv_write(&req1, stream, a, 2); > uv_write(&req2, stream, b, 2); > > Is this a correctly functional example? I'm asking because of the fact > that req1 and req2 are allocated on the stack. Now from what I > understand is that a callback (uv_write_cb) is done sometime in the > future (possibly after the stack frame where those reqs reside was > destroyed) once the write is completed (or failed) passing those reqs > as arguments. Although the client callback apparently can't do anything > with those reqs (they are opaque) other than use their identity. Does > my reasoning make any sense? > > Thanks, > Frank > > -- > You received this message because you are subscribed to the Google Groups > "libuv" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/libuv. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
