New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/ioprocs.cpp: Add wrappers for common patterns #11608
Conversation
I’m pretty tired, so I could have screwed something up here. I’ll definitely look over this again myself. |
Some initial comments:
PS:
|
I also don't like the naming, but I don't immediately have a better suggestion either. Other than that, I like it. |
OK, so if I went with what @ajrhacker is suggesting, would the names be:
My concerns with that would be that they could be misinterpreted as involving blocking I/O (potentially causing someone to believe that regular Another alternative would be to just call these ones @galibert do you have opinions on naming? |
Overloading of simple terminology has been the curse of computing jargon since the 1950s. I might suggest |
@galibert can I get an opinion on the names? Should I bite the bullet and change the member functions to |
emu/diimage.h: Removed fread overloads that allocate memory for output. util/core_file.cpp: Changed output size of load to size_t.
Updated to change the interface functions to |
emu/diimage.h: Removed fread overloads that allocate memory for output. util/core_file.cpp: Changed output size of load to size_t.
emu/diimage.h: Removed fread overloads that allocate memory for output. util/core_file.cpp: Changed output size of load to size_t.
First, some background on this. POSIX-like read/write operations have somewhat complicated semantics. In particular, they can return short for multiple reasons:
EINTR
, otherwise it will return success.EAGAIN
orEWOULDBLOCK
, otherwise it will return success.EAGAIN
) and actually reaching the end of the stream.ENOSPC
orEDQUOT
error.Reading/writing zero bytes may cause error checking to be performed, so it may fail in some cases. As such, attempting to read/write zero bytes should not be simply ignored.
This adds
try_read
/try_read_at
andtry_write
/try_write_at
wrappers to encapsulate the process of attempting to complete a read or write for cases where one doesn’t care whether the operation is atomic with respect to other reads/writes.The functions return pairs or tuples so they can be used with structured binding declarations and
std::tie
when convenient. They’re declared as free functions to keep the interfaces pure. They can be called using unqualified names due to argument-dependent name lookup.There are variants of
try_read
andtry_read_at
that allocate space for the output. Note that they will always allocate the requested number of bytes even though fewer bytes may actually be read. One limitation of the allocating variants is that they won’t work if you try to read zero bytes for the purpose of checking for errors – the non-allocating variants must be used for this purpose (or you can callread
directly on the stream).I’m not convinced
try_read
andtry_write
are necessarily the best names for these. If someone can come up with unambiguously better names, I’d be happy to change them.Like #11588, this also removes some
device_image_interface
member functions in favour of working with the image file object directly.I haven’t ported much code across to use these functions, since the names may need to change.