Commit f038b753 authored by yael.aharon@nokia.com's avatar yael.aharon@nokia.com

[Qt] WebSockets : Buffer the data in WebKit instead of QtNetwork

https://bugs.webkit.org/show_bug.cgi?id=34425

Reviewed by Kenneth Rohde Christiansen.

Buffer the sent data in SocketStreamHandlePrivate instead of relying on
the network layer to do it. This is more robust and more consistent with how 
Qt's HTTP stack works.
Close the socket in SocketStreamHandlePrivate::close() regardless of its state.

No new tests, since no new functionality is introduced.

* platform/network/qt/SocketStreamHandlePrivate.h:
* platform/network/qt/SocketStreamHandleQt.cpp:


git-svn-id: svn://svn.chromium.org/blink/trunk@54279 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 51387b81
2010-02-02 Yael Aharon <yael.aharon@nokia.com>
Reviewed by Kenneth Rohde Christiansen.
[Qt] WebSockets : Buffer the data in WebKit instead of QtNetwork
https://bugs.webkit.org/show_bug.cgi?id=34425
Buffer the sent data in SocketStreamHandlePrivate instead of relying on
the network layer to do it. This is more robust and more consistent with how
Qt's HTTP stack works.
Close the socket in SocketStreamHandlePrivate::close() regardless of its state.
No new tests, since no new functionality is introduced.
* platform/network/qt/SocketStreamHandlePrivate.h:
* platform/network/qt/SocketStreamHandleQt.cpp:
(WebCore::SocketStreamHandlePrivate::SocketStreamHandlePrivate):
(WebCore::SocketStreamHandlePrivate::send):
(WebCore::SocketStreamHandlePrivate::close):
(WebCore::SocketStreamHandlePrivate::socketBytesWritten):
2010-02-03 Shinichiro Hamaji <hamaji@chromium.org>
Unreviewed revert of r54259 as it seems to break chromium's unit tests.
......
......@@ -55,6 +55,7 @@ public slots:
int send(const char* data, int len);
void close();
void socketSentdata();
void socketBytesWritten(qint64);
void socketClosed();
void socketError(QAbstractSocket::SocketError);
void socketClosedCallback();
......@@ -65,6 +66,7 @@ public slots:
public:
QTcpSocket* m_socket;
SocketStreamHandle* m_streamHandle;
QByteArray m_data;
};
}
......
......@@ -56,7 +56,15 @@ SocketStreamHandlePrivate::SocketStreamHandlePrivate(SocketStreamHandle* streamH
if (!m_socket)
return;
connect(m_socket, SIGNAL(connected()), this, SLOT(socketConnected()));
if (isSecure) {
#ifndef QT_NO_OPENSSL
connect(m_socket, SIGNAL(encrypted()), this, SLOT(socketConnected()));
connect(m_socket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(socketBytesWritten(qint64)));
#endif
} else {
connect(m_socket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(m_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(socketBytesWritten(qint64)));
}
connect(m_socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
connect(m_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
......@@ -99,14 +107,17 @@ int SocketStreamHandlePrivate::send(const char* data, int len)
{
if (!m_socket || m_socket->state() != QAbstractSocket::ConnectedState)
return 0;
quint64 sentSize = m_socket->write(data, len);
QMetaObject::invokeMethod(this, "socketSentData", Qt::QueuedConnection);
return sentSize;
// If we are already sending something, then m_data is not empty.
bool sending = m_data.length() > 0;
m_data.append(data, len);
if (!sending)
m_socket->write(m_data);
return len;
}
void SocketStreamHandlePrivate::close()
{
if (m_socket && m_socket->state() == QAbstractSocket::ConnectedState)
if (m_socket)
m_socket->close();
}
......@@ -116,6 +127,18 @@ void SocketStreamHandlePrivate::socketSentdata()
m_streamHandle->sendPendingData();
}
void SocketStreamHandlePrivate::socketBytesWritten(qint64 written)
{
if (!m_socket || m_socket->state() != QAbstractSocket::ConnectedState || written < 0)
return;
m_data.remove(0, written);
// If we are done sending all the data, then m_data is now empty
if (m_data.isEmpty())
QMetaObject::invokeMethod(this, "socketSentdata", Qt::QueuedConnection);
else
m_socket->write(m_data);
}
void SocketStreamHandlePrivate::socketClosed()
{
QMetaObject::invokeMethod(this, "socketClosedCallback", Qt::QueuedConnection);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment