Closed droidsyer closed 7 years ago
@droidsyer this might be a Qt bug. The point of that line of code is to ensure that the data has been written completely, if its timing out then the underlying socket is either: not actually writing all the data, or not properly indicating that the data has been written. Perhaps you have another piece of code that is inadvertently closing the socket?
If the value passed in is -1 it will never time out. If you tried 0 then that should effectively be the same as deleting the line (because it will immediately exit, and we don't use the return value), so I suspect something else is going on in your code.
@mbroadst I'm sure that I never close the socket.
By passing 0, this error occurs:
QAmqpClientPrivate::_q_socketError 220 - socket error: "Network operation timed out"]
@droidsyer do you have a minimal test case?
About this bug I cannot provide a test case. Because this problem occurs only for a client with GUI, at a specific moment, when is opened the main window.
From qt site http://doc.qt.io/qt-5/qabstractsocket.html :
bool QAbstractSocket::waitForBytesWritten(int msecs = 30000)
Reimplemented from QIODevice::waitForBytesWritten().
This function blocks until at least one byte has been written on the socket and the bytesWritten() signal has been emitted. The function will timeout after msecs milliseconds; the default timeout is 30000 milliseconds.
The function returns true if the bytesWritten() signal is emitted; otherwise it returns false (if an error occurred or the operation timed out).
Note: This function may fail randomly on Windows. Consider using the event loop and the bytesWritten() signal if your software will run on Windows.
My application runs both on Windows and Linux OS.
What do you suggest me?
@droidsyer sorry I really don't have time to investigate this right now, but I reiterate that if you pass 0
as the timeout and this still fails, then something else far more sinister is probably going on. I guess we could compromise on adding a switch to shut it off, instead of outright removing the code?
Yeah should be a good compromise! So who choose switch "without waitForByteWritten method" have to handle the eventually overflow of OS socket buffer. That's right!
I'll provide the new solution ASAP.
Great! Thank you very much 👍
I have a problem with method waitForBytesWritten. Sometimes my application is locked when is called this method (timeout expired). Although I try to modify writeTimeout (i.e. -1; 5 or 30), when timeout expires, rabbitMQ server disconnects me.
But if I try to delete it, it works! My question is: Why is this method necessary? What is its purpose?
Thank you!