Skip to content

Commit

Permalink
feat(gear): add flush after data wrote to stream
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 24, 2024
1 parent 7ac6b02 commit 8bebb30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! # Oblivion exception
//! All exceptions to the Oblivion function return `OblivionException`.
#[cfg(feature = "python")]
use pyo3::prelude::*;
use ring::error::Unspecified;
use scrypt::errors::InvalidOutputLen;
use thiserror::Error;
#[cfg(feature = "python")]
use pyo3::prelude::*;

/// ## Oblivion exception iterator
/// Use an iterator as the type of exception returned by a function.
Expand Down Expand Up @@ -55,6 +55,8 @@ pub enum OblivionException {
EncryptError { error: Unspecified },
#[error("Exception while decrypting: {error:?}")]
DecryptError { error: Unspecified },
#[error("Failed to send some data: {message}")]
TCPWriteFailed { message: String },
}

#[cfg(feature = "python")]
Expand Down
15 changes: 11 additions & 4 deletions src/utils/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AbsoluteNonceSequence {
///
/// Used to abstract Oblivion's handling of transmitted data, wrapping all data type conversions.
pub struct Socket {
tcp: TcpStream,
pub tcp: TcpStream,
}

impl Socket {
Expand Down Expand Up @@ -101,9 +101,16 @@ impl Socket {
}

pub async fn send(&mut self, data: &[u8]) -> Result<(), OblivionException> {
match self.tcp.write(data).await {
Ok(_) => Ok(()),
Err(_) => Err(OblivionException::UnexpectedDisconnection),
match self.tcp.write_all(&data).await {
Ok(_) => match self.tcp.flush().await {
Ok(_) => Ok(()),
Err(e) => Err(OblivionException::TCPWriteFailed {
message: e.to_string(),
}),
},
Err(e) => Err(OblivionException::TCPWriteFailed {
message: e.to_string(),
}),
}
}

Expand Down

0 comments on commit 8bebb30

Please sign in to comment.