Problem with using uv_fs_read

123 views
Skip to first unread message

Bodo Kaiser

unread,
May 11, 2013, 11:59:20 AM5/11/13
to li...@googlegroups.com
Hello,

I would like to read the content of a text file.

To achieve this I have written following file:

https://gist.github.com/bodokaiser/55e44ecb18a9705585b6

I now have two problems with my current implementation:

1. on_read is only called once.
Because of this I have to add another close to the reading if (line 52)

2. result code of on_close indicates an error.
For some reason result in line 59 equals -1 which should indicate an error.

Would be glad to hear what I have done wrong ;)
Bodo

Ben Noordhuis

unread,
May 11, 2013, 8:22:57 PM5/11/13
to li...@googlegroups.com
On Sat, May 11, 2013 at 8:59 AM, Bodo Kaiser <bodo....@enabre.com> wrote:
> Hello,
>
> I would like to read the content of a text file.
>
> To achieve this I have written following file:
>
> https://gist.github.com/bodokaiser/55e44ecb18a9705585b6
>
> I now have two problems with my current implementation:
>
> 1. on_read is only called once.
> Because of this I have to add another close to the reading if (line 52)

Maybe I'm misunderstanding what you're saying but you call
uv_fs_read(on_read) only once, therefore on_read is called only once.

> 2. result code of on_close indicates an error.
> For some reason result in line 59 equals -1 which should indicate an error.

From the gist:

uv_fs_close(loop, &close_req, result, on_close);

`result` is the number of bytes read, not the file descriptor.

bodo....@enabre.com

unread,
May 20, 2013, 2:39:48 AM5/20/13
to li...@googlegroups.com
Yep, misinterpreted the header file. Sorry for wasting your time.
Reply all
Reply to author
Forward
0 new messages