- 
    Bug 
- 
    Resolution: Done
- 
    P3: Somewhat important 
- 
    5.9.4, 5.9.6, 5.9.8
- 
    None
- 
        
- 
        6afd5990c79d86d4136b41018066c05c95d1b0d2
After QUdpSocket::readyRead was triggered, the method QUdpSocket::pendingDatagramSize returns 1201 bytes (the whole UDP datagram i sent from the remote side). When calling QUdpSocket::readDatagram with only maxSize = 1200, the address and port parameters are not filled with the sender information (pointers are valid).
A look into the Qt source code revealed the reason in the file qnativesocketengine_win.cpp in method QNativeSocketEnginePrivate::nativeReceiveDatagram():
... if (ret == SOCKET_ERROR) { int err = WSAGetLastError(); if (err == WSAEMSGSIZE) { // it is ok the buffer was to small if bytesRead is larger than // maxLength then assume bytes read is really maxLenth ret = qint64(bytesRead) > maxLength ? maxLength : qint64(bytesRead); } else { WS_ERROR_DEBUG(err); switch (err) { case WSAENETRESET: setError(QAbstractSocket::NetworkError, NetworkDroppedConnectionErrorString); break; case WSAECONNRESET: setError(QAbstractSocket::ConnectionRefusedError, ConnectionResetErrorString); break; default: setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString); break; } ret = -1; if (header) header->clear(); } } else { ret = qint64(bytesRead); if (options & QNativeSocketEngine::WantDatagramSender) qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress); } ...
The lines
if (options & QNativeSocketEngine::WantDatagramSender)
    qt_socket_getPortAndAddress(socketDescriptor, &aa, &header->senderPort, &header->senderAddress);
needs to be executed also right after
    if (err == WSAEMSGSIZE) {
        // it is ok the buffer was to small if bytesRead is larger than
        // maxLength then assume bytes read is really maxLenth
        ret = qint64(bytesRead) > maxLength ? maxLength : qint64(bytesRead);
because this is a tolerated socket error.
- duplicates
- 
                    QTBUG-68755 readDatagram() has an empty sender value on Windows OS -         
- Closed
 
-