Skip to content

Commit

Permalink
net: use the same tokio runtime in websocket loader
Browse files Browse the repository at this point in the history
  • Loading branch information
tannal committed Mar 19, 2024
1 parent 96e5e77 commit 37e7f76
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions components/net/websocket_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! the need for a dedicated thread per websocket.

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::sync::Arc;

use async_tungstenite::tokio::{client_async_tls_with_connector_and_config, ConnectStream};
use async_tungstenite::WebSocketStream;
Expand All @@ -23,13 +23,11 @@ use futures::stream::StreamExt;
use http::header::{self, HeaderName, HeaderValue};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use lazy_static::lazy_static;
use log::{debug, trace, warn};
use net_traits::request::{RequestBuilder, RequestMode};
use net_traits::{CookieSource, MessageData, WebSocketDomAction, WebSocketNetworkEvent};
use servo_url::ServoUrl;
use tokio::net::TcpStream;
use tokio::runtime::Runtime;
use tokio::select;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use tokio_rustls::TlsConnector;
Expand All @@ -43,14 +41,7 @@ use crate::connector::{create_tls_config, CACertificates, TlsConfig};
use crate::cookie::Cookie;
use crate::fetch::methods::should_be_blocked_due_to_bad_port;
use crate::hosts::replace_host;
use crate::http_loader::HttpState;

// Websockets get their own tokio runtime that's independent of the one used for
// HTTP connections, otherwise a large number of websockets could occupy all workers
// and starve other network traffic.
lazy_static! {
pub static ref HANDLE: Mutex<Option<Runtime>> = Mutex::new(Some(Runtime::new().unwrap()));
}
use crate::http_loader::{HttpState, HANDLE};

/// Create a tungstenite Request object for the initial HTTP request.
/// This request contains `Origin`, `Sec-WebSocket-Protocol`, `Authorization`,
Expand Down

0 comments on commit 37e7f76

Please sign in to comment.