win32: return partial serial data on timeout - #3559
Conversation
Signed-off-by: Marcelo Pacheco <marcello.mpacheco@gmail.com>
|
A ZIP file with standard source tarball and another tarball with pre-built docs for commit d255dfa is temporarily available: NUT-tarballs-PR-3559.zip. |
|
✅ Build nut 2.8.5.5029-master completed (commit ced2ce8edf by @Marcelo-PX)
|
|
I wonder if it is correct to return partial data, without even a hint like setting |
That makes sense. In my test with But I agree that Would it be better to return the byte count but keep |
|
TL;DR: Ultimately, probably what you did is in fact the correct way to do it for the case where I thought returning the byte count and setting the A quick "Chat with GPT" confirmed it also does not know about any precedents directly like what I first suggested either. Portable readers just loop POSIX does not define a mechanism whereby Specifically,
POSIX explicitly treats Partial reads are not errors A partial read is already a normal, expected outcome for many kinds of file descriptors:
The standard already allows to return without implying anything is wrong. The application is expected to call Timeouts POSIX generally treats timeouts as one of two things:
If no bytes have been transferred before the timeout expires, the operation fails: or depending on the API and object. For example, sockets with
If some bytes have already been copied into the user's buffer, virtually every implementation considers the operation successful and simply returns the byte count. The timeout is effectively forgotten. This mirrors how For example, POSIX says (paraphrasing):
Timeouts are commonly implemented analogously. Why not both? Suppose copies and then times out. If it returned what should portable code do? Typical code is It never even looks at Changing that convention would break decades of software. Existing precedents I can't think of a POSIX interface that returns both
There are other APIs that return additional status separately, e.g.
where flags may contain These are not reported through If a datagram is larger than the supplied buffer, it returns Similarly, return readiness information separately from errors. Some APIs have out-parameters for auxiliary status. But POSIX generally avoids "success plus errno". |
|
Huh, why closed? UPDATE: refactored via #3560 |
Summary
Fix the Win32 serial read wrapper so that data already accumulated before a
timeout is returned to the caller instead of being discarded as an I/O error.
When
nutdrv_qxreceives a complete Q1 response over a Windows COM port, thesubsequent timeout currently falls through to the generic error path even
though valid bytes were already received.
This change cancels the pending overlapped operation, resets its state, clears
the Win32 error status and returns the accumulated byte count when the timeout
occurs after receiving data.
Fixes #3452.
Testing
Tested on Windows x86_64 with a UPSBrasil 3 kVA UPS using:
nutdrv_qxVerified:
upsd,upscandupsmonreceive the UPS data;adapter without restarting the driver process;
OLandOL BYPASSare reported correctly.The broader
ci_build.shrun stopped on an unrelated GCC 16-Werrorwarningin
nut-scanner, after the affected driver and libraries had compiled.AI disclosure
ChatGPT was used to assist with diagnosing the Win32 timeout behavior,
reviewing the proposed change, and drafting the issue and pull request text.
The submitted change was manually reviewed, compiled and tested against real
hardware by the contributor.
General points
Described the changes in the PR submission or a separate issue, e.g.
known published or discovered protocols, applicable hardware (expected
compatible and actually tested/developed against), limitations, etc.
There may be multiple commits in the PR, aligned and commented with
a functional change. Notably, coding style changes better belong in a
separate PR, but certainly in a dedicated commit to simplify reviews
of "real" changes in the other commits. Similarly for typo fixes in
comments or text documents.
Use of coding helper tools and AI should be disclosed in the commit
or PR comments (it is interesting to know which ones do a decent job).
As with other contributions, a human is responsible and thanked for the
quality and content of the change, and is presumed to have the right to
post that code to be published further under the project's license terms.
Especially with involvement of AI, including modern IDE coding aid,
please be sure to revise that proposed code and documentation changes
follow NUT code style guide -- this helps portability across the decades
worth of supported systems. Notably, avoid Unicode characters where ASCII
text is expected.
Please star NUT on GitHub, this helps with sponsorships! ;)
Frequent "underwater rocks" for driver addition/update PRs
Revised existing driver families and added a sub-driver if applicable
(
nutdrv_qx,usbhid-ups...) or added a brand new driver in the othercase.
Did not extend obsoleted drivers with new hardware support features
(notably
blazerand other single-device family drivers for Qx protocols,except the new
nutdrv_qxwhich should cover them all).For updated existing device drivers, bumped the
DRIVER_VERSIONmacroor its equivalent.
For USB devices (HID or not), revised that the driver uses unique
VID/PID combinations, or raised discussions when this is not the case.
For new USB devices, built and committed the changes for the
scripts/upower/95-upower-hid.hwdbfile.Proposed NUT data mapping is aligned with existing
docs/nut-names.txtfile.Updated
data/driver.list.inif applicable.Frequent "underwater rocks" for general C code PRs
Did not "blindly assume" default integer type sizes and value ranges,
structure layout and alignment in memory, endianness, or use of generic
intwhere language or libraries dictate the use ofsize_torssize_t.Progress and errors are handled with
upsdebugx(),upslogx(),fatalx()and related methods, not with directprintf()orexit().Coding style, including whitespace for indentations, follows precedent
in the code of the file and the guidance in
docs/developers.txt.For newly added files, the
Makefile.amrecipes were updated and themake distchecktarget passes.General documentation updates
Added a bullet point into
NEWS.adoc, possibly alsoUPGRADING.adocif there is something packagers or custom-build users should take into
account.
Updated
docs/acknowledgements.txt.Added or updated manual page information in
docs/man/*.txtfiles andcorresponding recipe lists in
docs/man/Makefile.am.Passed
make spellcheckand updateddocs/nut.dictif needed.Additional work may be needed after posting this PR
Propose a PR for NUT DDL with detailed device data dumps from tests
against real hardware.
Address NUT CI farm build failures for the PR.
Revise suggestions from LGTM.COM analysis about new issues.