Skip to content

Commit a1d7fc1

Browse files
committed
upgrade tokio-udt to alpha6 and support udt on non-linux systems too (unoptimized)
1 parent 60a57b8 commit a1d7fc1

5 files changed

Lines changed: 16 additions & 26 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@ socket2 = { version = "0.4.4" }
3232
nix = { version = "0.24.2" }
3333
num_cpus = { version = "1.13" }
3434

35-
[target.'cfg(target_os="linux")'.dependencies]
3635
#tokio-udt = { git = "https://github.com/amatissart/tokio-udt/", rev="f9fdae" }
37-
tokio-udt = "0.1.0-alpha.5"
36+
tokio-udt = "0.1.0-alpha.6"

src/link/rendezvous/listener.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ use tokio::sync::{
2020
mpsc::{Receiver, Sender},
2121
};
2222

23+
use tokio_udt::UdtListener;
24+
2325
type Outlet = Receiver<(Identity, SecureConnection)>;
2426

2527
pub(crate) enum RawListener {
2628
Tcp(TcpListener),
27-
#[cfg(target_os = "linux")]
28-
Udt(tokio_udt::UdtListener),
29+
Udt(UdtListener),
2930
}
3031

3132
pub struct Listener {
@@ -56,14 +57,11 @@ impl Listener {
5657
let port = listener.local_addr().unwrap().port();
5758
(RawListener::Tcp(listener), port)
5859
}
59-
#[cfg(target_os = "linux")]
6060
TransportProtocol::UDT(ref config) => {
61-
let listener = tokio_udt::UdtListener::bind(
62-
(Ipv4Addr::UNSPECIFIED, 0).into(),
63-
Some(config.clone()),
64-
)
65-
.await
66-
.unwrap();
61+
let listener =
62+
UdtListener::bind((Ipv4Addr::UNSPECIFIED, 0).into(), Some(config.clone()))
63+
.await
64+
.unwrap();
6765
let port = listener.local_addr().unwrap().port();
6866
(RawListener::Udt(listener), port)
6967
}
@@ -103,7 +101,6 @@ impl Listener {
103101
Ok((stream.into(), addr))
104102
})
105103
}
106-
#[cfg(target_os = "linux")]
107104
RawListener::Udt(ref udt_listener) => udt_listener
108105
.accept()
109106
.await

src/link/rendezvous/server.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::{
1717
};
1818

1919
use tokio::{io, net::TcpListener};
20+
use tokio_udt::UdtListener;
2021

2122
pub struct Server {
2223
_fuse: Fuse,
@@ -63,9 +64,8 @@ impl Server {
6364
let listener = {
6465
let result = match settings.connect.transport {
6566
TransportProtocol::TCP => TcpListener::bind(address).await.map(RawListener::Tcp),
66-
#[cfg(target_os = "linux")]
6767
TransportProtocol::UDT(ref config) => {
68-
tokio_udt::UdtListener::bind(address, Some(config.clone()))
68+
UdtListener::bind(address, Some(config.clone()))
6969
.await
7070
.map(RawListener::Udt)
7171
}
@@ -96,7 +96,6 @@ impl Server {
9696
.accept()
9797
.await
9898
.map(|(stream, address)| (stream.into(), address)),
99-
#[cfg(target_os = "linux")]
10099
RawListener::Udt(ref udt_listener) => udt_listener
101100
.accept()
102101
.await

src/net/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ mod session_connector;
1616
mod session_control;
1717
mod session_listener;
1818
mod socket;
19+
mod udt;
1920
mod unit_receiver;
2021
mod unit_sender;
2122

2223
pub mod sockets;
2324
pub mod traits;
2425

25-
#[cfg(target_os = "linux")]
26-
mod udt;
27-
2826
#[cfg(any(test, feature = "test_utilities"))]
2927
pub mod test;
3028

src/net/traits/connect.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::net::PlainConnection;
55
use std::io::Result;
66

77
use tokio::net::{TcpStream, ToSocketAddrs};
8+
use tokio_udt::{UdtConfiguration, UdtConnection};
89

910
#[derive(Clone, Debug)]
1011
pub enum TransportProtocol {
1112
TCP,
12-
#[cfg(target_os = "linux")]
13-
UDT(tokio_udt::UdtConfiguration),
13+
UDT(UdtConfiguration),
1414
}
1515

1616
#[derive(Clone, Debug)]
@@ -42,12 +42,9 @@ where
4242
stream.set_nodelay(true)?;
4343
Ok(stream.into())
4444
}),
45-
#[cfg(target_os = "linux")]
46-
TransportProtocol::UDT(config) => {
47-
tokio_udt::UdtConnection::connect(&self, Some(config.clone()))
48-
.await
49-
.map(Into::into)
50-
}
45+
TransportProtocol::UDT(config) => UdtConnection::connect(&self, Some(config.clone()))
46+
.await
47+
.map(Into::into),
5148
}
5249
}
5350
}

0 commit comments

Comments
 (0)