diff --git a/src/client/connection.rs b/src/client/connection.rs index ec29195..b7b2eb9 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -9,12 +9,12 @@ pub use response::Response; // Local dependencies use gio::{ - prelude::{IOStreamExt, OutputStreamExt, OutputStreamExtManual, TlsConnectionExt}, + prelude::{IOStreamExt, OutputStreamExtManual, TlsConnectionExt}, Cancellable, IOStream, NetworkAddress, SocketConnection, TlsCertificate, TlsClientConnection, }; use glib::{ object::{Cast, ObjectExt}, - Priority, + Bytes, Priority, }; pub struct Connection { @@ -61,8 +61,11 @@ impl Connection { callback: impl FnOnce(Result<(Response, Self), Error>) + 'static, ) { let output_stream = self.stream().output_stream(); - output_stream.clone().write_async( - request.header().into_bytes(), + // Make sure **all header bytes** sent to the destination + // > A partial write is performed with the size of a message block, which is 16kB + // > https://docs.openssl.org/3.0/man3/SSL_write/#notes + output_stream.clone().write_all_async( + Bytes::from_owned(request.header()), priority, Some(&cancellable.clone()), move |result| match result { @@ -78,8 +81,11 @@ impl Connection { }) }, ), - Request::Titan { data, .. } => output_stream.write_bytes_async( - &data, + // Make sure **all data bytes** sent to the destination + // > A partial write is performed with the size of a message block, which is 16kB + // > https://docs.openssl.org/3.0/man3/SSL_write/#notes + Request::Titan { data, .. } => output_stream.write_all_async( + data, priority, Some(&cancellable.clone()), move |result| match result { @@ -94,11 +100,11 @@ impl Connection { }) }, ), - Err(e) => callback(Err(Error::Request(e))), + Err((b, e)) => callback(Err(Error::Request(b, e))), }, ), }, - Err((_, e)) => callback(Err(Error::Request(e))), + Err((b, e)) => callback(Err(Error::Request(b, e))), }, ) } diff --git a/src/client/connection/error.rs b/src/client/connection/error.rs index 178cfba..711c2b6 100644 --- a/src/client/connection/error.rs +++ b/src/client/connection/error.rs @@ -2,7 +2,7 @@ use std::fmt::{Display, Formatter, Result}; #[derive(Debug)] pub enum Error { - Request(glib::Error), + Request(glib::Bytes, glib::Error), Response(crate::client::connection::response::Error), TlsClientConnection(glib::Error), } @@ -10,7 +10,7 @@ pub enum Error { impl Display for Error { fn fmt(&self, f: &mut Formatter) -> Result { match self { - Self::Request(e) => { + Self::Request(_, e) => { write!(f, "Request error: {e}") } Self::Response(e) => { diff --git a/src/gio/file_output_stream.rs b/src/gio/file_output_stream.rs index 9a62667..9d6ef23 100644 --- a/src/gio/file_output_stream.rs +++ b/src/gio/file_output_stream.rs @@ -44,7 +44,10 @@ pub fn from_stream_async( return on_complete(Ok((file_output_stream, total))); } - file_output_stream.clone().write_async( + // Make sure **all bytes** sent to the destination + // > A partial write is performed with the size of a message block, which is 16kB + // > https://docs.openssl.org/3.0/man3/SSL_write/#notes + file_output_stream.clone().write_all_async( bytes.clone(), priority, Some(&cancellable.clone()),