Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port.Write() returns nil error after partial write; does not adhere to the io.Writer contract #191

Open
4 tasks done
ccollins476ad opened this issue Jul 6, 2024 · 0 comments · May be fixed by #192
Open
4 tasks done
Labels

Comments

@ccollins476ad
Copy link

ccollins476ad commented Jul 6, 2024

Describe the problem

(see #192)

From the io.Writer GoDoc:

Write must return a non-nil error if it returns n < len(p).

The docs (doc.go) indicate that serial.Port implements the io.Writer interface:

The port object implements the io.ReadWriteCloser interface, so we can use
the usual Read, Write and Close functions to send and receive data from the
serial port...

However, I have seen instances where serial.Port.Write() reports success after a partial write. It seems the unix implementation forwards the data to the write syscall, but the syscall does not provide the same guarantee as io.Writer.

To reproduce

It varies by hardware/driver, but the steps would just be to open a port and write lots of data.

Please double-check that you have reported each of the following

before submitting the issue.

  • I've provided the FULL source code that causes the problem
  • I've provided all the actions required to reproduce the problem

Expected behavior

Write() should either write the entire buffer and return err=nil, or it should return an error.

Operating system and version

Linux, seen on multiple versions

Please describe your hardware setup

No response

Additional context

No response

Issue checklist

  • I searched for previous requests in the issue tracker
  • My request contains all necessary details
ccollins476ad added a commit to ccollins476ad/go-serial that referenced this issue Jul 7, 2024
Fixes bugst#191.

Change unix port.Write() implementation to match io.Writer requirement:
> Write must return a non-nil error if it returns n < len(p)

Keep executing write syscall until failure or entire buffer is written.
@ccollins476ad ccollins476ad linked a pull request Jul 7, 2024 that will close this issue
ccollins476ad added a commit to ccollins476ad/go-serial that referenced this issue Jul 7, 2024
Fixes bugst#191.

Change unix port.Write() implementation to match io.Writer requirement:
> Write must return a non-nil error if it returns n < len(p)

Keep executing write syscall until failure or entire buffer is written.
ccollins476ad added a commit to ccollins476ad/go-serial that referenced this issue Jul 7, 2024
Fixes bugst#191.

Change unix port.Write() implementation to match io.Writer requirement:
> Write must return a non-nil error if it returns n < len(p)

Keep executing write syscall until failure or entire buffer is written.
richyo-work pushed a commit to richyo-work/go-serial that referenced this issue Sep 16, 2024
Fixes bugst#191.

Change unix port.Write() implementation to match io.Writer requirement:
> Write must return a non-nil error if it returns n < len(p)

Keep executing write syscall until failure or entire buffer is written.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant