gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/internal/socket/error_unix.go (about)

     1  // Copyright 2017 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  
     5  //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
     6  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos
     7  
     8  package socket
     9  
    10  import "syscall"
    11  
    12  var (
    13  	errEAGAIN error = syscall.EAGAIN
    14  	errEINVAL error = syscall.EINVAL
    15  	errENOENT error = syscall.ENOENT
    16  )
    17  
    18  // errnoErr returns common boxed Errno values, to prevent allocations
    19  // at runtime.
    20  func errnoErr(errno syscall.Errno) error {
    21  	switch errno {
    22  	case 0:
    23  		return nil
    24  	case syscall.EAGAIN:
    25  		return errEAGAIN
    26  	case syscall.EINVAL:
    27  		return errEINVAL
    28  	case syscall.ENOENT:
    29  		return errENOENT
    30  	}
    31  	return errno
    32  }