Remove erroneous socket close() calls and clarify documentation.

This commit is contained in:
Nathan Osman
2017-08-08 17:18:07 -07:00
parent 0a7b81d4ba
commit 5fcfb11e73
3 changed files with 4 additions and 5 deletions

View File

@@ -39,8 +39,9 @@ class QHTTPENGINE_EXPORT QObjectHandlerPrivate;
*
* This handler enables incoming requests to be processed by slots in a
* QObject-derived class or functor. Methods are registered by providing a
* name and slot to invoke. The slot may take a pointer to the
* [Socket](@ref QHttpEngine::Socket) for the request as an argument.
* name and slot to invoke. The slot must take a pointer to the
* [Socket](@ref QHttpEngine::Socket) for the request as an argument and
* must also close the socket when finished with it.
*
* To use this class, simply create an instance and call the appropriate
* registerMethod() overload. For example:
@@ -68,6 +69,7 @@ class QHTTPENGINE_EXPORT QObjectHandlerPrivate;
* QHttpEngine::QObjectHandler handler;
* handler.registerMethod("something", [](QHttpEngine::Socket *socket) {
* // do something
* socket->close();
* });
* @endcode
*/

View File

@@ -92,5 +92,4 @@ void Handler::process(Socket *socket, const QString &)
{
// The default response is simply a 404 error
socket->writeError(Socket::NotFound);
socket->close();
}

View File

@@ -92,11 +92,9 @@ void QObjectHandler::process(Socket *socket, const QString &path)
// already the case, otherwise, wait until the rest of it arrives
if (!m.readAll || socket->bytesAvailable() >= socket->contentLength()) {
d->invokeSlot(socket, m);
socket->close();
} else {
connect(socket, &Socket::readChannelFinished, [this, socket, m]() {
d->invokeSlot(socket, m);
socket->close();
});
}
}