Skip to content

Commit

Permalink
Removed redundant Fd from Linux and POSIX ports
Browse files Browse the repository at this point in the history
- Removed reduntant File Descriptor field stored in Port structure
  for Linux and POSIX implementations
  • Loading branch information
madhurjain committed Mar 14, 2015
1 parent cee3521 commit d30c3c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions serial_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ func openPort(name string, baud int, readTimeout time.Duration) (p *Port, err er
return
}

return &Port{f: f, fd: fd}, nil
return &Port{f: f}, nil
}

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

func (p *Port) Read(b []byte) (n int, err error) {
Expand All @@ -108,7 +107,7 @@ func (p *Port) Flush() error {
const TCFLSH = 0x540B
_, _, err := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(p.fd),
uintptr(p.f.Fd()),
uintptr(TCFLSH),
uintptr(syscall.TCIOFLUSH),
)
Expand Down
7 changes: 3 additions & 4 deletions serial_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,13 @@ func openPort(name string, baud int, readTimeout time.Duration) (p *Port, err er
}
*/

return &Port{f: f, fd: fd}, nil
return &Port{f: f}, nil
}

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

func (p *Port) Read(b []byte) (n int, err error) {
Expand All @@ -135,7 +134,7 @@ func (p *Port) Write(b []byte) (n int, err error) {
}

func (p *Port) Flush() error {
_, err := C.tcflush(p.fd, C.TCIOFLUSH)
_, err := C.tcflush(C.int(p.f.Fd()), C.TCIOFLUSH)
return err
}

Expand Down

0 comments on commit d30c3c8

Please sign in to comment.