4 ms·
Nice. I think a reasonable addition to something like this might be a "truncated I/O" failure mode, i.e. make the read/write syscalls succeed, but only read/wri
by st_goliath 5y ago
Nice. I think a reasonable addition to something like this might be a "truncated I/O" failure mode, i.e. make the read/write syscalls succeed, but only read/write less than what was requested.
This is kind of a pet peeve of mine. I've seen way too much FLOSS as well as proprietary C code that simply assumes return value >0 means everything was processed, or assume -1 means unrecoverable error and don't even bother to check for e.g. EINTR.
I'm curious just how bad some programs might fall on their nose when they hit such an error condition.
- azinman2 5y agoWonder if there’s some way of encoding this as a much higher level, such that you could wrap any difficult handling logic inside of a library and simplify the handling of errors for us mere humans.
- teddyh 5y ago#include <stdio.h>
- rzzzt 5y agoGNOME's GIO library has a function that reads all requested bytes in a single call, until EOF or an error condition is reached: https://developer.gnome.org/gio/stable/GInputStream.html#g-input-stream-read-all https://developer.gnome.org/gio/stable/GInputStream.html#g-i...
- azinman2 5y agoBut don't you still need to switch on all of the possible errors to figure out what to do? I guess I'm thinking about something that's more like a strategy that you tell the system. E.g. if it's retryable, so do this many times or up to this many seconds. If it's not possible to write (out of space, device no longer exists, internet is down), then hand me back a string I can display to my user about the error. Etc. Something that is more akin to all the cases that you'd have to handle being done inside of a library call, with easy predictable ways to work with very few possible error(s) that get returned.
- rzzzt 5y agoIt could certainly be taken further along these lines; I was mentioning it because of the "short read" scenario, which is... not quite an error, but can be the cause of one, as st_goliath writes above.
- spc476 5y agoOne could add a side channel to tell it to fail certain calls. I'm doing a similar thing at work---I have a mock DB that runs with a side channel for the testing framework to tell the mock DB what to pass and what to fail (I should say I'm not testing the DB, but a program that talks to the DB).
- jra_samba 5y agoSamba actually ran into this with io_uring. It can return less that the client asked for for read/write. We were returning this to the client and the clients... didn't cope well (even though the protocol is supposed to allow this :-). The Samba client code worked fine though :-).