summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qnativesocketengine.cpp36
-rw-r--r--src/network/socket/qnativesocketengine_p.h12
-rw-r--r--src/network/socket/qnativesocketengine_winrt.cpp35
3 files changed, 54 insertions, 29 deletions
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index c11b889220..e86d3ad76e 100644
--- a/src/network/socket/qnativesocketengine.cpp
+++ b/src/network/socket/qnativesocketengine.cpp
@@ -672,6 +672,24 @@ int QNativeSocketEngine::accept()
return d->nativeAccept();
}
+/*!
+ Returns the number of bytes that are currently available for
+ reading. On error, -1 is returned.
+
+ For UDP sockets, this function returns the accumulated size of all
+ pending datagrams, and it is therefore more useful for UDP sockets
+ to call hasPendingDatagrams() and pendingDatagramSize().
+*/
+qint64 QNativeSocketEngine::bytesAvailable() const
+{
+ Q_D(const QNativeSocketEngine);
+ Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::bytesAvailable(), -1);
+ Q_CHECK_NOT_STATE(QNativeSocketEngine::bytesAvailable(), QAbstractSocket::UnconnectedState, -1);
+
+ return d->nativeBytesAvailable();
+}
+
+#ifndef QT_NO_UDPSOCKET
#ifndef QT_NO_NETWORKINTERFACE
/*!
@@ -734,23 +752,6 @@ bool QNativeSocketEngine::setMulticastInterface(const QNetworkInterface &iface)
#endif // QT_NO_NETWORKINTERFACE
/*!
- Returns the number of bytes that are currently available for
- reading. On error, -1 is returned.
-
- For UDP sockets, this function returns the accumulated size of all
- pending datagrams, and it is therefore more useful for UDP sockets
- to call hasPendingDatagrams() and pendingDatagramSize().
-*/
-qint64 QNativeSocketEngine::bytesAvailable() const
-{
- Q_D(const QNativeSocketEngine);
- Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::bytesAvailable(), -1);
- Q_CHECK_NOT_STATE(QNativeSocketEngine::bytesAvailable(), QAbstractSocket::UnconnectedState, -1);
-
- return d->nativeBytesAvailable();
-}
-
-/*!
Returns \c true if there is at least one datagram pending. This
function is only called by UDP sockets, where a datagram can have
a size of 0. TCP sockets call bytesAvailable().
@@ -834,6 +835,7 @@ qint64 QNativeSocketEngine::writeDatagram(const char *data, qint64 size, const Q
return d->nativeSendDatagram(data, size, header);
}
+#endif // QT_NO_UDPSOCKET
/*!
Writes a block of \a size bytes from \a data to the socket.
diff --git a/src/network/socket/qnativesocketengine_p.h b/src/network/socket/qnativesocketengine_p.h
index 5cc5e529fc..39e4d5e457 100644
--- a/src/network/socket/qnativesocketengine_p.h
+++ b/src/network/socket/qnativesocketengine_p.h
@@ -125,6 +125,12 @@ public:
int accept() Q_DECL_OVERRIDE;
void close() Q_DECL_OVERRIDE;
+ qint64 bytesAvailable() const Q_DECL_OVERRIDE;
+
+ qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
+ qint64 write(const char *data, qint64 len) Q_DECL_OVERRIDE;
+
+#ifndef QT_NO_UDPSOCKET
#ifndef QT_NO_NETWORKINTERFACE
bool joinMulticastGroup(const QHostAddress &groupAddress,
const QNetworkInterface &iface) Q_DECL_OVERRIDE;
@@ -134,16 +140,12 @@ public:
bool setMulticastInterface(const QNetworkInterface &iface) Q_DECL_OVERRIDE;
#endif
- qint64 bytesAvailable() const Q_DECL_OVERRIDE;
-
- qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE;
- qint64 write(const char *data, qint64 len) Q_DECL_OVERRIDE;
-
qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader * = 0,
PacketHeaderOptions = WantNone) Q_DECL_OVERRIDE;
qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &) Q_DECL_OVERRIDE;
bool hasPendingDatagrams() const Q_DECL_OVERRIDE;
qint64 pendingDatagramSize() const Q_DECL_OVERRIDE;
+#endif // QT_NO_UDPSOCKET
qint64 bytesToWrite() const Q_DECL_OVERRIDE;
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index e9fa227733..173221dec0 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -78,6 +78,21 @@ typedef IAsyncOperationWithProgress<IBuffer *, UINT32> IAsyncBufferOperation;
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
#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue) do { \
if (!isValid()) { \
@@ -275,8 +290,9 @@ bool QNativeSocketEngine::connectToHostByName(const QString &name, quint16 port)
else if (d->socketType == QAbstractSocket::UdpSocket)
hr = d->udpSocket()->ConnectAsync(remoteHost.Get(), portReference.Get(), &d->connectOp);
if (hr == E_ACCESSDENIED) {
- qErrnoWarning(hr, "QNativeSocketEngine::connectToHostByName: Unable to connect to host. \
- Please check your manifest capabilities.");
+ qErrnoWarning(hr, "QNativeSocketEngine::connectToHostByName: Unable to connect to host (%s:%hu/%s). "
+ "Please check your manifest capabilities.",
+ qPrintable(name), port, socketDescription(this).constData());
return false;
}
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);
}
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;
}
Q_ASSERT_SUCCEEDED(hr);
@@ -381,12 +398,14 @@ int QNativeSocketEngine::accept()
ComPtr<IAsyncBufferOperation> op;
hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, &op);
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;
}
hr = op->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get());
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;
}
d->currentConnections.append(socket);
@@ -1272,12 +1291,14 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
ComPtr<IAsyncBufferOperation> op;
hr = stream->ReadAsync(buffer.Get(), bufferLength, InputStreamOptions_Partial, &op);
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;
}
hr = op->put_Completed(Callback<SocketReadCompletedHandler>(this, &QNativeSocketEnginePrivate::handleReadyRead).Get());
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;