#[tokio::test] asyncfn disconnect() { let (mut a, mut b) = duplex(32);
let t1 = tokio::spawn(asyncmove {
a.write_all(b"ping").await.unwrap(); // and dropped
});
let t2 = tokio::spawn(asyncmove { letmut buf = [0u8; 32]; let n = b.read(&mut buf).await.unwrap();
assert_eq!(&buf[..n], b"ping");
let n = b.read(&mut buf).await.unwrap();
assert_eq!(n, 0);
});
t1.await.unwrap();
t2.await.unwrap();
}
#[tokio::test] asyncfn disconnect_reader() { let (a, mut b) = duplex(2);
let t1 = tokio::spawn(asyncmove { // this will block, as not all data fits into duplex
b.write_all(b"ping").await.unwrap_err();
});
let t2 = tokio::spawn(asyncmove { // here we drop the reader side, and we expect the writer in the other // task to exit with an error
drop(a);
});
t2.await.unwrap();
t1.await.unwrap();
}
#[tokio::test] asyncfn max_write_size() { let (mut a, mut b) = duplex(32);
let t1 = tokio::spawn(asyncmove { let n = a.write(&[0u8; 64]).await.unwrap();
assert_eq!(n, 32); let n = a.write(&[0u8; 64]).await.unwrap();
assert_eq!(n, 4);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.