Fixed TlsStream closing the connection abruptly on fatal errors. (#12)
Instead, flush queued TLS messages when an error occurs before closing the connection.
This commit is contained in:
parent
d606a10000
commit
42e1d72fb2
12
src/lib.rs
12
src/lib.rs
@ -172,8 +172,16 @@ impl<S, C> TlsStream<S, C>
|
|||||||
continue
|
continue
|
||||||
},
|
},
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.session.process_new_packets()
|
if let Err(err) = self.session.process_new_packets() {
|
||||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
|
// flush queued messages before returning an Err in
|
||||||
|
// order to send alerts instead of abruptly closing
|
||||||
|
// the socket
|
||||||
|
if self.session.wants_write() {
|
||||||
|
// ignore result to avoid masking original error
|
||||||
|
let _ = self.session.write_tls(&mut self.io);
|
||||||
|
}
|
||||||
|
return Err(io::Error::new(io::ErrorKind::Other, err));
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
},
|
},
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => true,
|
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => true,
|
||||||
|
Loading…
Reference in New Issue
Block a user