Skip to content

Commit

Permalink
IpStackTcpStreamInner is so larger and place it to heap
Browse files Browse the repository at this point in the history
  • Loading branch information
xmh0511 committed Mar 28, 2024
1 parent 4f0e506 commit 1ebfc21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl IpStack {
{
let (accept_sender, accept_receiver) = mpsc::unbounded_channel::<IpStackStream>();

let (drop_sender, mut drop_receiver) = mpsc::unbounded_channel::<IpStackTcpStreamInner>();
let (drop_sender, mut drop_receiver) =
mpsc::unbounded_channel::<Box<IpStackTcpStreamInner>>();
tokio::spawn(async move {
while let Some(mut inner) = drop_receiver.recv().await {
tokio::spawn(async move {
Expand Down
6 changes: 3 additions & 3 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,15 @@ impl Drop for IpStackTcpStreamInner {
#[derive(Debug)]
pub struct IpStackTcpStream {
inner: Option<IpStackTcpStreamInner>,
drop_sender: UnboundedSender<IpStackTcpStreamInner>,
drop_sender: UnboundedSender<Box<IpStackTcpStreamInner>>,
src_addr: SocketAddr,
dst_addr: SocketAddr,
stream_sender: UnboundedSender<NetworkPacket>,
}

impl IpStackTcpStream {
pub(crate) fn new(
drop_sender: UnboundedSender<IpStackTcpStreamInner>,
drop_sender: UnboundedSender<Box<IpStackTcpStreamInner>>,
src_addr: SocketAddr,
dst_addr: SocketAddr,
tcp: TcpPacket,
Expand Down Expand Up @@ -643,7 +643,7 @@ impl AsyncWrite for IpStackTcpStream {
impl Drop for IpStackTcpStream {
fn drop(&mut self) {
if let Some(inner) = self.inner.take() {
if let Err(e) = self.drop_sender.send(inner) {
if let Err(e) = self.drop_sender.send(Box::new(inner)) {
trace!("fail to send IpStackTcpStreamInner to drop {:?}", e);
}
}
Expand Down

0 comments on commit 1ebfc21

Please sign in to comment.