complete_io: bail out if progress is impossible

Have a test that demonstrates another route to reaching this
state: a fully & cleanly closed connection.
This commit is contained in:
Joseph Birr-Pixton 2024-04-18 09:08:59 +01:00 committed by Joe Birr-Pixton
parent 00e695d68d
commit 5374108df6
2 changed files with 43 additions and 0 deletions

View File

@ -391,6 +391,11 @@ impl<Data> ConnectionCommon<Data> {
loop {
let until_handshaked = self.is_handshaking();
if !self.wants_write() && !self.wants_read() {
// We will make no further progress.
return Ok((rdlen, wrlen));
}
while self.wants_write() {
wrlen += self.write_tls(io)?;
}

View File

@ -5855,6 +5855,44 @@ fn test_complete_io_errors_if_close_notify_received_too_early() {
);
}
#[test]
fn test_complete_io_with_no_io_needed() {
let (mut client, mut server) = make_pair(KeyType::Rsa);
do_handshake(&mut client, &mut server);
client
.writer()
.write_all(b"hello")
.unwrap();
client.send_close_notify();
transfer(&mut client, &mut server);
server.process_new_packets().unwrap();
server
.writer()
.write_all(b"hello")
.unwrap();
server.send_close_notify();
transfer(&mut server, &mut client);
client.process_new_packets().unwrap();
// neither want any IO: both directions are closed.
assert!(!client.wants_write());
assert!(!client.wants_read());
assert!(!server.wants_write());
assert!(!server.wants_read());
assert_eq!(
client
.complete_io(&mut FakeStream(&[]))
.unwrap(),
(0, 0)
);
assert_eq!(
server
.complete_io(&mut FakeStream(&[]))
.unwrap(),
(0, 0)
);
}
struct FakeStream<'a>(&'a [u8]);
impl<'a> io::Read for FakeStream<'a> {