Git Product home page Git Product logo

Comments (6)

berkowski avatar berkowski commented on June 8, 2024

The mio docs state that for edge-triggered read operations the client should read until a WouldBlock error. The default match case where b <= 0 should never be triggered because b will always have a size of at least one. However, we still need the guard on the match case or rust will throw an error at compile time. The logic could be more clear if I changed the println! to something like panic!.

For the second part: It does look like you can just catch the error on read, and then check what type of error was raised .

from mio-serial.

dvtomas avatar dvtomas commented on June 8, 2024

Ok, in that case, is the guard on bytes count necessary at all? Also, according to MIO docs, with edge-triggered events we ought loop reading until a WouldBlock is received. Maybe this kind of example (replacing the part I've quoted in the first post) would be more correct? Or is there anything special about mio-serial MIO semantics?

loop {
    // With edge triggered events, we must perform reading until we receive a WouldBlock
    match rx.read(&mut rx_buf) {
        Ok(b) => println!("{:?}", String::from_utf8_lossy(&rx_buf[..b])),
        Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
            break;
        }
        Err(e) => {
            println!("Error:  {}", e)
            break;
        },
    }
}

from mio-serial.

dvtomas avatar dvtomas commented on June 8, 2024

Hi, @berkowski ,

if you find time, what is your opinion on my last comment? We're implementing communication with measurement devices that needs to be pretty reliable, so I need to be sure about the correct way to use mio-serial. I've had issues before with TCP communication freeze when I didn't loop until WouldBlock, that's why I've raised the question with the example I think would be a proper way to handle MIO compatbile Evented read stream..

from mio-serial.

berkowski avatar berkowski commented on June 8, 2024

@dvtomas

Sorry about the delay. I'm on a ship at the moment and internet access is pretty..... slow....

Your example code seems like it would work (minus the small missing ';' after the second prinln!). I swapped in your method in the example and didn't see any change using the signals I can easily generate here at the moment.

My own knowledge of the internals of mio are limited to what their docs were about a year ago and it looks like they've put in a lot more work there since my last read. I don't think there is much difference between the two methods in practice, but your version certainly reads better and seems more idomatic.

from mio-serial.

dvtomas avatar dvtomas commented on June 8, 2024

Cool, thank you for your investigation. Should I update the docs with my example and make a PR? Maybe even replacing println!("Error..") with panic! would better show the intent..

Enjoy your sail!

from mio-serial.

berkowski avatar berkowski commented on June 8, 2024

I'd welcome a PR with those changes :) Otherwise I'll get around to it when I'm back on shore in December.

from mio-serial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.