0

In my application, While writing to socket the data is not written immediately. But if i use the flush() or waitForByteWritten(msec) then it get written. But here the only problem with flush() and waitforByteWritten() is its creating a performance bottleneck.

If i use it then performance is not so good. But if i doesn't use flush()/waitforBytesWritten() then data itself doesn't transfer immediately.

Is there any flag or something so that data can be written as the data is written to buffer.

  • 1
    Can you provide some code? – Kirill Chernikov Jul 01 '16 at 07:31
  • if you are `write()`ing small chunks of data within small time intervals, maybe you should disable [Nagle's Algorithm](https://en.wikipedia.org/wiki/Nagle%27s_algorithm), using [`tcpSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);`](https://doc.qt.io/qt-5/qabstractsocket.html#setSocketOption) – Mike Jul 01 '16 at 17:03
  • Hint: return to the event loop *as soon as possible*! – peppe Jul 01 '16 at 18:47

1 Answers1

0

You're blocking the event loop. Don't do that. The code that writes to the socket should return as soon as it's done.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313