2010-08-13 Fumitoshi Ukai <ukai@chromium.org>
authorukai@chromium.org <ukai@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Aug 2010 12:01:45 +0000 (12:01 +0000)
committerukai@chromium.org <ukai@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Aug 2010 12:01:45 +0000 (12:01 +0000)
        Reviewed by Alexey Proskuryakov.

        flaky websocket/tests/frame-length-overflow.html
        https://bugs.webkit.org/show_bug.cgi?id=43902

        Add m_shouldDiscardReceivedData flag to indicate it will no longer
        receive data from network.

        * websockets/WebSocketChannel.cpp:
        (WebCore::WebSocketChannel::WebSocketChannel):
        (WebCore::WebSocketChannel::didReceiveData):
        (WebCore::WebSocketChannel::didFail):
        (WebCore::WebSocketChannel::processBuffer):
        - when frame length overflows, we couldn't process data any more.
          clear buffer and mark m_shouldDiscardReceivedData true to make sure
          it doesn't process the same buffer again.
        * websockets/WebSocketChannel.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@65313 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/websockets/WebSocketChannel.cpp
WebCore/websockets/WebSocketChannel.h

index dd689ba..cec865d 100644 (file)
@@ -1,3 +1,23 @@
+2010-08-13  Fumitoshi Ukai  <ukai@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        flaky websocket/tests/frame-length-overflow.html
+        https://bugs.webkit.org/show_bug.cgi?id=43902
+
+        Add m_shouldDiscardReceivedData flag to indicate it will no longer
+        receive data from network.
+
+        * websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::WebSocketChannel):
+        (WebCore::WebSocketChannel::didReceiveData):
+        (WebCore::WebSocketChannel::didFail):
+        (WebCore::WebSocketChannel::processBuffer):
+        - when frame length overflows, we couldn't process data any more.
+          clear buffer and mark m_shouldDiscardReceivedData true to make sure
+          it doesn't process the same buffer again.
+        * websockets/WebSocketChannel.h:
+
 2010-08-13  Dirk Schulze  <krit@webkit.org>
 
         Reviewed by Nikolas Zimmermann.
index 47731cf..54be16a 100644 (file)
@@ -61,6 +61,7 @@ WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketCha
     , m_resumeTimer(this, &WebSocketChannel::resumeTimerFired)
     , m_suspended(false)
     , m_closed(false)
+    , m_shouldDiscardReceivedData(false)
     , m_unhandledBufferedAmount(0)
 {
 }
@@ -171,10 +172,14 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
         return;
     }
     if (!m_client) {
+        m_shouldDiscardReceivedData = true;
         handle->close();
         return;
     }
+    if (m_shouldDiscardReceivedData)
+        return;
     if (!appendToBuffer(data, len)) {
+        m_shouldDiscardReceivedData = true;
         handle->close();
         return;
     }
@@ -187,6 +192,7 @@ void WebSocketChannel::didFail(SocketStreamHandle* handle, const SocketStreamErr
 {
     LOG(Network, "WebSocketChannel %p didFail", this);
     ASSERT(handle == m_handle || !m_handle);
+    m_shouldDiscardReceivedData = true;
     handle->close();
 }
 
@@ -236,6 +242,8 @@ bool WebSocketChannel::processBuffer()
     ASSERT(!m_suspended);
     ASSERT(m_client);
     ASSERT(m_buffer);
+    if (m_shouldDiscardReceivedData)
+        return false;
 
     if (m_handshake.mode() == WebSocketHandshake::Incomplete) {
         int headerLength = m_handshake.readServerHandshake(m_buffer, m_bufferSize);
@@ -260,6 +268,7 @@ bool WebSocketChannel::processBuffer()
         }
         LOG(Network, "WebSocketChannel %p connection failed", this);
         skipBuffer(headerLength);
+        m_shouldDiscardReceivedData = true;
         if (!m_closed)
             m_handle->close();
         return false;
@@ -305,6 +314,8 @@ bool WebSocketChannel::processBuffer()
             errorFrame = true;
         }
         if (errorFrame) {
+            skipBuffer(m_bufferSize); // Save memory.
+            m_shouldDiscardReceivedData = true;
             m_client->didReceiveMessageError();
             if (!m_client)
                 return false;
index 06be50e..43d431a 100644 (file)
@@ -94,6 +94,7 @@ namespace WebCore {
         Timer<WebSocketChannel> m_resumeTimer;
         bool m_suspended;
         bool m_closed;
+        bool m_shouldDiscardReceivedData;
         unsigned long m_unhandledBufferedAmount;
     };