Comments (6)
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.
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.
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.
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.
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.
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)
- mio-serial v3.0.0 not compatible with serialport v3.1.0 HOT 3
- Update to serialport-rs 3.1 HOT 1
- Bump nix to 0.14 HOT 2
- libudev problems HOT 3
- Windows support HOT 1
- Windows try_clone returns incorrect trait HOT 1
- mio 0.7 support HOT 10
- Push for v4.0 before Ownership Transfer or Maintenence HOT 3
- Missing 4.0.0-beta1 tag HOT 9
- mio-serial-4.0.0-beta3 fails to compile due to StdIoErrorKind::Unsupported HOT 4
- Can't compile as dependency to another project HOT 5
- How to modify device parameters or stop the device during data reading?
- cann't open serial again HOT 1
- nix 0.26 can't work on ubuntu16.04
- how to control RTS and DTR? HOT 1
- Invalid stop bits setting encountered HOT 3
- Add a repo description
- How close is `Source` to a `Stream<..some bytes type..>`?
- Are there more read/write examples or better docs available? HOT 2
- What's wrong with tokio::fs?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mio-serial.