diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 3d665270fd..f28dc6698a 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -881,7 +881,7 @@ bool QAbstractSocketPrivate::flush() const char *ptr = writeBuffer.readPointer(); // Attempt to write it all in one chunk. - qint64 written = socketEngine->write(ptr, nextSize); + qint64 written = nextSize ? socketEngine->write(ptr, nextSize) : Q_INT64_C(0); if (written < 0) { #if defined (QABSTRACTSOCKET_DEBUG) qDebug() << "QAbstractSocketPrivate::flush() write error, aborting." << socketEngine->errorString(); @@ -2477,7 +2477,7 @@ qint64 QAbstractSocket::writeData(const char *data, qint64 size) if (!d->isBuffered && d->socketType == TcpSocket && d->socketEngine && d->writeBuffer.isEmpty()) { // This code is for the new Unbuffered QTcpSocket use case - qint64 written = d->socketEngine->write(data, size); + qint64 written = size ? d->socketEngine->write(data, size) : Q_INT64_C(0); if (written < 0) { d->setError(d->socketEngine->error(), d->socketEngine->errorString()); return written; diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp index 805acde860..86d13d82a2 100644 --- a/src/network/socket/qnativesocketengine.cpp +++ b/src/network/socket/qnativesocketengine.cpp @@ -846,6 +846,10 @@ qint64 QNativeSocketEngine::writeDatagram(const char *data, qint64 size, const Q /*! Writes a block of \a size bytes from \a data to the socket. Returns the number of bytes written, or -1 if an error occurred. + + Passing zero as the \a size parameter on a connected UDP socket + will send an empty datagram. For other socket types results are + unspecified. */ qint64 QNativeSocketEngine::write(const char *data, qint64 size) {