Skip to content

Commit

Permalink
fix: missing Read + Write
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed May 24, 2024
1 parent ba8e07e commit 6f186e3
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 7 deletions.
3 changes: 3 additions & 0 deletions crates/shadowsocks-service/src/local/tun/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ cfg_if! {
} else if #[cfg(windows)] {
mod windows;
pub use self::windows::*;
} else {
mod others;
pub use self::others::*;
}
}
21 changes: 19 additions & 2 deletions crates/shadowsocks-service/src/local/tun/sys/others.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
//! Other platforms
use std::{
io::{self, Read, Write},
marker::Unpin,
};

use tokio::io::{AsyncWrite, AsyncWriteExt};
use tun::Device;

/// Packet Information length in bytes
pub const IFF_PI_PREFIX_LEN: usize = 0;

/// Writing packet with packet information
pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet: &[u8]) -> io::Result<()> {
writer.write_all(packet).await
}

/// Set platform specific route configuration
pub async fn set_route_configuration(_: &mut TunDevice) -> io::Result<()> {
pub async fn set_route_configuration<Q>(_: &mut (dyn Device<Queue = Q> + Send)) -> io::Result<()>
where
Q: Read + Write,
{
Ok(())
}
5 changes: 4 additions & 1 deletion crates/shadowsocks-service/src/local/tun/sys/unix/android.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{io, marker::Unpin};
use std::{
io::{self, Read, Write},
marker::Unpin,
};

use tokio::io::{AsyncWrite, AsyncWriteExt};
use tun::Device;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
use std::io::{self, Read, Write};

use tun::Device;

Expand Down
2 changes: 1 addition & 1 deletion crates/shadowsocks-service/src/local/tun/sys/unix/bsd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
io::{self, ErrorKind, IoSlice},
io::{self, ErrorKind, IoSlice, Read, Write},
marker::Unpin,
};

Expand Down
5 changes: 4 additions & 1 deletion crates/shadowsocks-service/src/local/tun/sys/unix/linux.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{io, marker::Unpin};
use std::{
io::{self, Read, Write},
marker::Unpin,
};

use tokio::io::{AsyncWrite, AsyncWriteExt};
use tun::Device;
Expand Down
3 changes: 3 additions & 0 deletions crates/shadowsocks-service/src/local/tun/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ cfg_if! {
} else if #[cfg(target_os = "android")] {
mod android;
pub use self::android::*;
} else {
mod others;
pub use self::others::*;
}
}
23 changes: 23 additions & 0 deletions crates/shadowsocks-service/src/local/tun/sys/unix/others.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::{
io::{self, Read, Write},
marker::Unpin,
};

use tokio::io::{AsyncWrite, AsyncWriteExt};
use tun::Device;

/// Packet Information length in bytes
pub const IFF_PI_PREFIX_LEN: usize = 0;

/// Writing packet with packet information
pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet: &[u8]) -> io::Result<()> {
writer.write_all(packet).await
}

/// Set platform specific route configuration
pub async fn set_route_configuration<Q>(_: &mut (dyn Device<Queue = Q> + Send)) -> io::Result<()>
where
Q: Read + Write,
{
Ok(())
}
5 changes: 4 additions & 1 deletion crates/shadowsocks-service/src/local/tun/sys/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{io, marker::Unpin};
use std::{
io::{self, Read, Write},
marker::Unpin,
};

use tokio::io::{AsyncWrite, AsyncWriteExt};
use tun::Device;
Expand Down

0 comments on commit 6f186e3

Please sign in to comment.