Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions serial_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,25 @@ func (port *unixPort) Read(p []byte) (int, error) {
}
}

func (port *unixPort) Write(p []byte) (n int, err error) {
n, err = unix.Write(port.handle, p)
func (port *unixPort) writeOnce(p []byte) (int, error) {
n, err := unix.Write(port.handle, p)
if n < 0 { // Do not return -1 unix errors
if err == nil {
err = fmt.Errorf("unix.Write() returned n<0,err==nil: n=%d", n)
}
Comment on lines +115 to +117
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?

n = 0
}
return
return n, err
}

func (port *unixPort) Write(p []byte) (n int, err error) {
for n < len(p) && err == nil {
var n2 int
n2, err = port.writeOnce(p[n:])
n += n2
Comment on lines +125 to +127
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?

}

return n, err
}

func (port *unixPort) Break(t time.Duration) error {
Expand Down