Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Apr 27, 2024
1 parent 0b43401 commit ac132fb
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub mod tests {
use std::net::SocketAddr;

use nodecraft::resolver::AddressResolver;
#[cfg(not(windows))]
use parking_lot::Mutex;
// #[cfg(not(windows))]
// use parking_lot::Mutex;
pub use paste;

use self::{delegate::Delegate, error::Error, transport::Transport};
Expand Down Expand Up @@ -120,44 +120,44 @@ pub mod tests {
/// Any error type used for testing.
pub type AnyError = Box<dyn std::error::Error + Send + Sync + 'static>;

#[cfg(not(windows))]
static IPV4_BIND_NUM: Mutex<usize> = Mutex::new(10);
#[cfg(not(windows))]
static IPV6_BIND_NUM: Mutex<usize> = Mutex::new(10);
// #[cfg(not(windows))]
// static IPV4_BIND_NUM: Mutex<usize> = Mutex::new(10);
// #[cfg(not(windows))]
// static IPV6_BIND_NUM: Mutex<usize> = Mutex::new(10);

/// Returns the next socket addr v4
pub fn next_socket_addr_v4(_network: u8) -> SocketAddr {
#[cfg(not(windows))]
{
let mut mu = IPV4_BIND_NUM.lock();
let addr: SocketAddr = format!("127.0.{}.{}:0", _network, *mu).parse().unwrap();
*mu += 1;
if *mu > 255 {
*mu = 10;
}

addr
}

#[cfg(windows)]
// #[cfg(not(windows))]
// {
// let mut mu = IPV4_BIND_NUM.lock();
// let addr: SocketAddr = format!("127.0.{}.{}:0", _network, *mu).parse().unwrap();
// *mu += 1;
// if *mu > 255 {
// *mu = 10;
// }

// addr
// }

// #[cfg(windows)]
"127.0.0.1:0".parse().unwrap()
}

/// Returns the next socket addr v6
pub fn next_socket_addr_v6() -> SocketAddr {
#[cfg(not(windows))]
{
let mut mu = IPV6_BIND_NUM.lock();
let addr: SocketAddr = format!("[fc00::1:{}]:0", *mu).parse().unwrap();
*mu += 1;
if *mu > 255 {
*mu = 10;
}

addr
}

#[cfg(windows)]
// #[cfg(not(windows))]
// {
// let mut mu = IPV6_BIND_NUM.lock();
// let addr: SocketAddr = format!("[fc00::1:{}]:0", *mu).parse().unwrap();
// *mu += 1;
// if *mu > 255 {
// *mu = 10;
// }

// addr
// }

// #[cfg(windows)]
"[::1]:0".parse().unwrap()
}

Expand Down

0 comments on commit ac132fb

Please sign in to comment.