Auto merge of #23461 - TheOriginalAlex:issue-23408, r=jdm

Switched from using thread for websocket requests to ipc_channel::router::ROUTER

<!-- Please describe your changes on the following line: -->
Switched from using thread for websocket requests to ipc_channel::router::ROUTER

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #23408  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because the existing websocket tests should cover these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23461)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-05-28 07:36:12 -04:00 committed by GitHub
commit 96ac540a24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,7 @@ use crate::task_source::websocket::WebsocketTaskSource;
use crate::task_source::TaskSource; use crate::task_source::TaskSource;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::{JSAutoRealm, JSObject}; use js::jsapi::{JSAutoRealm, JSObject};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::rust::CustomAutoRooterGuard; use js::rust::CustomAutoRooterGuard;
@ -40,7 +41,6 @@ use servo_url::{ImmutableOrigin, ServoUrl};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
use std::ptr; use std::ptr;
use std::thread;
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)]
enum WebSocketRequestState { enum WebSocketRequestState {
@ -216,9 +216,9 @@ impl WebSocket {
let task_source = global.websocket_task_source(); let task_source = global.websocket_task_source();
let canceller = global.task_canceller(WebsocketTaskSource::NAME); let canceller = global.task_canceller(WebsocketTaskSource::NAME);
thread::spawn(move || { ROUTER.add_route(
while let Ok(event) = dom_event_receiver.recv() { dom_event_receiver.to_opaque(),
match event { Box::new(move |message| match message.to().unwrap() {
WebSocketNetworkEvent::ConnectionEstablished { protocol_in_use } => { WebSocketNetworkEvent::ConnectionEstablished { protocol_in_use } => {
let open_thread = ConnectionEstablishedTask { let open_thread = ConnectionEstablishedTask {
address: address.clone(), address: address.clone(),
@ -249,9 +249,8 @@ impl WebSocket {
reason, reason,
); );
}, },
} }),
} );
});
// Step 7. // Step 7.
Ok(ws) Ok(ws)