aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/websocket_loader.rs
diff options
context:
space:
mode:
authortannal <149947508+tannal@users.noreply.github.com>2024-03-21 14:13:03 +0800
committerGitHub <noreply@github.com>2024-03-21 06:13:03 +0000
commit5c0199b5687a5c0c1b2fe82235ca609c7d9ea614 (patch)
tree87b9ede2b821c0c651d5b803358ae2c177330849 /components/net/websocket_loader.rs
parent2789e9887666a05695778bd9d822616985b40dbc (diff)
downloadservo-5c0199b5687a5c0c1b2fe82235ca609c7d9ea614.tar.gz
servo-5c0199b5687a5c0c1b2fe82235ca609c7d9ea614.zip
Net: fold websocket and http tokio runtime into one (#31771)
* net: use the same tokio runtime in websocket loader #31648 * readability * license
Diffstat (limited to 'components/net/websocket_loader.rs')
-rw-r--r--components/net/websocket_loader.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/components/net/websocket_loader.rs b/components/net/websocket_loader.rs
index 1fd2b4178cb..f50670ed914 100644
--- a/components/net/websocket_loader.rs
+++ b/components/net/websocket_loader.rs
@@ -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;
@@ -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;
@@ -39,19 +37,12 @@ use tungstenite::protocol::CloseFrame;
use tungstenite::Message;
use url::Url;
+use crate::async_runtime::HANDLE;
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()));
-}
-
/// Create a tungstenite Request object for the initial HTTP request.
/// This request contains `Origin`, `Sec-WebSocket-Protocol`, `Authorization`,
/// and `Cookie` headers as appropriate.