diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2013-03-28 16:56:04 +0100 |
---|---|---|
committer | Pierre Rossi <pierre.rossi@gmail.com> | 2013-11-01 13:57:50 +0100 |
commit | f87c2bec8de9d6ba84f6c03655cd71851592092a (patch) | |
tree | b691b41cc526620474b48ca62bf902d1436af5b2 | |
parent | d1af727765c3b0dbc3dc91e8d672e9c4142b0170 (diff) | |
download | qtwebchannel-f87c2bec8de9d6ba84f6c03655cd71851592092a.tar.gz |
Add support for websocket ping/pongs.
Change-Id: Id825cc0095398d72922700fa5c0d4f30cf19353c
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
-rw-r--r-- | src/qtmetaobjectpublisher.cpp | 1 | ||||
-rw-r--r-- | src/qwebchannel.cpp | 7 | ||||
-rw-r--r-- | src/qwebchannel.h | 2 | ||||
-rw-r--r-- | src/qwebsocketserver.cpp | 7 | ||||
-rw-r--r-- | src/qwebsocketserver.h | 1 |
5 files changed, 16 insertions, 2 deletions
diff --git a/src/qtmetaobjectpublisher.cpp b/src/qtmetaobjectpublisher.cpp index e441199..1646434 100644 --- a/src/qtmetaobjectpublisher.cpp +++ b/src/qtmetaobjectpublisher.cpp @@ -44,7 +44,6 @@ #include <QStringList> #include <QMetaObject> #include <QMetaProperty> -#include <QDebug> QtMetaObjectPublisher::QtMetaObjectPublisher(QObject *parent) : QObject(parent) diff --git a/src/qwebchannel.cpp b/src/qwebchannel.cpp index 2a78624..ea78046 100644 --- a/src/qwebchannel.cpp +++ b/src/qwebchannel.cpp @@ -132,6 +132,8 @@ QWebChannel::QWebChannel(QObject *parent) SIGNAL(failed(QString))); connect(d, SIGNAL(initialized()), SLOT(onInitialized())); + connect(d, SIGNAL(pongReceived()), + SIGNAL(pongReceived())); d->initLater(); } @@ -168,4 +170,9 @@ void QWebChannel::sendRawMessage(const QString& message) d->sendMessage(message); } +void QWebChannel::ping() +{ + d->ping(); +} + #include <qwebchannel.moc> diff --git a/src/qwebchannel.h b/src/qwebchannel.h index 37126c7..0d97762 100644 --- a/src/qwebchannel.h +++ b/src/qwebchannel.h @@ -65,12 +65,14 @@ public: signals: void baseUrlChanged(const QString& baseUrl); void rawMessageReceived(const QString& rawMessage); + void pongReceived(); void initialized(); void failed(const QString& reason); public slots: void sendRawMessage(const QString& rawMessage); + void ping(); private slots: void onInitialized(); diff --git a/src/qwebsocketserver.cpp b/src/qwebsocketserver.cpp index a87d4bf..2f46247 100644 --- a/src/qwebsocketserver.cpp +++ b/src/qwebsocketserver.cpp @@ -280,7 +280,7 @@ bool QWebSocketServer::readFrameData(QTcpSocket* socket, Frame& frame) frame.state = Frame::ReadData; frame.data.reserve(frame.length); } - if (frame.state == Frame::ReadData && bytesAvailable) { + if (frame.state == Frame::ReadData && (bytesAvailable || !frame.length)) { frame.data.append(socket->read(qMin(frame.length - frame.data.size(), bytesAvailable))); if (frame.data.size() == frame.length) { frame.state = Frame::ReadStart; @@ -412,3 +412,8 @@ void QWebSocketServer::sendFrame(QTcpSocket* socket, Frame::Opcode opcode, const socket->write(header); socket->write(data); } + +void QWebSocketServer::ping() +{ + sendFrame(Frame::Ping, QByteArray()); +} diff --git a/src/qwebsocketserver.h b/src/qwebsocketserver.h index 875cb58..774f318 100644 --- a/src/qwebsocketserver.h +++ b/src/qwebsocketserver.h @@ -72,6 +72,7 @@ signals: public slots: void sendMessage(const QString& message); + void ping(); private slots: void newConnection(); |