Skip to content

Commit efa87f5

Browse files
committed
No shutdown raw stream
1 parent 710cf25 commit efa87f5

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ where
359359
}
360360
}
361361

362-
Poll::Ready(match ready!(Pin::new(&mut self.io).poll_shutdown(cx)) {
362+
Poll::Ready(match ready!(Pin::new(&mut self.io).poll_flush(cx)) {
363363
Ok(()) => Ok(()),
364364
// When trying to shutdown, not being connected seems fine
365365
Err(err) if err.kind() == io::ErrorKind::NotConnected => Ok(()),

src/common/test_stream.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,75 @@ async fn stream_write_zero() -> io::Result<()> {
366366
Ok(()) as io::Result<()>
367367
}
368368

369+
#[tokio::test]
370+
async fn stream_shutdown() -> io::Result<()> {
371+
struct TestIo<'a> {
372+
conn: &'a mut Connection,
373+
is_shutdown: bool,
374+
}
375+
376+
impl AsyncRead for TestIo<'_> {
377+
fn poll_read(
378+
self: Pin<&mut Self>,
379+
_cx: &mut Context<'_>,
380+
_: &mut ReadBuf<'_>,
381+
) -> Poll<io::Result<()>> {
382+
Poll::Pending
383+
}
384+
}
385+
386+
impl AsyncWrite for TestIo<'_> {
387+
fn poll_write(
388+
mut self: Pin<&mut Self>,
389+
_cx: &mut Context<'_>,
390+
mut buf: &[u8],
391+
) -> Poll<io::Result<usize>> {
392+
let len = self.conn.read_tls(buf.by_ref())?;
393+
self.conn
394+
.process_new_packets()
395+
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
396+
Poll::Ready(Ok(len))
397+
}
398+
399+
fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
400+
self.conn
401+
.process_new_packets()
402+
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
403+
Poll::Ready(Ok(()))
404+
}
405+
406+
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
407+
self.get_mut().is_shutdown = true;
408+
Poll::Ready(Ok(()))
409+
}
410+
}
411+
412+
let (server, mut client) = make_pair();
413+
let mut server = Connection::from(server);
414+
poll_fn(|cx| do_handshake(&mut client, &mut server, cx)).await?;
415+
416+
{
417+
let mut io = TestIo {
418+
conn: &mut server,
419+
is_shutdown: false,
420+
};
421+
let mut stream = Stream::new(&mut io, &mut client);
422+
423+
stream.session.send_close_notify();
424+
stream.shutdown().await?;
425+
426+
assert!(!io.is_shutdown);
427+
}
428+
429+
assert!(!server.is_handshaking());
430+
assert!(server
431+
.process_new_packets()
432+
.map_err(io::Error::other)?
433+
.peer_has_closed());
434+
435+
Ok(()) as io::Result<()>
436+
}
437+
369438
fn make_pair() -> (ServerConnection, ClientConnection) {
370439
let (sconfig, cconfig) = utils::make_configs();
371440
let server = ServerConnection::new(Arc::new(sconfig)).unwrap();

0 commit comments

Comments
 (0)