1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 22:51:07 +01:00

update mio to 0.8

This commit is contained in:
Rob Ede 2021-11-15 18:48:37 +00:00
parent 54d1d9e520
commit ae28ce5377
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 22 additions and 21 deletions

View File

@ -28,7 +28,7 @@ actix-utils = "3.0.0"
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] }
log = "0.4"
mio = { version = "0.7.6", features = ["os-poll", "net"] }
mio = { version = "0.8", features = ["os-poll", "net"] }
num_cpus = "1.13"
socket2 = "0.4.2"
tokio = { version = "1.5.1", features = ["sync"] }

View File

@ -1,5 +1,4 @@
use std::sync::mpsc;
use std::{io, net, thread};
use std::{io, net, sync::mpsc, thread};
use actix_rt::{net::TcpStream, System};
@ -105,12 +104,16 @@ impl TestServer {
/// Get first available unused local address.
pub fn unused_addr() -> net::SocketAddr {
use socket2::{Domain, Protocol, Socket, Type};
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap();
let socket = mio::net::TcpSocket::new_v4().unwrap();
socket.bind(addr).unwrap();
socket.set_reuseaddr(true).unwrap();
let tcp = socket.listen(1024).unwrap();
tcp.local_addr().unwrap()
let socket =
Socket::new(Domain::for_address(addr), Type::STREAM, Some(Protocol::TCP)).unwrap();
socket.set_reuse_address(true).unwrap();
socket.set_nonblocking(true).unwrap();
socket.bind(&addr.into()).unwrap();
socket.listen(1024).unwrap();
net::TcpListener::from(socket).local_addr().unwrap()
}
}

View File

@ -1,21 +1,19 @@
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{mpsc, Arc};
use std::{net, thread, time::Duration};
use std::{
net,
sync::{
atomic::{AtomicUsize, Ordering},
mpsc, Arc,
},
thread,
time::Duration,
};
use actix_rt::{net::TcpStream, time::sleep};
use actix_server::Server;
use actix_server::{Server, TestServer};
use actix_service::fn_service;
use socket2::{Domain, Protocol, Socket, Type};
fn unused_addr() -> net::SocketAddr {
let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap();
let socket =
Socket::new(Domain::for_address(addr), Type::STREAM, Some(Protocol::TCP)).unwrap();
socket.set_reuse_address(true).unwrap();
socket.set_nonblocking(true).unwrap();
socket.bind(&addr.into()).unwrap();
socket.listen(32).unwrap();
net::TcpListener::from(socket).local_addr().unwrap()
TestServer::unused_addr()
}
#[test]