winrt: Make error messages of QNativeSocketEngine more verbose.

Output function, object name and class of the socket. Example:

qt.winrtrunner.app: handleReadyRead(): Could not read into socket stream buffer ("QTcpServer:40000"/QTcpServer). (A method was called at an unexpected time.)

Change-Id: Ic074c2c3a01221bd77dae0715db912e830f21435
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-11-27 14:37:19 +01:00
parent 45f7512bf5
commit c06a39f6d2

View File

@ -78,6 +78,21 @@ typedef IAsyncOperationWithProgress<IBuffer *, UINT32> IAsyncBufferOperation;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
static QByteArray socketDescription(const QAbstractSocketEngine *s)
{
QByteArray result;
if (const QObject *o = s->parent()) {
const QString name = o->objectName();
if (!name.isEmpty()) {
result += '"';
result += name.toLocal8Bit();
result += "\"/";
}
result += o->metaObject()->className();
}
return result;
}
// Common constructs // Common constructs
#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue) do { \ #define Q_CHECK_VALID_SOCKETLAYER(function, returnValue) do { \
if (!isValid()) { \ if (!isValid()) { \
@ -275,8 +290,9 @@ bool QNativeSocketEngine::connectToHostByName(const QString &name, quint16 port)
else if (d->socketType == QAbstractSocket::UdpSocket) else if (d->socketType == QAbstractSocket::UdpSocket)
hr = d->udpSocket()->ConnectAsync(remoteHost.Get(), portReference.Get(), &d->connectOp); hr = d->udpSocket()->ConnectAsync(remoteHost.Get(), portReference.Get(), &d->connectOp);
if (hr == E_ACCESSDENIED) { if (hr == E_ACCESSDENIED) {
qErrnoWarning(hr, "QNativeSocketEngine::connectToHostByName: Unable to connect to host. \ qErrnoWarning(hr, "QNativeSocketEngine::connectToHostByName: Unable to connect to host (%s:%hu/%s). "
Please check your manifest capabilities."); "Please check your manifest capabilities.",
qPrintable(name), port, socketDescription(this).constData());
return false; return false;
} }
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
@ -328,7 +344,8 @@ bool QNativeSocketEngine::bind(const QHostAddress &address, quint16 port)
hr = d->udpSocket()->BindEndpointAsync(hostAddress.Get(), portString.Get(), &op); hr = d->udpSocket()->BindEndpointAsync(hostAddress.Get(), portString.Get(), &op);
} }
if (hr == E_ACCESSDENIED) { if (hr == E_ACCESSDENIED) {
qErrnoWarning(hr, "Unable to bind socket. Please check your manifest capabilities."); qErrnoWarning(hr, "Unable to bind socket (%s:%hu/%s). Please check your manifest capabilities.",
qPrintable(address.toString()), port, socketDescription(this).constData());
return false; return false;
} }
Q_ASSERT_SUCCEEDED(hr); Q_ASSERT_SUCCEEDED(hr);
@ -381,12 +398,14 @@ int QNativeSocketEngine::accept()
ComPtr<IAsyncBufferOperation> op; ComPtr<IAsyncBufferOperation> op;
hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, &op); hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, &op);
if (FAILED(hr)) { if (FAILED(hr)) {
qErrnoWarning(hr, "Faild to read from the socket buffer."); qErrnoWarning(hr, "accept(): Failed to read from the socket buffer (%s).",
socketDescription(this).constData());
return -1; return -1;
} }
hr = op->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get()); hr = op->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get());
if (FAILED(hr)) { if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to set socket read callback."); qErrnoWarning(hr, "accept(): Failed to set socket read callback (%s).",
socketDescription(this).constData());
return -1; return -1;
} }
d->currentConnections.append(socket); d->currentConnections.append(socket);
@ -1272,12 +1291,14 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
ComPtr<IAsyncBufferOperation> op; ComPtr<IAsyncBufferOperation> op;
hr = stream->ReadAsync(buffer.Get(), bufferLength, InputStreamOptions_Partial, &op); hr = stream->ReadAsync(buffer.Get(), bufferLength, InputStreamOptions_Partial, &op);
if (FAILED(hr)) { if (FAILED(hr)) {
qErrnoWarning(hr, "Could not read into socket stream buffer."); qErrnoWarning(hr, "handleReadyRead(): Could not read into socket stream buffer (%s).",
socketDescription(q).constData());
return S_OK; return S_OK;
} }
hr = op->put_Completed(Callback<SocketReadCompletedHandler>(this, &QNativeSocketEnginePrivate::handleReadyRead).Get()); hr = op->put_Completed(Callback<SocketReadCompletedHandler>(this, &QNativeSocketEnginePrivate::handleReadyRead).Get());
if (FAILED(hr)) { if (FAILED(hr)) {
qErrnoWarning(hr, "Failed to set socket read callback."); qErrnoWarning(hr, "handleReadyRead(): Failed to set socket read callback (%s).",
socketDescription(q).constData());
return S_OK; return S_OK;
} }
return S_OK; return S_OK;