libuv / help

Need help with libuv? Post your question here.
28 stars 7 forks source link

UV_HANDLE_READABLE and UV_EOF #162

Closed kyze8439690 closed 4 years ago

kyze8439690 commented 4 years ago

Is it a good design to make handle->flags &= ~UV_HANDLE_READABLE flag correspond to getting UV_EOF in uv_read_start? It seem that UV_HANDLE_READABLE is removed only when closing.

bnoordhuis commented 4 years ago

uv_read_start() never clears UV_HANDLE_READABLE. Were you thinking of uv__stream_close()?

uv_read_start() sets UV_HANDLE_READING (different flag), to mark that the user wants data.

UV_HANDLE_READABLE is a note that libuv makes to remember whether the handle was opened in read mode. It never changes during the lifetime of the handle, only when it's closed.

kyze8439690 commented 4 years ago

I mean when you get UV_EOF in uv_read_cb, which mean this uv_stream becomes unreadable, why not we clear UV_HANDLE_READABLE flag on this uv_stream?

kyze8439690 commented 4 years ago

Here is a similar scene, uv_shutdown method makes a uv_stream becomes unwritable, and it will clear UV_HANDLE_WRITABLE flag.

bnoordhuis commented 4 years ago

If you think it's a good idea, you're welcome to open a pull request. The thing is, the observable behavior can't change - it's not allowed to break existing programs.

kyze8439690 commented 4 years ago

It seems that there is a flag called UV_HANDLE_READ_EOF which can indicate UV_EOF, I will try to use this flag instead. Thanks.

kyze8439690 commented 4 years ago

UV_HANDLE_READ_EOF work like a charm! Hope that in the future there will be an uv_is_read_eof() method for it. Maybe I can open a pull request? :)