summaryrefslogtreecommitdiffstats
path: root/net/websockets
diff options
context:
space:
mode:
authorukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-01 10:22:32 +0000
committerukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-01 10:22:32 +0000
commitd513d6ea5eec4773e299d2bae17e9159cebf0446 (patch)
treee170a5fea6b4b8a37c2037574cd221a925b43e3e /net/websockets
parentc4e9890a10fb35a78247be5d204d77f512d7654c (diff)
downloadchromium_src-d513d6ea5eec4773e299d2bae17e9159cebf0446.zip
chromium_src-d513d6ea5eec4773e299d2bae17e9159cebf0446.tar.gz
chromium_src-d513d6ea5eec4773e299d2bae17e9159cebf0446.tar.bz2
Fix regression of websocket/tests/simple-stress.html
Since stress-test.html tries to send 256K message, but we'll set 32K for max_pending_send_allowed in SocketStream. Thus, WebCore::SocketStreamHandle won't send full websocket frame for such large message since WebSocketJob doesn't notify OnSentData at all. Don't parse websocket frame for sending to avoid this issue for now. Also disable buffering and parsing websocket frame for receiving to fix performance regression. BUG=32018 TEST=LayoutTests/websocket/tests/stress-test.html passes Review URL: http://codereview.chromium.org/2453002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48629 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r--net/websockets/websocket_frame_handler.cc24
-rw-r--r--net/websockets/websocket_frame_handler.h4
-rw-r--r--net/websockets/websocket_frame_handler_unittest.cc6
-rw-r--r--net/websockets/websocket_job.cc20
4 files changed, 38 insertions, 16 deletions
diff --git a/net/websockets/websocket_frame_handler.cc b/net/websockets/websocket_frame_handler.cc
index a822652..5ac395e 100644
--- a/net/websockets/websocket_frame_handler.cc
+++ b/net/websockets/websocket_frame_handler.cc
@@ -26,7 +26,7 @@ void WebSocketFrameHandler::AppendData(const char* data, int length) {
pending_buffers_.push_back(buffer);
}
-int WebSocketFrameHandler::UpdateCurrentBuffer() {
+int WebSocketFrameHandler::UpdateCurrentBuffer(bool buffered) {
if (current_buffer_)
return 0;
DCHECK(!current_buffer_size_);
@@ -35,15 +35,22 @@ int WebSocketFrameHandler::UpdateCurrentBuffer() {
if (pending_buffers_.empty())
return 0;
scoped_refptr<IOBufferWithSize> buffer = pending_buffers_.front();
- std::vector<FrameInfo> frame_info;
- int buffer_size =
- ParseWebSocketFrame(buffer->data(), buffer->size(), &frame_info);
- if (buffer_size <= 0)
- return buffer_size;
- original_current_buffer_size_ = buffer_size;
+ int buffer_size = 0;
+ if (buffered) {
+ std::vector<FrameInfo> frame_info;
+ buffer_size =
+ ParseWebSocketFrame(buffer->data(), buffer->size(), &frame_info);
+ if (buffer_size <= 0)
+ return buffer_size;
+
+ original_current_buffer_size_ = buffer_size;
- // TODO(ukai): filter(e.g. compress or decompress) frame messages.
+ // TODO(ukai): filter(e.g. compress or decompress) frame messages.
+ } else {
+ original_current_buffer_size_ = buffer->size();
+ buffer_size = buffer->size();
+ }
current_buffer_ = buffer;
current_buffer_size_ = buffer_size;
@@ -63,6 +70,7 @@ void WebSocketFrameHandler::ReleaseCurrentBuffer() {
buffer_size += next_buffer->size();
pending_buffers_.pop_front();
}
+ // TODO(ukai): don't copy data.
scoped_refptr<IOBufferWithSize> buffer = new IOBufferWithSize(buffer_size);
memcpy(buffer->data(), front_buffer->data() + original_current_buffer_size_,
remaining_size);
diff --git a/net/websockets/websocket_frame_handler.h b/net/websockets/websocket_frame_handler.h
index df72e45..d6c38da 100644
--- a/net/websockets/websocket_frame_handler.h
+++ b/net/websockets/websocket_frame_handler.h
@@ -35,9 +35,11 @@ class WebSocketFrameHandler {
void AppendData(const char* data, int len);
// Updates current IOBuffer.
+ // If |buffered| is true, it tries to find WebSocket frames.
+ // Otherwise, it just picks the first buffer in |pending_buffers_|.
// Returns available size of data, 0 if no more data or current buffer was
// not released, and negative if some error occurred.
- int UpdateCurrentBuffer();
+ int UpdateCurrentBuffer(bool buffered);
// Gets current IOBuffer.
// For sending, this is data to network.
diff --git a/net/websockets/websocket_frame_handler_unittest.cc b/net/websockets/websocket_frame_handler_unittest.cc
index 80f0e59..52d70de 100644
--- a/net/websockets/websocket_frame_handler_unittest.cc
+++ b/net/websockets/websocket_frame_handler_unittest.cc
@@ -19,7 +19,7 @@ TEST(WebSocketFrameHandlerTest, Basic) {
scoped_ptr<WebSocketFrameHandler> handler(new WebSocketFrameHandler);
// No data.
- EXPECT_EQ(0, handler->UpdateCurrentBuffer());
+ EXPECT_EQ(0, handler->UpdateCurrentBuffer(true));
EXPECT_TRUE(handler->GetCurrentBuffer() == NULL);
EXPECT_EQ(0, handler->GetCurrentBufferSize());
@@ -27,7 +27,7 @@ TEST(WebSocketFrameHandlerTest, Basic) {
// or data is received from network (WebSocketJob::OnReceivedData)
handler->AppendData(kInputData, kInputDataLen);
EXPECT_TRUE(handler->GetCurrentBuffer() == NULL);
- EXPECT_GT(handler->UpdateCurrentBuffer(), 0);
+ EXPECT_GT(handler->UpdateCurrentBuffer(true), 0);
// Get data to send to the socket (send),
// or to send to WebKit (receive).
IOBuffer* buf = handler->GetCurrentBuffer();
@@ -40,7 +40,7 @@ TEST(WebSocketFrameHandlerTest, Basic) {
handler->ReleaseCurrentBuffer();
EXPECT_TRUE(handler->GetCurrentBuffer() == NULL);
EXPECT_EQ(0, handler->GetCurrentBufferSize());
- EXPECT_EQ(0, handler->UpdateCurrentBuffer());
+ EXPECT_EQ(0, handler->UpdateCurrentBuffer(true));
}
TEST(WebSocketFrameHandlerTest, ParseFrame) {
diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc
index c096d5c..063b3ab 100644
--- a/net/websockets/websocket_job.cc
+++ b/net/websockets/websocket_job.cc
@@ -174,9 +174,16 @@ bool WebSocketJob::SendData(const char* data, int len) {
send_frame_handler_->AppendData(data, len);
// If current buffer is sending now, this data will be sent in
// SendPending() after current data was sent.
+ // Do not buffer sending data for now. Since
+ // WebCore::SocketStreamHandle controls traffic to keep number of
+ // pending bytes less than max_pending_send_allowed, so when sending
+ // larger message than max_pending_send_allowed should not be buffered.
+ // If we don't call OnSentData, WebCore::SocketStreamHandle would stop
+ // sending more data when pending data reaches max_pending_send_allowed.
+ // TODO(ukai): Fix this to support compression for larger message.
int err = 0;
if (!send_frame_handler_->GetCurrentBuffer() &&
- (err = send_frame_handler_->UpdateCurrentBuffer()) > 0) {
+ (err = send_frame_handler_->UpdateCurrentBuffer(false)) > 0) {
current_buffer_ = new DrainableIOBuffer(
send_frame_handler_->GetCurrentBuffer(),
send_frame_handler_->GetCurrentBufferSize());
@@ -278,7 +285,9 @@ void WebSocketJob::OnReceivedData(
}
std::string received_data;
receive_frame_handler_->AppendData(data, len);
- while (receive_frame_handler_->UpdateCurrentBuffer() > 0) {
+ // Don't buffer receiving data for now.
+ // TODO(ukai): fix performance of WebSocketFrameHandler.
+ while (receive_frame_handler_->UpdateCurrentBuffer(false) > 0) {
received_data +=
std::string(receive_frame_handler_->GetCurrentBuffer()->data(),
receive_frame_handler_->GetCurrentBufferSize());
@@ -496,7 +505,9 @@ void WebSocketJob::SaveNextCookie() {
kResponseKeySize,
handshake_response_.size() - handshake_response_header_length_ -
kResponseKeySize);
- while (receive_frame_handler_->UpdateCurrentBuffer() > 0) {
+ // Don't buffer receiving data for now.
+ // TODO(ukai): fix performance of WebSocketFrameHandler.
+ while (receive_frame_handler_->UpdateCurrentBuffer(false) > 0) {
received_data +=
std::string(receive_frame_handler_->GetCurrentBuffer()->data(),
receive_frame_handler_->GetCurrentBufferSize());
@@ -596,7 +607,8 @@ void WebSocketJob::SendPending() {
if (current_buffer_)
return;
// Current buffer is done. Try next buffer if any.
- if (send_frame_handler_->UpdateCurrentBuffer() <= 0) {
+ // Don't buffer sending data. See comment on case OPEN in SendData().
+ if (send_frame_handler_->UpdateCurrentBuffer(false) <= 0) {
// No more data to send.
if (state_ == CLOSING)
socket_->Close();