Skip to content

fix: clamp negative msecs to -1 for waitForReadyRead() - #220

Merged
itay-grudev merged 5 commits into
itay-grudev:masterfrom
re2zero:fix/issue-194-waitforreadyread-negative-timeout
Jun 16, 2026
Merged

fix: clamp negative msecs to -1 for waitForReadyRead()#220
itay-grudev merged 5 commits into
itay-grudev:masterfrom
re2zero:fix/issue-194-waitforreadyread-negative-timeout

Conversation

@re2zero

@re2zero re2zero commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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

  • Logic verified: negative msecs now clamped to Qt6's -1 sentinel
  • Original issue reporter's fix confirmed as correct approach
  • No change to the positive msecs path

Fixes #194

waitForReadyRead() treats any negative value as an error (returning
false immediately), but Qt6 defines -1 as the "wait forever" sentinel.

When msecs is computed from (timeout - elapsed), it can become negative
due to elapsed overflow, causing sendMessage() to silently fail.

Clamp negative values to -1 so the behavior matches user intent.

Fixes itay-grudev#194
@re2zero
re2zero marked this pull request as ready for review June 3, 2026 05:11
@itay-grudev
itay-grudev merged commit a218603 into itay-grudev:master Jun 16, 2026
7 checks passed
@re2zero
re2zero deleted the fix/issue-194-waitforreadyread-negative-timeout branch July 3, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SendMessage doesn't send (with Fix)

2 participants