complete_dontwait.go 798 B

1234567891011121314151617181920212223242526
  1. // Copyright 2021 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
  5. // +build darwin dragonfly freebsd linux netbsd openbsd solaris
  6. package socket
  7. import (
  8. "syscall"
  9. )
  10. // ioComplete checks the flags and result of a syscall, to be used as return
  11. // value in a syscall.RawConn.Read or Write callback.
  12. func ioComplete(flags int, operr error) bool {
  13. if flags&syscall.MSG_DONTWAIT != 0 {
  14. // Caller explicitly said don't wait, so always return immediately.
  15. return true
  16. }
  17. if operr == syscall.EAGAIN || operr == syscall.EWOULDBLOCK {
  18. // No data available, block for I/O and try again.
  19. return false
  20. }
  21. return true
  22. }