mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-04 10:57:50 +08:00
Much better sys.SetNonblock...
This commit is contained in:
parent
79f80b94e9
commit
4a1415dcda
|
@ -66,7 +66,7 @@ type Reader struct {
|
|||
}
|
||||
|
||||
func NewReader(f *os.File) *Reader {
|
||||
if err := sys.SetNonblock(int(f.Fd())); err != nil {
|
||||
if err := sys.SetNonblock(int(f.Fd()), true); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
rd := &Reader{
|
||||
|
|
13
sys/fcntl.go
13
sys/fcntl.go
|
@ -19,7 +19,16 @@ func GetNonblock(fd int) (bool, error) {
|
|||
return r&syscall.O_NONBLOCK != 0, err
|
||||
}
|
||||
|
||||
func SetNonblock(fd int) error {
|
||||
_, err := Fcntl(fd, syscall.F_SETFL, syscall.O_NONBLOCK)
|
||||
func SetNonblock(fd int, nonblock bool) error {
|
||||
r, err := Fcntl(fd, syscall.F_GETFL, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if nonblock {
|
||||
r |= syscall.O_NONBLOCK
|
||||
} else {
|
||||
r &^= syscall.O_NONBLOCK
|
||||
}
|
||||
_, err = Fcntl(fd, syscall.F_SETFL, r)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user