Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ where
self
}

/// Writes a stored alert, consuming the alert (if any) and IO.
pub async fn write_alert(&mut self) -> io::Result<()> {
/// Writes a stored alert, consuming the alert (if any).
/// This is useful when previously `send_alert(false)` was set.
pub async fn write_alert(&mut self, io: IO) -> io::Result<()> {
let Some(alert) = self.take_alert() else {
return Ok(());
};

let Some(io) = self.take_io() else {
return Ok(());
};

WritingAlert {
io,
alert: Some(alert),
Expand Down Expand Up @@ -251,7 +248,10 @@ where

match alert.write(&mut SyncWriteAdapter { io, cx }) {
Ok(0) => return Poll::Ready(Ok(())),
Ok(_) => continue,
Ok(_) => {
this.alert = Some(alert);
continue;
}
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
this.alert = Some(alert);
return Poll::Pending;
Expand Down
5 changes: 3 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ async fn lazy_config_acceptor_manual_alert() {
let Ok(accept_result) = time::timeout(Duration::from_secs(3), acceptor.as_mut()).await else {
panic!("timeout");
};

assert!(accept_result.is_err());
acceptor.write_alert().await.unwrap();
let io = acceptor.take_io().unwrap();
// At this point, a user may do something with the IO....
acceptor.write_alert(io).await.unwrap();
let Ok(Ok(received)) = time::timeout(Duration::from_secs(3), rx).await else {
panic!("failed to receive");
};
Expand Down