example: allow concurrent read/write

This commit is contained in:
Aode (lion) 2022-02-14 13:59:36 -06:00
parent 30654fddf9
commit 9aca91c6b3

View file

@ -75,7 +75,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
poller.update_interests(&stream_key, Readiness::write() | Readiness::hangup());
if !bytes.is_empty() {
poller.update_interests(&stream_key, |interests| {
Readiness::write() | interests
});
}
}
if readiness.is_hangup() {
break 'l2;
@ -84,10 +88,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match rustix::io::write(&*stream, &bytes) {
Ok(n) if n == bytes.len() => {
bytes = Vec::new();
poller.update_interests(
&stream_key,
Readiness::read() | Readiness::hangup(),
);
poller.update_interests(&stream_key, |_| {
Readiness::read() | Readiness::hangup()
});
}
Ok(n) => {
bytes = Vec::from(&bytes[n..]);