Also use take_error after writing

This commit is contained in:
Stjepan Glavina 2020-05-22 20:29:50 +02:00
parent 7ac8969f45
commit c7bc1bed0f
1 changed files with 14 additions and 6 deletions

View File

@ -701,9 +701,13 @@ impl Async<TcpStream> {
};
// The stream becomes writable when connected.
stream.write_with(|io| wait_connect(io)).await?;
Ok(stream)
match stream.write_with(|io| wait_connect(io)).await {
Ok(()) => Ok(stream),
Err(err) => match stream.get_ref().take_error()? {
Some(err) => Err(err),
None => Err(err),
},
}
}
/// Reads data from the stream without removing it from the buffer.
@ -1020,9 +1024,13 @@ impl Async<UnixStream> {
};
// The stream becomes writable when connected.
stream.write_with(|io| wait_connect(io)).await?;
Ok(stream)
match stream.write_with(|io| wait_connect(io)).await {
Ok(()) => Ok(stream),
Err(err) => match stream.get_ref().take_error()? {
Some(err) => Err(err),
None => Err(err),
},
}
}
/// Creates an unnamed pair of connected UDS stream sockets.