rns-net 0.8.1

Network interfaces and node driver for the Reticulum Network Stack
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! Shared process-local allocation for component-owned test listeners.

use std::sync::atomic::{AtomicU16, Ordering};

static NEXT_PORT: AtomicU16 = AtomicU16::new(0);

pub(crate) fn port() -> u16 {
    let pid = std::process::id() as u16;
    // Stay below Linux's default ephemeral range so client connections created by
    // parallel network tests cannot consume a component-owned listener port.
    let base = 10_000 + (pid % 200) * 100;
    let _ = NEXT_PORT.compare_exchange(0, base, Ordering::SeqCst, Ordering::SeqCst);
    NEXT_PORT.fetch_add(1, Ordering::SeqCst)
}