Skip to content

Commit

Permalink
Fixed issues on MacOS
Browse files Browse the repository at this point in the history
Signed-off-by: xchenan <xchenan@gmail.com>
  • Loading branch information
xchenan authored and Xuan Chen committed May 15, 2017
1 parent 2aea07d commit 9a5d5a4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 27 deletions.
8 changes: 8 additions & 0 deletions sys/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sys

import "errors"

var (
ErrNotImplemented = errors.New("not implemented")
ErrInvalidAction = errors.New("invalid action")
)
7 changes: 0 additions & 7 deletions sys/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import (

type FdSet syscall.FdSet

const NFDBits = 64

func index(fd int) (idx uint, bit int64) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}

func (fs *FdSet) s() *syscall.FdSet {
return (*syscall.FdSet)(fs)
}
Expand Down
7 changes: 7 additions & 0 deletions sys/select_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ package sys

import "syscall"

const NFDBits = 64

func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) (err error) {
return syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
}

func index(fd int) (idx uint, bit int32) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}
7 changes: 7 additions & 0 deletions sys/select_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ package sys

import "syscall"

const NFDBits = 64

func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) error {
_, err := syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
return err
}

func index(fd int) (idx uint, bit int64) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}
8 changes: 1 addition & 7 deletions sys/termios.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ func (term *Termios) SetVMin(v uint8) {
term.Cc[unix.VMIN] = v
}

func setFlag(flag *uint32, mask uint32, v bool) {
if v {
*flag |= mask
} else {
*flag &= ^mask
}
}


// SetICanon sets the canonical flag.
func (term *Termios) SetICanon(v bool) {
Expand Down
35 changes: 22 additions & 13 deletions sys/termios_freebsd.go → sys/termios_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build darwin dragonfly freebsd netbsd openbsd

// Copyright 2015 go-termios Author. All Rights Reserved.
// https://github.com/go-termios/termios
// Author: John Lenton <chipaca@github.com>
Expand All @@ -8,7 +10,6 @@ import (
"os"
"time"

"github.com/termios"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -52,8 +53,8 @@ func (tio *Termios) GetSpeed() (in int, out int) {

// SetSpeed sets the baud rate.
func (tio *Termios) SetSpeed(in int, out int) error {
tio.Ispeed = uint32(in)
tio.Ospeed = uint32(out)
tio.Ispeed = uint64(in)
tio.Ospeed = uint64(out)

return nil
}
Expand Down Expand Up @@ -102,24 +103,32 @@ func Flow(fd uintptr, action int) error {
case TCION:
idx = unix.VSTART
default:
return termios.ErrInvalidAction
return ErrInvalidAction
}

tio, err := GetAttr(fd)
tio, err := NewTermiosFromFd(int(fd))
if err != nil {
return err
}
_, err = os.NewFile(fd, "").Write([]byte{tio.Cc[idx]})
return err
}

func (q Queue) bits() uintptr {
switch q {
case InputQueue:
return FREAD
case OutputQueue:
return FWRITE
default:
return 0
//func (q Queue) bits() uintptr {
// switch q {
// case InputQueue:
// return FREAD
// case OutputQueue:
// return FWRITE
// default:
// return 0
// }
//}

func setFlag(flag *uint64, mask uint64, v bool) {
if v {
*flag |= mask
} else {
*flag &= ^mask
}
}
10 changes: 10 additions & 0 deletions sys/termios_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

// Copyright 2015 go-termios Author. All Rights Reserved.
// https://github.com/go-termios/termios
// Author: John Lenton <chipaca@github.com>
Expand Down Expand Up @@ -189,3 +191,11 @@ func Drain(fd uintptr) error {
func Flow(fd uintptr, action int) error {
return ioctlu(fd, unix.TCXONC, uintptr(action))
}

func setFlag(flag *uint32, mask uint32, v bool) {
if v {
*flag |= mask
} else {
*flag &= ^mask
}
}

0 comments on commit 9a5d5a4

Please sign in to comment.