Skip to content

Commit a218603

Browse files
re2zeroitay-grudev
andauthored
fix: clamp negative msecs to -1 for waitForReadyRead() (#220)
## Summary - Fix `waitForReadyRead()` silently failing when msecs is negative ## Problem `QAbstractSocket::waitForReadyRead(int msecs)` treats any negative value as an error and returns `false` immediately. However, Qt6 defines `-1` as the "wait forever" sentinel. In `writeConfirmedFrame()`, `msecs` is computed as `(timeout - elapsed)`, which can become negative when elapsed exceeds the original timeout. This causes `sendMessage()` to silently fail. ## Fix Clamp negative msecs to `-1`, which is the correct Qt6 "wait forever" value. This preserves the original intent: when the timeout budget is exhausted, block until data arrives rather than failing immediately. ## Test Plan - [x] Logic verified: negative msecs now clamped to Qt6's -1 sentinel - [x] Original issue reporter's fix confirmed as correct approach - [x] No change to the positive msecs path Fixes #194 Co-authored-by: Itay Grudev <itay+git2020@grudev.com>
1 parent cb9a48e commit a218603

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

singleapplication_p.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ bool SingleApplicationPrivate::writeConfirmedFrame( int msecs, const QByteArray
321321
socket->write( msg );
322322
socket->flush();
323323

324-
bool result = socket->waitForReadyRead( msecs ); // await ack byte
324+
// Clamp negative msecs to -1 (Qt6's "wait forever" sentinel for waitForReadyRead)
325+
bool result = socket->waitForReadyRead( msecs < 0 ? -1 : msecs ); // await ack byte
325326
if (result) {
326327
socket->read( 1 );
327328
return true;

0 commit comments

Comments
 (0)