Update tokio to 1.0

This commit is contained in:
Jonas Herzig 2021-01-17 16:47:41 +01:00
parent 99f702234d
commit cfae6178c7
6 changed files with 274 additions and 291 deletions

View file

@ -30,7 +30,7 @@ use std::task::Context;
use std::task::Poll;
use std::time::Duration;
use tokio::io;
use tokio::time::Delay;
use tokio::time::Sleep;
use webrtc_sdp::attribute_type::SdpAttribute;
use crate::error::Error;
@ -39,10 +39,10 @@ use crate::Config;
type SessionId = u32;
struct User {
session: u32, // mumble session id
ssrc: u32, // ssrc id
active: bool, // whether the user is currently transmitting audio
timeout: Option<Delay>, // assume end of transmission if silent until then
session: u32, // mumble session id
ssrc: u32, // ssrc id
active: bool, // whether the user is currently transmitting audio
timeout: Option<Pin<Box<Sleep>>>, // assume end of transmission if silent until then
start_voice_seq_num: u64,
highest_voice_seq_num: u64,
rtp_seq_num_offset: u32, // u32 because we also derive the timestamp from it
@ -70,7 +70,7 @@ impl User {
}
fn set_active(&mut self, target: u8) -> Option<Frame> {
self.timeout = Some(tokio::time::delay_for(Duration::from_millis(400)));
self.timeout = Some(Box::pin(tokio::time::sleep(Duration::from_millis(400))));
if self.active {
None
@ -587,8 +587,7 @@ impl Future for Connection {
// (same applies to the other futures directly below it)
for session in self.sessions.values_mut() {
if let Some(timeout) = &mut session.timeout {
pin_mut!(timeout);
if let Poll::Ready(()) = timeout.poll(cx) {
if let Poll::Ready(()) = timeout.poll_unpin(cx) {
if let Some(frame) = session.set_inactive() {
self.outbound_buf.push_back(frame);
}

View file

@ -37,12 +37,6 @@ impl From<native_tls::Error> for Error {
}
}
impl From<tokio::time::Error> for Error {
fn from(e: tokio::time::Error) -> Self {
Error::Misc(Box::new(e))
}
}
impl From<rtp::Error> for Error {
fn from(e: rtp::Error) -> Self {
Error::Misc(Box::new(e))

View file

@ -21,7 +21,7 @@ use std::net::Ipv6Addr;
use std::net::ToSocketAddrs;
use tokio::net::TcpListener;
use tokio::net::TcpStream;
use tokio_tls::TlsConnector;
use tokio_native_tls::TlsConnector;
use tokio_tungstenite::accept_hdr_async_with_config;
use tokio_util::codec::Decoder;
use tungstenite::handshake::server::{ErrorResponse, Request, Response};
@ -179,7 +179,7 @@ async fn main() -> Result<(), Error> {
println!("Binding to port {}", ws_port);
let socket_addr = (Ipv6Addr::from(0), ws_port);
let mut server = TcpListener::bind(&socket_addr).await?;
let server = TcpListener::bind(&socket_addr).await?;
println!("Waiting for client connections..");
loop {
@ -212,6 +212,7 @@ async fn main() -> Result<(), Error> {
max_send_queue: Some(10), // can be fairly small as voice is using WebRTC instead
max_message_size: Some(0x7f_ffff), // maximum size accepted by Murmur
max_frame_size: Some(0x7f_ffff), // maximum size accepted by Murmur
accept_unmasked_frames: false, // browsers should comply with RFC 6455
};
fn header_callback(
_req: &Request,