mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #20298 - Eijebong:websocket, r=nox
Bump servo-websocket to 0.21 <!-- 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/20298) <!-- Reviewable:end -->
This commit is contained in:
commit
5b575e3647
3 changed files with 39 additions and 25 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -1869,7 +1869,7 @@ dependencies = [
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo-websocket 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"servo-websocket 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2753,16 +2753,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servo-websocket"
|
name = "servo-websocket"
|
||||||
version = "0.20.0"
|
version = "0.21.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"openssl 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
"sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
@ -3943,7 +3942,7 @@ dependencies = [
|
||||||
"checksum servo-fontconfig-sys 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "38b494f03009ee81914b0e7d387ad7c145cafcd69747c2ec89b0e17bb94f303a"
|
"checksum servo-fontconfig-sys 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "38b494f03009ee81914b0e7d387ad7c145cafcd69747c2ec89b0e17bb94f303a"
|
||||||
"checksum servo-freetype-sys 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9232032c2e85118c0282c6562c84cab12316e655491ba0a5d1905b2320060d1b"
|
"checksum servo-freetype-sys 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9232032c2e85118c0282c6562c84cab12316e655491ba0a5d1905b2320060d1b"
|
||||||
"checksum servo-skia 0.30000013.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3fb707c7dc3d8a053b8c9d48ed9eb7f2a0c0751616dfbe3598f526948408bc33"
|
"checksum servo-skia 0.30000013.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3fb707c7dc3d8a053b8c9d48ed9eb7f2a0c0751616dfbe3598f526948408bc33"
|
||||||
"checksum servo-websocket 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efde78dfcf2178d5a11e1e2268e0d8df0627dfe2724546db8585d6678e1af150"
|
"checksum servo-websocket 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6bac1e2295e72f0525147d993c626761811acf0441dac1cee8707f12dc7f3363"
|
||||||
"checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c"
|
"checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c"
|
||||||
"checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a"
|
"checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a"
|
||||||
"checksum sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c6649e43c1a1e68d29ed56d0dc3b5b6cf3b901da77cf107c4066b9e3da036df5"
|
"checksum sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c6649e43c1a1e68d29ed56d0dc3b5b6cf3b901da77cf107c4066b9e3da036df5"
|
||||||
|
|
|
@ -35,7 +35,7 @@ serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
servo_url = {path = "../url"}
|
servo_url = {path = "../url"}
|
||||||
servo-websocket = "0.20"
|
servo-websocket = { version = "0.21", default-features = false, features = ["sync"] }
|
||||||
threadpool = "1.0"
|
threadpool = "1.0"
|
||||||
time = "0.1.17"
|
time = "0.1.17"
|
||||||
unicase = "1.4.0"
|
unicase = "1.4.0"
|
||||||
|
|
|
@ -26,11 +26,12 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use url::Position;
|
use url::Position;
|
||||||
use websocket::{Message, Receiver as WSReceiver, Sender as WSSender};
|
use websocket::Message;
|
||||||
use websocket::header::{Origin, WebSocketAccept, WebSocketKey, WebSocketProtocol, WebSocketVersion};
|
use websocket::header::{Origin, WebSocketAccept, WebSocketKey, WebSocketProtocol, WebSocketVersion};
|
||||||
use websocket::message::Type as MessageType;
|
use websocket::message::OwnedMessage;
|
||||||
use websocket::receiver::Receiver;
|
use websocket::receiver::{Reader as WsReader, Receiver as WsReceiver};
|
||||||
use websocket::sender::Sender;
|
use websocket::sender::{Sender as WsSender, Writer as WsWriter};
|
||||||
|
use websocket::ws::dataframe::DataFrame;
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
req_init: RequestInit,
|
req_init: RequestInit,
|
||||||
|
@ -60,7 +61,7 @@ pub fn init(
|
||||||
let ws_sender_incoming = ws_sender.clone();
|
let ws_sender_incoming = ws_sender.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
for message in receiver.incoming_messages() {
|
for message in receiver.incoming_messages() {
|
||||||
let message: Message = match message {
|
let message = match message {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("Error receiving incoming WebSocket message: {:?}", e);
|
debug!("Error receiving incoming WebSocket message: {:?}", e);
|
||||||
|
@ -68,21 +69,25 @@ pub fn init(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let message = match message.opcode {
|
let message = match message {
|
||||||
MessageType::Text => MessageData::Text(String::from_utf8_lossy(&message.payload).into_owned()),
|
OwnedMessage::Text(_) => {
|
||||||
MessageType::Binary => MessageData::Binary(message.payload.into_owned()),
|
MessageData::Text(String::from_utf8_lossy(&message.take_payload()).into_owned())
|
||||||
MessageType::Ping => {
|
},
|
||||||
let pong = Message::pong(message.payload);
|
OwnedMessage::Binary(_) => MessageData::Binary(message.take_payload()),
|
||||||
|
OwnedMessage::Ping(_) => {
|
||||||
|
let pong = Message::pong(message.take_payload());
|
||||||
ws_sender_incoming.lock().unwrap().send_message(&pong).unwrap();
|
ws_sender_incoming.lock().unwrap().send_message(&pong).unwrap();
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
MessageType::Pong => continue,
|
OwnedMessage::Pong(_) => continue,
|
||||||
MessageType::Close => {
|
OwnedMessage::Close(ref msg) => {
|
||||||
if !initiated_close_incoming.fetch_or(true, Ordering::SeqCst) {
|
if !initiated_close_incoming.fetch_or(true, Ordering::SeqCst) {
|
||||||
ws_sender_incoming.lock().unwrap().send_message(&message).unwrap();
|
ws_sender_incoming.lock().unwrap().send_message(&message).unwrap();
|
||||||
}
|
}
|
||||||
let code = message.cd_status_code;
|
let (code, reason) = match *msg {
|
||||||
let reason = String::from_utf8_lossy(&message.payload).into_owned();
|
None => (None, "".into()),
|
||||||
|
Some(ref data) => (Some(data.status_code), data.reason.clone())
|
||||||
|
};
|
||||||
let _ = resource_event_sender.send(WebSocketNetworkEvent::Close(code, reason));
|
let _ = resource_event_sender.send(WebSocketNetworkEvent::Close(code, reason));
|
||||||
break;
|
break;
|
||||||
},
|
},
|
||||||
|
@ -148,7 +153,7 @@ fn obtain_a_websocket_connection(url: &ServoUrl) -> Result<Stream, NetworkError>
|
||||||
fn establish_a_websocket_connection(
|
fn establish_a_websocket_connection(
|
||||||
req_init: RequestInit,
|
req_init: RequestInit,
|
||||||
http_state: &HttpState
|
http_state: &HttpState
|
||||||
) -> Result<(Option<String>, Sender<Stream>, Receiver<Stream>), NetworkError>
|
) -> Result<(Option<String>, WsWriter<HttpStream>, WsReader<HttpStream>), NetworkError>
|
||||||
{
|
{
|
||||||
let protocols = match req_init.mode {
|
let protocols = match req_init.mode {
|
||||||
RequestMode::WebSocket { protocols } => protocols.clone(),
|
RequestMode::WebSocket { protocols } => protocols.clone(),
|
||||||
|
@ -255,9 +260,19 @@ fn establish_a_websocket_connection(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let sender = Sender::new(response.writer, true);
|
let sender = WsSender::new(true);
|
||||||
let receiver = Receiver::new(response.reader, false);
|
let writer = WsWriter {
|
||||||
Ok((protocol_in_use, sender, receiver))
|
stream: response.writer,
|
||||||
|
sender
|
||||||
|
};
|
||||||
|
|
||||||
|
let receiver = WsReceiver::new(false);
|
||||||
|
let reader = WsReader {
|
||||||
|
stream: response.reader,
|
||||||
|
receiver,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((protocol_in_use, writer, reader))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Response {
|
struct Response {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue