aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/websocket.rs
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2015-07-14 18:14:00 +0200
committerMs2ger <ms2ger@gmail.com>2015-07-16 12:43:08 +0200
commitcd741e681d0a3dd3a90e4ee906dabf75b2926e08 (patch)
treec21bc6f1a492127b4afe69dda060a6c17bc78ef5 /components/script/dom/websocket.rs
parent2b0bdbe1c195f2f6dd7671981999d622c505fbc5 (diff)
downloadservo-cd741e681d0a3dd3a90e4ee906dabf75b2926e08.tar.gz
servo-cd741e681d0a3dd3a90e4ee906dabf75b2926e08.zip
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.
Diffstat (limited to 'components/script/dom/websocket.rs')
-rw-r--r--components/script/dom/websocket.rs28
1 files changed, 11 insertions, 17 deletions
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs
index 8db290c3a69..bad0e1a8e7f 100644
--- a/components/script/dom/websocket.rs
+++ b/components/script/dom/websocket.rs
@@ -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
}