Skip to content

Commit

Permalink
Switch to using 'spare_buffer' crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
dEajL3kA committed Feb 13, 2023
1 parent 9db4efd commit b3bd307
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 55 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "mtcp-rs"
version = "0.1.9"
version = "0.1.10"
edition = "2021"
license-file = "LICENSE"
description = "Provides a “blocking” implementation of TcpListener and TcpStream with proper timeout and cancellation support."
Expand All @@ -16,6 +16,7 @@ readme = "README.md"
lazy_rc = "0.1.3"
log = "0.4.17"
mio = { version = "0.8.5", features = ["os-poll", "net"] }
spare_buffer = "0.1.0"

[dev-dependencies]
crossbeam-channel = "0.5.6"
Expand Down
9 changes: 5 additions & 4 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use mio::{Token, Interest};
use mio::net::TcpStream as MioTcpStream;

use log::warn;
use spare_buffer::SpareBuffer;

use crate::utilities::{Timeout, BufferManager};
use crate::utilities::Timeout;
use crate::{TcpConnection, TcpManager, TcpError};
use crate::manager::TcpPollContext;

Expand Down Expand Up @@ -288,15 +289,15 @@ impl TcpStream {
panic!("maximum_length must be greater than or equal to chunk_size!")
}

let mut buffer = BufferManager::from(buffer, maximum_length);
let mut buffer = SpareBuffer::from(buffer, maximum_length);

loop {
let spare = buffer.alloc_spare_buffer(chunk_size);
let spare = buffer.allocate_spare(chunk_size);
match self.read_timeout(spare, timeout) {
Ok(0) => return Err(TcpError::Incomplete),
Ok(count) => {
buffer.commit(count).map_err(|_err| TcpError::TooBig)?;
match fn_complete(buffer.valid_data()) {
match fn_complete(buffer.data()) {
true => return Ok(()),
false => {},
}
Expand Down
48 changes: 0 additions & 48 deletions src/utilities/buffer.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/utilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* This is free and unencumbered software released into the public domain.
*/
mod flag;
mod buffer;
mod timeout;

pub(crate) use buffer::BufferManager;
pub(crate) use flag::Flag;
pub(crate) use timeout::Timeout;

0 comments on commit b3bd307

Please sign in to comment.