looking for an example of libuv embedded in libevent

270 views
Skip to first unread message

Ramesh Rayaprolu

unread,
Jan 22, 2014, 7:51:46 PM1/22/14
to li...@googlegroups.com
I am trying to do async File IO using libuv (uv_fs_* api's).

I need to embed this File IO into an application which uses libevent and has its own main-loop.

I was looking for such examples, and did not find any. Please let me know if someone has it.

The problem that I am facing is like this --
uv_fs_open, uv_fs_read have their own callbacks (which use uv_fs_t * as argument).
But libevent has its own callback and that call back cannot get this "uv_fs_t *"

So, whenever I add the uv_backend_fd to libevent, and as soon as I do uv_fs_open, I reach the libevent callback, and I see that the uv_fs_t * is not yet updated.
Thus , I cannot get the uv_file (fd) to further read/write on this.

Any help or suggestions on this is greatly appreciated.

Thanks and Best Regards,
Ramesh

Fedor Indutny

unread,
Jan 23, 2014, 2:49:17 AM1/23/14
to li...@googlegroups.com
Hello!

You may want to try following scenario:

1. Adding uv_backend_fd() to the libevent's loop
2. On change on that fd do: uv_run(UV_RUN_NOWAIT)
> --
> 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 libuv+un...@googlegroups.com.
> To post to this group, send email to li...@googlegroups.com.
> Visit this group at http://groups.google.com/group/libuv.
> For more options, visit https://groups.google.com/groups/opt_out.

yaco...@lineratesystems.com

unread,
Jan 30, 2014, 11:51:17 AM1/30/14
to li...@googlegroups.com
This isn't using the recommend backend kqueue method but here is an example I created to use the threadpool behavior, you may be able to adopt it to your needs - see attached.

Hope it helps.
test_integrated.c

Ramesh Rayaprolu

unread,
Feb 4, 2014, 7:00:03 PM2/4/14
to li...@googlegroups.com, fe...@indutny.com
Thank you so very much Fedor and Yaco...

I used my main lib-event callback (change in UV fd) to do the uv_run(...NOWAIT), and then I get respective libuv callback to do my job !!

did the trick for me.


Thanks and Best Regards,
Ramesh

Reply all
Reply to author
Forward
0 new messages