Skip to content

Commit

Permalink
Save reference to fd for flush calls (fix tarm#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotmr committed Nov 8, 2018
1 parent 98f6abe commit 31153d3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions serial_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ func openPort(name string, baud int, databits byte, parity Parity, stopbits Stop
return
}

return &Port{f: f}, nil
return &Port{f: f, fd: int(fd)}, nil
}

type Port struct {
// We intentionly do not use an "embedded" struct so that we
// don't export File
f *os.File
f *os.File

// Saving a reference to the file descriptor so we don't set as blocking during Flush() calls
fd int
}

func (p *Port) Read(b []byte) (n int, err error) {
Expand All @@ -148,7 +151,7 @@ func (p *Port) Flush() error {
const TCFLSH = 0x540B
_, _, errno := unix.Syscall(
unix.SYS_IOCTL,
uintptr(p.f.Fd()),
uintptr(p.fd),
uintptr(TCFLSH),
uintptr(unix.TCIOFLUSH),
)
Expand Down

0 comments on commit 31153d3

Please sign in to comment.