complete_dontwait.go 734 B

12345678910111213141516171819202122232425
  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. package socket
  6. import (
  7. "syscall"
  8. )
  9. // ioComplete checks the flags and result of a syscall, to be used as return
  10. // value in a syscall.RawConn.Read or Write callback.
  11. func ioComplete(flags int, operr error) bool {
  12. if flags&syscall.MSG_DONTWAIT != 0 {
  13. // Caller explicitly said don't wait, so always return immediately.
  14. return true
  15. }
  16. if operr == syscall.EAGAIN || operr == syscall.EWOULDBLOCK {
  17. // No data available, block for I/O and try again.
  18. return false
  19. }
  20. return true
  21. }