From c51ab1223baa573bd74182b6679e89e4e205fa11 Mon Sep 17 00:00:00 2001 From: "loislo@chromium.org" Date: Mon, 26 Sep 2011 16:14:49 +0000 Subject: DevTools: web socket does not expect frames other than text. BUG=97974 TEST=none Review URL: http://codereview.chromium.org/8043023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102736 0039d316-1c4b-4281-b951-d872f2087c98 --- net/server/http_server.cc | 7 +++++-- net/server/web_socket.cc | 24 +++++++++++++++++++++--- net/server/web_socket.h | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/net/server/http_server.cc b/net/server/http_server.cc index 42d5752..6f2a46b 100644 --- a/net/server/http_server.cc +++ b/net/server/http_server.cc @@ -80,7 +80,9 @@ void HttpServer::Close(int connection_id) if (connection == NULL) return; - connection->DetachSocket(); + // Initiating close from server-side does not lead to the DidClose call. + // Do it manually here. + DidClose(connection->socket_); } // @@ -237,7 +239,8 @@ void HttpServer::DidRead(ListenSocket* socket, if (result == WebSocket::FRAME_INCOMPLETE) break; - if (result == WebSocket::FRAME_ERROR) { + if (result == WebSocket::FRAME_CLOSE || + result == WebSocket::FRAME_ERROR) { Close(connection->id()); break; } diff --git a/net/server/web_socket.cc b/net/server/web_socket.cc index de5e33a..2409e0c 100644 --- a/net/server/web_socket.cc +++ b/net/server/web_socket.cc @@ -223,7 +223,19 @@ class WebSocketHybi10 : public WebSocket { op_code_ = first_byte & kOpCodeMask; masked_ = second_byte & kMaskBit; - CHECK_EQ(kOpCodeText, op_code_); + switch (op_code_) { + case kOpCodeClose: + closed_ = true; + break; + case kOpCodeText: + break; + case kOpCodeBinary: // We don't support binary frames yet. + case kOpCodeContinuation: // We don't support binary frames yet. + case kOpCodePing: // We don't support binary frames yet. + case kOpCodePong: // We don't support binary frames yet. + default: + return FRAME_ERROR; + } uint64 payload_length64 = second_byte & kPayloadLengthMask; if (payload_length64 > kMaxSingleBytePayloadLength) { @@ -271,10 +283,14 @@ class WebSocketHybi10 : public WebSocket { size_t pos = p + masking_key_length + payload_length_ - connection_->recv_data().c_str(); connection_->Shift(pos); - return FRAME_OK; + + return closed_ ? FRAME_CLOSE : FRAME_OK; } virtual void Send(const std::string& message) { + if (closed_) + return; + std::vector frame; OpCode op_code = kOpCodeText; size_t data_length = message.length(); @@ -331,7 +347,8 @@ class WebSocketHybi10 : public WebSocket { masked_(false), payload_(0), payload_length_(0), - frame_end_(0) { + frame_end_(0), + closed_(false) { } OpCode op_code_; @@ -343,6 +360,7 @@ class WebSocketHybi10 : public WebSocket { const char* payload_; size_t payload_length_; const char* frame_end_; + bool closed_; DISALLOW_COPY_AND_ASSIGN(WebSocketHybi10); }; diff --git a/net/server/web_socket.h b/net/server/web_socket.h index baed07c..66ad789 100644 --- a/net/server/web_socket.h +++ b/net/server/web_socket.h @@ -21,6 +21,7 @@ class WebSocket { enum ParseResult { FRAME_OK, FRAME_INCOMPLETE, + FRAME_CLOSE, FRAME_ERROR }; -- cgit v1.1