Add close code and close reason getter functions
authorKurt Pattyn <pattyn.kurt@gmail.com>
Sun, 17 Nov 2013 14:30:34 +0000 (15:30 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sun, 17 Nov 2013 14:31:11 +0000 (15:31 +0100)
Change-Id: I4eeab1521054e4f4921d25c6a990eeb7486443cb
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
src/websockets/qwebsocket.cpp
src/websockets/qwebsocket.h
src/websockets/qwebsocket_p.cpp
src/websockets/qwebsocket_p.h
sync.profile

index 21b6a35..0d3b23d 100644 (file)
@@ -509,6 +509,26 @@ QString QWebSocket::extension() const
 }
 
 /*!
+    \brief Returns the code indicating why the socket was closed.
+    \sa QWebSocketProtocol::CloseCode, closeReason()
+ */
+QWebSocketProtocol::CloseCode QWebSocket::closeCode() const
+{
+    Q_D(const QWebSocket);
+    return d->closeCode();
+}
+
+/*!
+    \brief Returns the reason why the socket was closed.
+    \sa closeCode()
+ */
+QString QWebSocket::closeReason() const
+{
+    Q_D(const QWebSocket);
+    return d->closeReason();
+}
+
+/*!
     \brief Returns the current state of the socket
  */
 QAbstractSocket::SocketState QWebSocket::state() const
index f99daad..8a6369a 100644 (file)
@@ -102,6 +102,8 @@ public:
     QString origin() const;
     QString protocol() const;
     QString extension() const;
+    QWebSocketProtocol::CloseCode closeCode() const;
+    QString closeReason() const;
 
     qint64 write(const char *message);         //send data as text
     qint64 write(const char *message, qint64 maxSize);         //send data as text
index 941366f..87bfa3f 100644 (file)
@@ -101,6 +101,8 @@ QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::
     m_mustMask(true),
     m_isClosingHandshakeSent(false),
     m_isClosingHandshakeReceived(false),
+    m_closeCode(QWebSocketProtocol::CC_NORMAL),
+    m_closeReason(),
     m_pingTimer(),
     m_dataProcessor(),
     m_configuration()
@@ -128,6 +130,8 @@ QWebSocketPrivate::QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol:
     m_mustMask(true),
     m_isClosingHandshakeSent(false),
     m_isClosingHandshakeReceived(false),
+    m_closeCode(QWebSocketProtocol::CC_NORMAL),
+    m_closeReason(),
     m_pingTimer(),
     m_dataProcessor(),
     m_configuration()
@@ -622,6 +626,22 @@ QString QWebSocketPrivate::extension() const
 /*!
  * \internal
  */
+QWebSocketProtocol::CloseCode QWebSocketPrivate::closeCode() const
+{
+    return m_closeCode;
+}
+
+/*!
+ * \internal
+ */
+QString QWebSocketPrivate::closeReason() const
+{
+    return m_closeReason;
+}
+
+/*!
+ * \internal
+ */
 QByteArray QWebSocketPrivate::getFrameHeader(QWebSocketProtocol::OpCode opCode, quint64 payloadLength, quint32 maskingKey, bool lastFrame) const
 {
     QByteArray header;
index 80c5e4f..bd41d8b 100644 (file)
@@ -137,6 +137,8 @@ public:
     QString origin() const;
     QString protocol() const;
     QString extension() const;
+    QWebSocketProtocol::CloseCode closeCode() const;
+    QString closeReason() const;
 
     qint64 write(const char *message);         //send data as text
     qint64 write(const char *message, qint64 maxSize);         //send data as text
@@ -223,6 +225,8 @@ private:
 
     bool m_isClosingHandshakeSent;
     bool m_isClosingHandshakeReceived;
+    QWebSocketProtocol::CloseCode m_closeCode;
+    QString m_closeReason;
 
     QTime m_pingTimer;
 
index ed0c60a..c812830 100644 (file)
@@ -15,4 +15,5 @@
 
 %dependencies = (
     "qtbase" => "",
+    "qtdeclarative" => "",
 );