[Development] There is the wrong behavior with QUdpSocket && EAGAIN on *nix?
Denis Shienkov
denis.shienkov at gmail.com
Thu Mar 2 07:43:40 CET 2017
Hi Thiago,
> QAbstractSocket::waitForBytesWritten ... This isn't needed and isn't
useful.
> QUdpSocket is unbuffered, so the bytesWritten() signal is not useful.
> You don't get to poll(). See above.
Goood news! :)
So, should I create an own wrapper (QIODevice) for the UDP socket? Or there
is a solution with QUdpSocket?
> ...unless QUdpSocket already creates one on that socket. The event
dispatcher
> does not allow two QSN on the same socket, with the same type. If that
> happens, let us know.
Ok, I will try to check it.
BR,
Denis
2017-03-01 23:17 GMT+03:00 Thiago Macieira <thiago.macieira at intel.com>:
> Em quarta-feira, 1 de março de 2017, às 02:27:54 PST, Denis Shienkov
> escreveu:
> > 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);
>
> This isn't needed and isn't useful. QAbstractSocket::waitForBytesWritten
> has
> this:
>
> if (writeBuffer.isEmpty())
> return false;
>
> Since QUdpSocket is unbuffered, the write buffer is always empty. So
> waitForBytesWritten will always return false.
>
> > 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
>
> Which is QSocketNotifier.
>
> QUdpSocket is unbuffered, so the bytesWritten() signal is not useful. We
> can't
> add a readyWrite() signal because it would be fired all the time. You'll
> have
> to do the QSocketNotifier.
>
> ...unless QUdpSocket already creates one on that socket. The event
> dispatcher
> does not allow two QSN on the same socket, with the same type. If that
> happens, let us know.
>
> > 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.
>
> You don't get to poll(). See above.
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
> Software Architect - Intel Open Source Technology Center
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170302/683e18c1/attachment.html>
More information about the Development
mailing list