varlink / libvarlink

C implementation of the Varlink protocol and command line tool
Apache License 2.0
87 stars 15 forks source link

non-blocking sockets: Handle EWOULDBLOCK as EAGAIN #16

Closed thomasjfox closed 3 years ago

thomasjfox commented 4 years ago

The non-blocking I/O socket code in varlink_stream_read() / varlink_stream_flush() handles EAGAIN already. It should be an easy thing to also handle EWOULDBLOCK:

From the write() man page: EAGAIN or EWOULDBLOCK The file descriptor fd refers to a socket and has been marked non-blocking (O_NONBLOCK), and the write would block. POSIX.1-2001 allows either error to be returned for this case, and does not require these constants to have the same value, so a portable application should check for both possibilities.

Looking at the code again today, support for EINTR should also be added to varlink_stream_read() and varlink_stream_flush(). Otherwise the code errors out during normal signal delivery.

haraldh commented 4 years ago
/usr/include/asm-generic/errno.h:#define    EWOULDBLOCK EAGAIN  /* Operation would block */
haraldh commented 4 years ago

Please review https://github.com/varlink/libvarlink/pull/20

thomasjfox commented 4 years ago

..."and does not require these constants to have the same value, so a portable application should check for both possibilities." ;)

We can either choose to ignore this fact or just change every

case EAGAIN:
    xyz

to

case EAGAIN:
case EWOULDBLOCK:
    xyz

As you mentioned in #17, libvarlink is tested on Linux only at the moment.

haraldh commented 3 years ago

..."and does not require these constants to have the same value, so a portable application should check for both possibilities." ;)

Hmm.. epoll is Linux only anyway.. right?