diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-05-28 07:36:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 07:36:12 -0400 |
commit | 96ac540a244eb28376c17cc424d53f0c72f6fba7 (patch) | |
tree | 272cc875162744c4f6bc6c877f30d9fa5fc8c356 /components/script | |
parent | 2ac916b5a1534a7dbd9c642d2031150d217a6f98 (diff) | |
parent | 1c35c44c35d41b3503f9402fb8771d71631cf0cb (diff) | |
download | servo-96ac540a244eb28376c17cc424d53f0c72f6fba7.tar.gz servo-96ac540a244eb28376c17cc424d53f0c72f6fba7.zip |
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 -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/websocket.rs | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 530d2ca6f76..5f783ab5a30 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -27,6 +27,7 @@ use crate::task_source::websocket::WebsocketTaskSource; use crate::task_source::TaskSource; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; +use ipc_channel::router::ROUTER; use js::jsapi::{JSAutoRealm, JSObject}; use js::jsval::UndefinedValue; use js::rust::CustomAutoRooterGuard; @@ -40,7 +41,6 @@ use servo_url::{ImmutableOrigin, ServoUrl}; use std::borrow::ToOwned; use std::cell::Cell; use std::ptr; -use std::thread; #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] enum WebSocketRequestState { @@ -216,42 +216,41 @@ impl WebSocket { let task_source = global.websocket_task_source(); let canceller = global.task_canceller(WebsocketTaskSource::NAME); - thread::spawn(move || { - while let Ok(event) = dom_event_receiver.recv() { - match event { - WebSocketNetworkEvent::ConnectionEstablished { protocol_in_use } => { - let open_thread = ConnectionEstablishedTask { - address: address.clone(), - protocol_in_use, - }; - task_source - .queue_with_canceller(open_thread, &canceller) - .unwrap(); - }, - WebSocketNetworkEvent::MessageReceived(message) => { - let message_thread = MessageReceivedTask { - address: address.clone(), - message: message, - }; - task_source - .queue_with_canceller(message_thread, &canceller) - .unwrap(); - }, - WebSocketNetworkEvent::Fail => { - fail_the_websocket_connection(address.clone(), &task_source, &canceller); - }, - WebSocketNetworkEvent::Close(code, reason) => { - close_the_websocket_connection( - address.clone(), - &task_source, - &canceller, - code, - reason, - ); - }, - } - } - }); + ROUTER.add_route( + dom_event_receiver.to_opaque(), + Box::new(move |message| match message.to().unwrap() { + WebSocketNetworkEvent::ConnectionEstablished { protocol_in_use } => { + let open_thread = ConnectionEstablishedTask { + address: address.clone(), + protocol_in_use, + }; + task_source + .queue_with_canceller(open_thread, &canceller) + .unwrap(); + }, + WebSocketNetworkEvent::MessageReceived(message) => { + let message_thread = MessageReceivedTask { + address: address.clone(), + message: message, + }; + task_source + .queue_with_canceller(message_thread, &canceller) + .unwrap(); + }, + WebSocketNetworkEvent::Fail => { + fail_the_websocket_connection(address.clone(), &task_source, &canceller); + }, + WebSocketNetworkEvent::Close(code, reason) => { + close_the_websocket_connection( + address.clone(), + &task_source, + &canceller, + code, + reason, + ); + }, + }), + ); // Step 7. Ok(ws) |