mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Remove WebSocket::sendCloseFrame.
It is a field that is used a function argument. Given that the control flow is not quite the same, and we can't add an argument to Send, I opted for a separate function.
This commit is contained in:
parent
2b0bdbe1c1
commit
cd741e681d
1 changed files with 11 additions and 17 deletions
|
@ -62,7 +62,6 @@ pub struct WebSocket {
|
|||
code: Cell<u16>, //Closing code
|
||||
reason: DOMRefCell<DOMString>, //Closing reason
|
||||
data: DOMRefCell<DOMString>, //Data from send - TODO: Remove after buffer is added.
|
||||
sendCloseFrame: Cell<bool>
|
||||
}
|
||||
|
||||
/// *Establish a WebSocket Connection* as defined in RFC 6455.
|
||||
|
@ -93,7 +92,6 @@ impl WebSocket {
|
|||
code: Cell::new(0),
|
||||
reason: DOMRefCell::new("".to_owned()),
|
||||
data: DOMRefCell::new("".to_owned()),
|
||||
sendCloseFrame: Cell::new(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -185,16 +183,20 @@ impl<'a> WebSocketMethods for &'a WebSocket {
|
|||
*/
|
||||
let mut other_sender = self.sender.borrow_mut();
|
||||
let my_sender = other_sender.as_mut().unwrap();
|
||||
if self.sendCloseFrame.get() { //TODO: Also check if the buffer is full
|
||||
self.sendCloseFrame.set(false);
|
||||
let _ = my_sender.send_message(Message::Close(None));
|
||||
return Ok(());
|
||||
}
|
||||
let _ = my_sender.send_message(Message::Text(data.unwrap().0));
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
fn Close(self, code: Option<u16>, reason: Option<USVString>) -> Fallible<()>{
|
||||
fn send_close(this: &WebSocket) {
|
||||
this.ready_state.set(WebSocketRequestState::Closing);
|
||||
|
||||
let mut sender = this.sender.borrow_mut();
|
||||
//TODO: Also check if the buffer is full
|
||||
let _ = sender.as_mut().unwrap().send_message(Message::Close(None));
|
||||
}
|
||||
|
||||
|
||||
if let Some(code) = code {
|
||||
//Check code is NOT 1000 NOR in the range of 3000-4999 (inclusive)
|
||||
if code != 1000 && (code < 3000 || code > 4999) {
|
||||
|
@ -212,13 +214,8 @@ impl<'a> WebSocketMethods for &'a WebSocket {
|
|||
WebSocketRequestState::Connecting => { //Connection is not yet established
|
||||
/*By setting the state to closing, the open function
|
||||
will abort connecting the websocket*/
|
||||
self.ready_state.set(WebSocketRequestState::Closing);
|
||||
self.failed.set(true);
|
||||
self.sendCloseFrame.set(true);
|
||||
//Dispatch send task to send close frame
|
||||
//TODO: Sending here is just empty string, though no string is really needed. Another send, empty
|
||||
// send, could be used.
|
||||
let _ = self.Send(None);
|
||||
send_close(self);
|
||||
//Note: After sending the close message, the receive loop confirms a close message from the server and
|
||||
// must fire a close event
|
||||
}
|
||||
|
@ -231,10 +228,7 @@ impl<'a> WebSocketMethods for &'a WebSocket {
|
|||
if let Some(reason) = reason {
|
||||
*self.reason.borrow_mut() = reason.0;
|
||||
}
|
||||
self.ready_state.set(WebSocketRequestState::Closing);
|
||||
self.sendCloseFrame.set(true);
|
||||
//Dispatch send task to send close frame
|
||||
let _ = self.Send(None);
|
||||
send_close(self);
|
||||
//Note: After sending the close message, the receive loop confirms a close message from the server and
|
||||
// must fire a close event
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue