2011-05-27 Sheriff Bot <webkit.review.bot@gmail.com>

        Unreviewed, rolling out r87464.
        http://trac.webkit.org/changeset/87464
        https://bugs.webkit.org/show_bug.cgi?id=61643

        client-close/server-close tests are flaky on Chromium Mac and
        Windows (Requested by aklein on #webkit).

        * http/tests/websocket/tests/client-close-expected.txt: Removed.
        * http/tests/websocket/tests/client-close.html: Removed.
        * http/tests/websocket/tests/client-close_wsh.py: Removed.
        * http/tests/websocket/tests/close-before-open-expected.txt:
        * http/tests/websocket/tests/close-event-expected.txt:
        * http/tests/websocket/tests/close-event.html:
        * http/tests/websocket/tests/close-unref-websocket-expected.txt:
        * http/tests/websocket/tests/frame-length-longer-than-buffer_wsh.py:
        * http/tests/websocket/tests/server-close-expected.txt: Removed.
        * http/tests/websocket/tests/server-close.html: Removed.
        * http/tests/websocket/tests/server-close_wsh.py: Removed.
        * http/tests/websocket/tests/websocket-event-target-expected.txt:
2011-05-27  Sheriff Bot  <webkit.review.bot@gmail.com>

        Unreviewed, rolling out r87464.
        http://trac.webkit.org/changeset/87464
        https://bugs.webkit.org/show_bug.cgi?id=61643

        client-close/server-close tests are flaky on Chromium Mac and
        Windows (Requested by aklein on #webkit).

        * platform/network/SocketStreamHandleBase.cpp:
        (WebCore::SocketStreamHandleBase::send):
        (WebCore::SocketStreamHandleBase::close):
        (WebCore::SocketStreamHandleBase::sendPendingData):
        * platform/network/SocketStreamHandleBase.h:
        * websockets/ThreadableWebSocketChannelClientWrapper.cpp:
        (WebCore::ThreadableWebSocketChannelClientWrapper::didClose):
        (WebCore::ThreadableWebSocketChannelClientWrapper::didCloseCallback):
        * websockets/ThreadableWebSocketChannelClientWrapper.h:
        * websockets/WebSocket.cpp:
        (WebCore::WebSocket::send):
        (WebCore::WebSocket::close):
        (WebCore::WebSocket::bufferedAmount):
        (WebCore::WebSocket::didConnect):
        (WebCore::WebSocket::didReceiveMessage):
        (WebCore::WebSocket::didReceiveMessageError):
        (WebCore::WebSocket::didClose):
        * websockets/WebSocket.h:
        * websockets/WebSocketChannel.cpp:
        (WebCore::WebSocketChannel::WebSocketChannel):
        (WebCore::WebSocketChannel::close):
        (WebCore::WebSocketChannel::disconnect):
        (WebCore::WebSocketChannel::didClose):
        (WebCore::WebSocketChannel::didReceiveData):
        (WebCore::WebSocketChannel::didFail):
        (WebCore::WebSocketChannel::processBuffer):
        * websockets/WebSocketChannel.h:
        * websockets/WebSocketChannelClient.h:
        (WebCore::WebSocketChannelClient::didClose):
        * websockets/WorkerThreadableWebSocketChannel.cpp:
        (WebCore::WorkerThreadableWebSocketChannel::Peer::close):
        (WebCore::workerContextDidClose):
        (WebCore::WorkerThreadableWebSocketChannel::Peer::didClose):
        * websockets/WorkerThreadableWebSocketChannel.h:
2011-05-27  Sheriff Bot  <webkit.review.bot@gmail.com>

        Unreviewed, rolling out r87464.
        http://trac.webkit.org/changeset/87464
        https://bugs.webkit.org/show_bug.cgi?id=61643

        client-close/server-close tests are flaky on Chromium Mac and
        Windows (Requested by aklein on #webkit).

        * Scripts/webkitpy/thirdparty/__init__.py:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@87519 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5645d163
2011-05-27 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r87464.
http://trac.webkit.org/changeset/87464
https://bugs.webkit.org/show_bug.cgi?id=61643
client-close/server-close tests are flaky on Chromium Mac and
Windows (Requested by aklein on #webkit).
* http/tests/websocket/tests/client-close-expected.txt: Removed.
* http/tests/websocket/tests/client-close.html: Removed.
* http/tests/websocket/tests/client-close_wsh.py: Removed.
* http/tests/websocket/tests/close-before-open-expected.txt:
* http/tests/websocket/tests/close-event-expected.txt:
* http/tests/websocket/tests/close-event.html:
* http/tests/websocket/tests/close-unref-websocket-expected.txt:
* http/tests/websocket/tests/frame-length-longer-than-buffer_wsh.py:
* http/tests/websocket/tests/server-close-expected.txt: Removed.
* http/tests/websocket/tests/server-close.html: Removed.
* http/tests/websocket/tests/server-close_wsh.py: Removed.
* http/tests/websocket/tests/websocket-event-target-expected.txt:
2011-05-27 Rob Buis <rbuis@rim.com>
Reviewed by Nikolas Zimmermann.
WebSocket: Test client-initiated close.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Connected
Closed
PASS closeEvent.wasClean is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../../js-test-resources/js-test-style.css">
<script src="../../../js-test-resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("WebSocket: Test client-initiated close.");
window.jsTestIsAsync = true;
var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/client-close");
var closeEvent;
ws.onopen = function()
{
debug("Connected");
ws.close();
};
ws.onmessage = function(messageEvent)
{
debug("Received: " + messageEvent.data);
};
ws.onclose = function(event)
{
debug("Closed");
closeEvent = event;
shouldBeTrue("closeEvent.wasClean");
finishJSTest();
};
var successfullyParsed = true;
</script>
<script src="../../../js-test-resources/js-test-post.js"></script>
</body>
</html>
from mod_pywebsocket import msgutil
def web_socket_do_extra_handshake(request):
pass
def web_socket_transfer_data(request):
# Wait for a close frame sent from the client.
close_frame = request.ws_stream.receive_bytes(2)
# If the following assertion fails, AssertionError will be raised,
# which will prevent pywebsocket from sending a close frame.
# In this case, the client will fail to finish closing handshake, thus
# closeEvent.wasClean will become false.
assert close_frame == '\xff\x00'
# Pretend we have received a close frame from the client.
# After this function exits, pywebsocket will send a close frame automatically.
request.client_terminated = True
CONSOLE MESSAGE: line 0: WebSocket is closed before the connection is established.
Test if Web Socket fires close event when WebSocket is opened and closed fore open event is received.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
......@@ -7,7 +7,6 @@ Received: 'Hello from Simple WSH.'
Closed
PASS closeEventType is "close"
PASS 'wasClean' in closeEvent is true
PASS closeEvent.wasClean is true
PASS Object.getPrototypeOf(closeEvent) === CloseEvent.prototype is true
PASS Object.getPrototypeOf(closeEvent) !== Event.prototype is true
PASS successfullyParsed is true
......
......@@ -33,7 +33,6 @@ ws.onclose = function(event)
closeEventType = closeEvent.type;
shouldBe("closeEventType", '"close"')
shouldBeTrue("'wasClean' in closeEvent");
shouldBeTrue("closeEvent.wasClean");
shouldBeTrue("Object.getPrototypeOf(closeEvent) === CloseEvent.prototype");
shouldBeTrue("Object.getPrototypeOf(closeEvent) !== Event.prototype");
finishJSTest();
......
CONSOLE MESSAGE: line 0: WebSocket is closed before the connection is established.
Test if Web Socket is closed while handshaking and unreferenced, it should fire close event at most once.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
def web_socket_do_extra_handshake(request):
pass
pass
def web_socket_transfer_data(request):
msg = "\0hello\xff"
msg += "\x80\x81\x01" # Skip 1*128+1 bytes.
msg += "\x01\xff"
msg += "\0should be skipped\xff"
request.connection.write(msg)
raise Exception("Abort the connection") # Prevents pywebsocket from starting closing handshake.
msg = "\0hello\xff"
msg += "\x80\x81\x01" # skip 1*128+1 bytes.
msg += "\x01\xff"
msg += "\0should be skipped\xff"
request.connection.write(msg)
print msg
WebSocket: Test server-initiated close.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Connected
Closed
PASS closeEvent.wasClean is true
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../../js-test-resources/js-test-style.css">
<script src="../../../js-test-resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("WebSocket: Test server-initiated close.");
window.jsTestIsAsync = true;
var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/server-close");
var closeEvent;
ws.onopen = function()
{
debug("Connected");
};
ws.onmessage = function(messageEvent)
{
debug("Received: " + messageEvent.data);
};
ws.onclose = function(event)
{
debug("Closed");
closeEvent = event;
shouldBeTrue("closeEvent.wasClean");
finishJSTest();
};
var successfullyParsed = true;
</script>
<script src="../../../js-test-resources/js-test-post.js"></script>
</body>
</html>
def web_socket_do_extra_handshake(request):
pass
def web_socket_transfer_data(request):
# After this handler exits, pywebsocket initiates the closing handshake.
pass
CONSOLE MESSAGE: line 0: WebSocket is closed before the connection is established.
Make sure WebSocket object acts as EventTarget.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
2011-05-27 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r87464.
http://trac.webkit.org/changeset/87464
https://bugs.webkit.org/show_bug.cgi?id=61643
client-close/server-close tests are flaky on Chromium Mac and
Windows (Requested by aklein on #webkit).
* platform/network/SocketStreamHandleBase.cpp:
(WebCore::SocketStreamHandleBase::send):
(WebCore::SocketStreamHandleBase::close):
(WebCore::SocketStreamHandleBase::sendPendingData):
* platform/network/SocketStreamHandleBase.h:
* websockets/ThreadableWebSocketChannelClientWrapper.cpp:
(WebCore::ThreadableWebSocketChannelClientWrapper::didClose):
(WebCore::ThreadableWebSocketChannelClientWrapper::didCloseCallback):
* websockets/ThreadableWebSocketChannelClientWrapper.h:
* websockets/WebSocket.cpp:
(WebCore::WebSocket::send):
(WebCore::WebSocket::close):
(WebCore::WebSocket::bufferedAmount):
(WebCore::WebSocket::didConnect):
(WebCore::WebSocket::didReceiveMessage):
(WebCore::WebSocket::didReceiveMessageError):
(WebCore::WebSocket::didClose):
* websockets/WebSocket.h:
* websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::WebSocketChannel):
(WebCore::WebSocketChannel::close):
(WebCore::WebSocketChannel::disconnect):
(WebCore::WebSocketChannel::didClose):
(WebCore::WebSocketChannel::didReceiveData):
(WebCore::WebSocketChannel::didFail):
(WebCore::WebSocketChannel::processBuffer):
* websockets/WebSocketChannel.h:
* websockets/WebSocketChannelClient.h:
(WebCore::WebSocketChannelClient::didClose):
* websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::Peer::close):
(WebCore::workerContextDidClose):
(WebCore::WorkerThreadableWebSocketChannel::Peer::didClose):
* websockets/WorkerThreadableWebSocketChannel.h:
2011-05-27 Rob Buis <rbuis@rim.com>
Reviewed by Nikolas Zimmermann.
......@@ -52,7 +52,7 @@ SocketStreamHandleBase::SocketStreamState SocketStreamHandleBase::state() const
bool SocketStreamHandleBase::send(const char* data, int length)
{
if (m_state == Connecting || m_state == Closing)
if (m_state == Connecting)
return false;
if (!m_buffer.isEmpty()) {
if (m_buffer.size() + length > bufferSize) {
......@@ -77,16 +77,6 @@ bool SocketStreamHandleBase::send(const char* data, int length)
}
void SocketStreamHandleBase::close()
{
if (m_state == Closed)
return;
m_state = Closing;
if (!m_buffer.isEmpty())
return;
disconnect();
}
void SocketStreamHandleBase::disconnect()
{
RefPtr<SocketStreamHandle> protect(static_cast<SocketStreamHandle*>(this)); // platformClose calls the client, which may make the handle get deallocated immediately.
......@@ -102,16 +92,10 @@ void SocketStreamHandleBase::setClient(SocketStreamHandleClient* client)
bool SocketStreamHandleBase::sendPendingData()
{
if (m_state != Open && m_state != Closing)
if (m_state != Open)
return false;
if (m_buffer.isEmpty())
return false;
if (m_buffer.isEmpty()) {
if (m_state == Open)
return false;
if (m_state == Closing) {
disconnect();
return false;
}
}
int bytesWritten = platformSend(m_buffer.data(), m_buffer.size());
if (bytesWritten <= 0)
return false;
......
......@@ -48,8 +48,7 @@ namespace WebCore {
SocketStreamState state() const;
bool send(const char* data, int length);
void close(); // Disconnect after all data in buffer are sent.
void disconnect();
void close();
int bufferedAmount() const { return m_buffer.size(); }
SocketStreamHandleClient* client() const { return m_client; }
......
......@@ -110,16 +110,9 @@ void ThreadableWebSocketChannelClientWrapper::didReceiveMessage(const String& me
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didStartClosingHandshake()
void ThreadableWebSocketChannelClientWrapper::didClose(unsigned long unhandledBufferedAmount)
{
m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didStartClosingHandshakeCallback, AllowCrossThreadAccess(this)));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didClose(unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closingHandshakeCompletion)
{
m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didCloseCallback, AllowCrossThreadAccess(this), unhandledBufferedAmount, closingHandshakeCompletion));
m_pendingTasks.append(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::didCloseCallback, AllowCrossThreadAccess(this), unhandledBufferedAmount));
if (!m_suspended)
processPendingTasks();
}
......@@ -158,18 +151,11 @@ void ThreadableWebSocketChannelClientWrapper::didReceiveMessageCallback(ScriptEx
wrapper->m_client->didReceiveMessage(message);
}
void ThreadableWebSocketChannelClientWrapper::didStartClosingHandshakeCallback(ScriptExecutionContext* context, RefPtr<ThreadableWebSocketChannelClientWrapper> wrapper)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didStartClosingHandshake();
}
void ThreadableWebSocketChannelClientWrapper::didCloseCallback(ScriptExecutionContext* context, RefPtr<ThreadableWebSocketChannelClientWrapper> wrapper, unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closingHandshakeCompletion)
void ThreadableWebSocketChannelClientWrapper::didCloseCallback(ScriptExecutionContext* context, RefPtr<ThreadableWebSocketChannelClientWrapper> wrapper, unsigned long unhandledBufferedAmount)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didClose(unhandledBufferedAmount, closingHandshakeCompletion);
wrapper->m_client->didClose(unhandledBufferedAmount);
}
} // namespace WebCore
......
......@@ -35,7 +35,6 @@
#include "PlatformString.h"
#include "ScriptExecutionContext.h"
#include "WebSocketChannelClient.h"
#include <wtf/Forward.h>
#include <wtf/OwnPtr.h>
#include <wtf/Threading.h>
......@@ -63,8 +62,7 @@ public:
void didConnect();
void didReceiveMessage(const String& message);
void didStartClosingHandshake();
void didClose(unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus);
void didClose(unsigned long unhandledBufferedAmount);
void suspend();
void resume();
......@@ -75,8 +73,7 @@ protected:
void processPendingTasks();
static void didConnectCallback(ScriptExecutionContext*, RefPtr<ThreadableWebSocketChannelClientWrapper>);
static void didReceiveMessageCallback(ScriptExecutionContext*, RefPtr<ThreadableWebSocketChannelClientWrapper>, String message);
static void didStartClosingHandshakeCallback(ScriptExecutionContext*, RefPtr<ThreadableWebSocketChannelClientWrapper>);
static void didCloseCallback(ScriptExecutionContext*, RefPtr<ThreadableWebSocketChannelClientWrapper>, unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus);
static void didCloseCallback(ScriptExecutionContext*, RefPtr<ThreadableWebSocketChannelClientWrapper>, unsigned long unhandledBufferedAmount);
WebSocketChannelClient* m_client;
bool m_syncMethodDone;
......
......@@ -164,7 +164,7 @@ bool WebSocket::send(const String& message, ExceptionCode& ec)
return false;
}
// No exception is raised if the connection was once established but has subsequently been closed.
if (m_state == CLOSING || m_state == CLOSED) {
if (m_state == CLOSED) {
m_bufferedAmountAfterClose += message.utf8().length() + 2; // 2 for frameing
return false;
}
......@@ -176,14 +176,9 @@ bool WebSocket::send(const String& message, ExceptionCode& ec)
void WebSocket::close()
{
LOG(Network, "WebSocket %p close", this);
if (m_state == CLOSING || m_state == CLOSED)
if (m_state == CLOSED)
return;
if (m_state == CONNECTING) {
m_state = CLOSING;
m_channel->fail("WebSocket is closed before the connection is established.");
return;
}
m_state = CLOSING;
m_state = CLOSED;
m_bufferedAmountAfterClose = m_channel->bufferedAmount();
// didClose notification may be already queued, which we will inadvertently process while waiting for bufferedAmount() to return.
// In this case m_channel will be set to null during didClose() call, thus we need to test validness of m_channel here.
......@@ -205,8 +200,6 @@ unsigned long WebSocket::bufferedAmount() const
{
if (m_state == OPEN)
return m_channel->bufferedAmount();
else if (m_state == CLOSING)
return m_channel->bufferedAmount() + m_bufferedAmountAfterClose;
return m_bufferedAmountAfterClose;
}
......@@ -256,7 +249,7 @@ void WebSocket::didConnect()
{
LOG(Network, "WebSocket %p didConnect", this);
if (m_state != CONNECTING) {
didClose(0, ClosingHandshakeIncomplete);
didClose(0);
return;
}
ASSERT(scriptExecutionContext());
......@@ -267,7 +260,7 @@ void WebSocket::didConnect()
void WebSocket::didReceiveMessage(const String& msg)
{
LOG(Network, "WebSocket %p didReceiveMessage %s", this, msg.utf8().data());
if (m_state != OPEN && m_state != CLOSING)
if (m_state != OPEN)
return;
ASSERT(scriptExecutionContext());
RefPtr<MessageEvent> evt = MessageEvent::create();
......@@ -278,29 +271,22 @@ void WebSocket::didReceiveMessage(const String& msg)
void WebSocket::didReceiveMessageError()
{
LOG(Network, "WebSocket %p didReceiveErrorMessage", this);
if (m_state != OPEN && m_state != CLOSING)
if (m_state != OPEN)
return;
ASSERT(scriptExecutionContext());
dispatchEvent(Event::create(eventNames().errorEvent, false, false));
}
void WebSocket::didStartClosingHandshake()
{
LOG(Network, "WebSocket %p didStartClosingHandshake", this);
m_state = CLOSING;
}
void WebSocket::didClose(unsigned long unhandledBufferedAmount, ClosingHandshakeCompletionStatus closingHandshakeCompletion)
void WebSocket::didClose(unsigned long unhandledBufferedAmount)
{
LOG(Network, "WebSocket %p didClose", this);
if (!m_channel)
return;
bool wasClean = m_state == CLOSING && !unhandledBufferedAmount && closingHandshakeCompletion == ClosingHandshakeComplete;
m_state = CLOSED;
m_bufferedAmountAfterClose += unhandledBufferedAmount;
ASSERT(scriptExecutionContext());
RefPtr<CloseEvent> event = CloseEvent::create(false);
event->initCloseEvent(eventNames().closeEvent, false, false, wasClean);
event->initCloseEvent(eventNames().closeEvent, false, false, false);
dispatchEvent(event);
if (m_channel) {
m_channel->disconnect();
......
......@@ -95,8 +95,7 @@ namespace WebCore {
virtual void didConnect();
virtual void didReceiveMessage(const String& message);
virtual void didReceiveMessageError();
virtual void didStartClosingHandshake();
virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHandshakeCompletionStatus);
virtual void didClose(unsigned long unhandledBufferedAmount);
private:
WebSocket(ScriptExecutionContext*);
......
......@@ -56,8 +56,6 @@
namespace WebCore {
const double TCPMaximumSegmentLifetime = 2 * 60.0;
WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client, const KURL& url, const String& protocol)
: m_context(context)
, m_client(client)
......@@ -66,9 +64,6 @@ WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketCha
, m_bufferSize(0)
, m_resumeTimer(this, &WebSocketChannel::resumeTimerFired)
, m_suspended(false)
, m_closing(false)
, m_receivedClosingHandshake(false)
, m_closingTimer(this, &WebSocketChannel::closingTimerFired)
, m_closed(false)
, m_shouldDiscardReceivedData(false)
, m_unhandledBufferedAmount(0)
......@@ -122,11 +117,8 @@ void WebSocketChannel::close()
{
LOG(Network, "WebSocketChannel %p close", this);
ASSERT(!m_suspended);
if (!m_handle)
return;
startClosingHandshake();
if (m_closing && !m_closingTimer.isActive())
m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime);
if (m_handle)
m_handle->close(); // will call didClose()
}
void WebSocketChannel::fail(const String& reason)
......@@ -148,7 +140,7 @@ void WebSocketChannel::disconnect()
m_client = 0;
m_context = 0;
if (m_handle)
m_handle->disconnect();
m_handle->close();
}
void WebSocketChannel::suspend()
......@@ -183,8 +175,6 @@ void WebSocketChannel::didClose(SocketStreamHandle* handle)
InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
ASSERT_UNUSED(handle, handle == m_handle || !m_handle);
m_closed = true;
if (m_closingTimer.isActive())
m_closingTimer.stop();
if (m_handle) {
m_unhandledBufferedAmount = m_handle->bufferedAmount();
if (m_suspended)
......@@ -194,7 +184,7 @@ void WebSocketChannel::didClose(SocketStreamHandle* handle)
m_context = 0;
m_handle = 0;
if (client)
client->didClose(m_unhandledBufferedAmount, m_receivedClosingHandshake ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketChannelClient::ClosingHandshakeIncomplete);
client->didClose(m_unhandledBufferedAmount);
}
deref();
}
......@@ -207,13 +197,9 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
if (!m_context) {
return;
}
if (len <= 0) {
handle->disconnect();
return;
}
if (!m_client) {
m_shouldDiscardReceivedData = true;
handle->disconnect();
handle->close();
return;
}
if (m_shouldDiscardReceivedData)
......@@ -247,7 +233,7 @@ void WebSocketChannel::didFail(SocketStreamHandle* handle, const SocketStreamErr
m_context->addMessage(OtherMessageSource, NetworkErrorMessageType, ErrorMessageLevel, message, 0, failingURL, 0);
}
m_shouldDiscardReceivedData = true;
handle->disconnect();
handle->close();
}
void WebSocketChannel::didReceiveAuthenticationChallenge(SocketStreamHandle*, const AuthenticationChallenge&)
......@@ -295,18 +281,9 @@ bool WebSocketChannel::processBuffer()
ASSERT(!m_suspended);
ASSERT(m_client);
ASSERT(m_buffer);
LOG(Network, "WebSocketChannel %p processBuffer %lu", this, static_cast<unsigned long>(m_bufferSize));
if (m_shouldDiscardReceivedData)
return false;
if (m_receivedClosingHandshake) {
skipBuffer(m_bufferSize);
return false;
}
RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference.
if (m_handshake.mode() == WebSocketHandshake::Incomplete) {
int headerLength = m_handshake.readServerHandshake(m_buffer, m_bufferSize);
if (headerLength <= 0)
......@@ -334,7 +311,7 @@ bool WebSocketChannel::processBuffer()
skipBuffer(headerLength);
m_shouldDiscardReceivedData = true;
if (!m_closed)
m_handle->disconnect();
m_handle->close();
return false;
}
if (m_handshake.mode() != WebSocketHandshake::Connected)
......@@ -385,18 +362,12 @@ bool WebSocketChannel::processBuffer()
return false;
}
ASSERT(p + length >= p);
if (p + length <= end) {
if (p + length < end) {
p += length;
nextFrame = p;
ASSERT(nextFrame > m_buffer);
skipBuffer(nextFrame - m_buffer);
if (frameByte == 0xff && !length) {
m_receivedClosingHandshake = true;
startClosingHandshake();
if (m_closing)
m_handle->close(); // close after sending FF 00.
} else
m_client->didReceiveMessageError();
m_client->didReceiveMessageError();
return m_buffer;
}
return false;
......@@ -434,32 +405,6 @@ void WebSocketChannel::resumeTimerFired(Timer<WebSocketChannel>* timer)
didClose(m_handle.get());
}
void WebSocketChannel::startClosingHandshake()