Remove waitXXX() methods from websockets
authorKurt Pattyn <pattyn.kurt@gmail.com>
Sat, 11 Jan 2014 18:08:28 +0000 (19:08 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 11 Jan 2014 18:11:17 +0000 (19:11 +0100)
The QWebSocketServer::waitForNewConnection() was just calling
QTcpServer::waitForNewConnection(), which was not correct because
a connection is only complete when the handshake succeeds.
Waiting for the handshake to complete would need a separate thread
for the handshake handling code, which would complicate the code a lot.
It was decided to leave out all waitXXX() methods from the module,
as it is easier to add this functionality later, then to remove it.

Change-Id: I778bae45b67f81e151ad2362f772c75e9f537ff0
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
src/websockets/qwebsocketserver.cpp
src/websockets/qwebsocketserver.h
src/websockets/qwebsocketserver_p.cpp
src/websockets/qwebsocketserver_p.h

index 943af56..2887b84 100644 (file)
@@ -551,44 +551,6 @@ QAbstractSocket::SocketState QWebSocket::state() const
 }
 
 /*!
-    \brief Waits until the socket is connected, up to \a msecs milliseconds. If the connection has been established, this function returns true; otherwise it returns false. In the case where it returns false, you can call error() to determine the cause of the error.
-    The following example waits up to one second for a connection to be established:
-
-    \code
-    socket->open("ws://localhost:1234", false);
-    if (socket->waitForConnected(1000))
-    {
-        qDebug("Connected!");
-    }
-    \endcode
-
-    If \a msecs is -1, this function will not time out.
-    \note This function may wait slightly longer than msecs, depending on the time it takes to complete the host lookup.
-    \note Multiple calls to this functions do not accumulate the time. If the function times out, the connecting process will be aborted.
-
-    \sa connected(), open(), state()
- */
-bool QWebSocket::waitForConnected(int msecs)
-{
-    Q_D(QWebSocket);
-    return d->waitForConnected(msecs);
-}
-
-/*!
-  Waits \a msecs for the socket to be disconnected.
-  If the socket was successfully disconnected within time, this method returns true.
-  Otherwise false is returned.
-  When \a msecs is -1, this function will block until the socket is disconnected.
-
-  \sa close(), state()
-*/
-bool QWebSocket::waitForDisconnected(int msecs)
-{
-    Q_D(QWebSocket);
-    return d->waitForDisconnected(msecs);
-}
-
-/*!
     Returns the local address
  */
 QHostAddress QWebSocket::localAddress() const
index 40e1e9a..927350a 100644 (file)
@@ -95,9 +95,6 @@ public:
     QVariant socketOption(QAbstractSocket::SocketOption option);
     QAbstractSocket::SocketState state() const;
 
-    bool waitForConnected(int msecs = 30000);
-    bool waitForDisconnected(int msecs = 30000);
-
     QWebSocketProtocol::Version version() const;
     QString resourceName() const;
     QUrl requestUrl() const;
index bcbb205..d620008 100644 (file)
@@ -1042,28 +1042,6 @@ QAbstractSocket::SocketState QWebSocketPrivate::state() const
 /*!
     \internal
  */
-bool QWebSocketPrivate::waitForConnected(int msecs)
-{
-    bool result = false;
-    if (Q_LIKELY(m_pSocket))
-        result = m_pSocket->waitForConnected(msecs);
-    return result;
-}
-
-/*!
-    \internal
- */
-bool QWebSocketPrivate::waitForDisconnected(int msecs)
-{
-    bool result = false;
-    if (Q_LIKELY(m_pSocket))
-        result = m_pSocket->waitForDisconnected(msecs);
-    return result;
-}
-
-/*!
-    \internal
- */
 void QWebSocketPrivate::setSocketState(QAbstractSocket::SocketState state)
 {
     Q_Q(QWebSocket);
index d9fc612..544035f 100644 (file)
@@ -130,9 +130,6 @@ public:
     QVariant socketOption(QAbstractSocket::SocketOption option);
     QAbstractSocket::SocketState state() const;
 
-    bool waitForConnected(int msecs);
-    bool waitForDisconnected(int msecs);
-
     QWebSocketProtocol::Version version() const;
     QString resourceName() const;
     QUrl requestUrl() const;
index d60d6b1..e811e3a 100644 (file)
@@ -58,7 +58,6 @@
     If an error occurs, serverError() returns the type of error, and errorString() can be called to get a human readable description of what happened.
     When listening for connections, the address and port on which the server is listening are available as serverAddress() and serverPort().
     Calling close() makes QWebSocketServer stop listening for incoming connections.
-    Although QWebSocketServer is mostly designed for use with an event loop, it's possible to use it without one. In that case, you must use waitForNewConnection(), which blocks until either a connection is available or a timeout expires.
 
     \sa echoserver.html
 
@@ -495,25 +494,6 @@ int QWebSocketServer::socketDescriptor() const
 }
 
 /*!
-    Waits for at most \a msec milliseconds or until an incoming connection is available.
-    Returns true if a connection is available; otherwise returns false.
-    If the operation timed out and \a timedOut is not 0, \a timedOut will be set to true.
-
-    \note This is a blocking function call.
-    \note Its use is disadvised in a single-threaded GUI application, since the whole application will stop responding until the function returns. waitForNewConnection() is mostly useful when there is no event loop available.
-    \note The non-blocking alternative is to connect to the newConnection() signal.
-
-    If \a msec is -1, this function will not time out.
-
-    \sa hasPendingConnections(), nextPendingConnection()
-*/
-bool QWebSocketServer::waitForNewConnection(int msec, bool *timedOut)
-{
-    Q_D(QWebSocketServer);
-    return d->waitForNewConnection(msec, timedOut);
-}
-
-/*!
   Returns a list of websocket versions that this server is supporting.
  */
 QList<QWebSocketProtocol::Version> QWebSocketServer::supportedVersions() const
index bc7801a..c34cab3 100644 (file)
@@ -95,7 +95,6 @@ public:
     bool setSocketDescriptor(int socketDescriptor);
     int socketDescriptor() const;
 
-    bool waitForNewConnection(int msec = 0, bool *timedOut = 0);
     bool hasPendingConnections() const;
     virtual QWebSocket *nextPendingConnection();
 
index 4d5680f..d5d98bd 100644 (file)
@@ -267,14 +267,6 @@ qintptr QWebSocketServerPrivate::socketDescriptor() const
 /*!
     \internal
  */
-bool QWebSocketServerPrivate::waitForNewConnection(int msec, bool *timedOut)
-{
-    return m_pTcpServer->waitForNewConnection(msec, timedOut);
-}
-
-/*!
-    \internal
- */
 QList<QWebSocketProtocol::Version> QWebSocketServerPrivate::supportedVersions() const
 {
     QList<QWebSocketProtocol::Version> supportedVersions;
index ad76bbf..b9d382e 100644 (file)
@@ -103,7 +103,6 @@ public:
     void setMaxPendingConnections(int numConnections);
     bool setSocketDescriptor(qintptr socketDescriptor);
     qintptr socketDescriptor() const;
-    bool waitForNewConnection(int msec = 0, bool *timedOut = Q_NULLPTR);
 
     QList<QWebSocketProtocol::Version> supportedVersions() const;
     QStringList supportedProtocols() const;