diff options
author | Oliver Wolff <oliver.wolff@theqtcompany.com> | 2016-04-07 15:52:59 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@theqtcompany.com> | 2016-04-13 10:17:08 +0000 |
commit | b501fc3b3378526e35590d1733ba61c7c1562a75 (patch) | |
tree | 7ea941950a9b3cb2a458960e1c23accf9fac493d /src/network/socket | |
parent | 29a8c2d9b9cc3055706cd022e5286f7b330fa55a (diff) |
winrt: Register for socket reads for correct socket engine
Reading from the socket must not happen from the managing socket engine
but the socket engines that are spawned for reading/writing data (these
are initialized with the socket descriptor given). With the current
implementation the managing socket engine might be closed after the
first connection so that no other socket requests will be handled.
Change-Id: I76e1356bb75b8641b4f113872be143ca5c8b08cc
Reviewed-by: Samuel Nevala <samuel.nevala@intopalo.com>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r-- | src/network/socket/qnativesocketengine_winrt.cpp | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp index 21c5dc607a..c5281ee9c5 100644 --- a/src/network/socket/qnativesocketengine_winrt.cpp +++ b/src/network/socket/qnativesocketengine_winrt.cpp @@ -239,7 +239,8 @@ bool QNativeSocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket:: close(); // Currently, only TCP sockets are initialized this way. - d->socketDescriptor = qintptr(gSocketHandler->pendingTcpSockets.take(socketDescriptor)); + IStreamSocket *socket = gSocketHandler->pendingTcpSockets.take(socketDescriptor); + d->socketDescriptor = qintptr(socket); d->socketType = QAbstractSocket::TcpSocket; if (!d->socketDescriptor || !d->fetchConnectionParameters()) { @@ -249,6 +250,36 @@ bool QNativeSocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket:: return false; } + // Start processing incoming data + if (d->socketType == QAbstractSocket::TcpSocket) { + HRESULT hr; + hr = QEventDispatcherWinRT::runOnXamlThread([d, socket, this]() { + ComPtr<IBuffer> buffer; + HRESULT hr = g->bufferFactory->Create(READ_BUFFER_SIZE, &buffer); + RETURN_HR_IF_FAILED("initialize(): Could not create buffer"); + + ComPtr<IInputStream> stream; + hr = socket->get_InputStream(&stream); + RETURN_HR_IF_FAILED("initialize(): Could not obtain input stream"); + hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, d->readOp.GetAddressOf()); + if (FAILED(hr)) { + qErrnoWarning(hr, "initialize(): Failed to read from the socket buffer (%s).", + socketDescription(this).constData()); + return E_FAIL; + } + hr = d->readOp->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get()); + if (FAILED(hr)) { + qErrnoWarning(hr, "initialize(): Failed to set socket read callback (%s).", + socketDescription(this).constData()); + return E_FAIL; + } + return S_OK; + }); + if (hr == E_FAIL) + return false; + Q_ASSERT_SUCCEEDED(hr); + } + d->socketState = socketState; return true; } @@ -390,37 +421,9 @@ int QNativeSocketEngine::accept() return -1; } - // Start processing incoming data if (d->socketType == QAbstractSocket::TcpSocket) { IStreamSocket *socket = d->pendingConnections.takeFirst(); - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([d, socket, this]() { - ComPtr<IBuffer> buffer; - HRESULT hr = g->bufferFactory->Create(READ_BUFFER_SIZE, &buffer); - RETURN_HR_IF_FAILED("accept(): Could not create buffer"); - ComPtr<IInputStream> stream; - hr = socket->get_InputStream(&stream); - RETURN_HR_IF_FAILED("accept(): Could not obtain input stream"); - hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, &d->readOp); - if (FAILED(hr)) { - qErrnoWarning(hr, "accept(): Failed to read from the socket buffer (%s).", - socketDescription(this).constData()); - return E_FAIL; - } - hr = d->readOp->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get()); - if (FAILED(hr)) { - qErrnoWarning(hr, "accept(): Failed to set socket read callback (%s).", - socketDescription(this).constData()); - return E_FAIL; - } - return S_OK; - }); - if (hr == E_FAIL) - return -1; - Q_ASSERT_SUCCEEDED(hr); - d->currentConnections.append(socket); - SocketHandler *handler = gSocketHandler(); handler->pendingTcpSockets.insert(++handler->socketCount, socket); return handler->socketCount; |