Skip to content

Conversation

ccollins476ad
Copy link

Fixes #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.

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 force-pushed the unix-no-partial-writes branch from d5a5a6a to 0d5660d Compare July 7, 2024 02:21
@richyo-codes
Copy link

richyo-codes commented Sep 16, 2024

I seem to be experiencing this same issue on a specific piece of hardware / uart. Write reports 5 bytes, and only wrote 2 bytes. Obviously this is very frustrating and should be fixed. I will test this PR

Comment on lines +115 to +117
if err == nil {
err = fmt.Errorf("unix.Write() returned n<0,err==nil: n=%d", n)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? It could happen n<0 and err==nil at the same time?

Comment on lines +125 to +127
var n2 int
n2, err = port.writeOnce(p[n:])
n += n2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why two functions? It couldn't be inlined?

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.

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

3 participants