Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
fixing windows '*mut c_void' cannot be sent between threads safely
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Feb 12, 2024
1 parent ef11d6f commit d7ef515
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tun2"
version = "1.0.4"
version = "1.1.0"
edition = "2021"

authors = ["meh. <[email protected]>", "@ssrlive"]
Expand All @@ -15,6 +15,7 @@ crate-type = ["staticlib", "cdylib", "lib"]

[dependencies]
bytes = { version = "1" }
cfg-if = "1.0"
futures-core = { version = "0.3", optional = true }
libc = "0.2"
log = "0.4"
Expand Down
13 changes: 11 additions & 2 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ use std::os::windows::raw::HANDLE;
use crate::address::IntoAddress;
use crate::platform::PlatformConfig;

cfg_if::cfg_if! {
if #[cfg(windows)] {
#[derive(Clone, Debug)]
pub(crate) struct WinHandle(std::os::windows::raw::HANDLE);
unsafe impl Send for WinHandle {}
unsafe impl Sync for WinHandle {}
}
}

/// TUN interface OSI layer of operation.
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
pub enum Layer {
Expand All @@ -47,7 +56,7 @@ pub struct Configuration {
#[cfg(not(unix))]
pub(crate) raw_fd: Option<i32>,
#[cfg(windows)]
pub(crate) raw_handle: Option<HANDLE>,
pub(crate) raw_handle: Option<WinHandle>,
}

impl Configuration {
Expand Down Expand Up @@ -142,7 +151,7 @@ impl Configuration {
}
#[cfg(windows)]
pub fn raw_handle(&mut self, handle: HANDLE) -> &mut Self {
self.raw_handle = Some(handle);
self.raw_handle = Some(WinHandle(handle));
self
}
}

0 comments on commit d7ef515

Please sign in to comment.