Skip to content
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

Export EAGAIN as a memory of Error #215

Open
valarauca opened this issue Sep 30, 2024 · 0 comments
Open

Export EAGAIN as a memory of Error #215

valarauca opened this issue Sep 30, 2024 · 0 comments

Comments

@valarauca
Copy link

Please discuss your new feature before implementing it if it's nontrivial. Adding a small method is probably trivial, anything larger than that, maybe not. Note that API stability is paramount.

Many of the encoding & decoding functions communicate the state of the decoder/encoders via the posix EAGAIN code (example: 1, 2). This code is even so important, that the documentation calls out how to find it, I can only assume as a way to help consumers of the library.

So why isn't EAGAIN part of the Error enum?

The advantage is obvious it would take

for (stream,packet) in input.packets() {
    if stream.index() == idx {
        match output_decoder.send_packet(&packet) {
            Ok(()) => { },
            // Why does such a common case require so much visual noise?
            Err(Error::Other { code: EAGAIN }) => {
                 // get data out of the decoder
             }
             Err(e) => return Err(e),
        };
    }
}

into

for (stream,packet) in input.packets() {
    if stream.index() == idx {
        match output_decoder.send_packet(&packet) {
            Ok(()) => { },
            Err(Error::EAgain) => {
                 // get data out of the decoder 
             }
             Err(e) => return Err(e),
        };
    }
}

It feels like the most common case that needs special error handling shouldn't require the most visual space.


This more closely follows the "flow" of C code examples, e.g.:

rc = send_packet(decoder_ptr, packet_ptr);
if rc == 0 {
    continue;
} else if rc == EAGAIN {
    /* get data out of the decoder */
} else {
    return rc;
}

The very obvious, "I need to read data out of decoder/encoder" return code shouldn't be buried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant