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

serial_unix.go: Keep writing until complete #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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)
}
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
}

return n, err
}

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