[Development] There is the wrong behavior with QUdpSocket && EAGAIN on *nix?
    Denis Shienkov 
    denis.shienkov at gmail.com
       
    Wed Mar  1 11:27:54 CET 2017
    
    
  
Hi all,
I have use Qt 5.8, and I want to send to the UDP socket many datagrams
(e.g. 10000 datagrams, each datagram have 1000 bytes size).
I use following code:
        int busyCounter = 0;
        for(;;) {
            ...
            const QNetworkDatagram datagram(data, m_remoteAddress,
Protocol::SlavePort);
            if (m_dataSocket->writeDatagram(datagram) == -2) {
                QElapsedTimer timer;
                timer.start();
                const bool result = m_dataSocket->waitForBytesWritten(-1);
                ++busyCounter;
                qDebug() << "Wait result:" << result << "nsecs:" <<
timer.nsecsElapsed() << "busy counter:" << busyCounter;
            } else {
                busyCounter = 0;
                break;
            }
        }
As I understand, when I got the EAGAIN error (when the writeDatagram()
method fails
with the error code == -2), it means, that the transmit queue is full, and
I need wait
for something time, e.g. using the select() function:
https://linux.die.net/man/2/sendmsg
"
When the message does not fit into the send buffer of the socket, *send*()
normally blocks, unless the socket has been placed in nonblocking I/O mode.
In nonblocking mode it would fail with the error *EAGAIN* or *EWOULDBLOCK*
in this case. The *select <https://linux.die.net/man/2/select>*(2) call may
be used to determine when it is possible to send more data.
"
and then, as I understand, I need try to send same datagram again.
Instead of the select() I use the QUdpSocket::waitForBytesWritten() method,
which uses the select/pool/epoll internally.
But, seems it does not work, as described in the POSIX documentation,
I got following debug output:
"
Wait result: false nsecs: 363 busy counter: 1
...
Wait result: false nsecs: 140 busy counter: 232
...
Wait result: false nsecs: 167 busy counter: 1
...
Wait result: false nsecs: 139 busy counter: 238
...
Wait result: false nsecs: 167 busy counter: 1
..
Wait result: false nsecs: 167 busy counter: 19
...
"
and etc.
I suspect, that the busyCounter always should be 1, but it does
not happens, and the waitForBytesWritten() always fails!
What doing wrong?
BR,
Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170301/2f2e8094/attachment.html>
    
    
More information about the Development
mailing list