gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/net/internal/socket/sys_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
     6  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     7  
     8  package socket
     9  
    10  import (
    11  	"syscall"
    12  	"unsafe"
    13  )
    14  
    15  //go:linkname syscall_getsockopt syscall.getsockopt
    16  func syscall_getsockopt(s, level, name int, val unsafe.Pointer, vallen *uint32) error
    17  
    18  //go:linkname syscall_setsockopt syscall.setsockopt
    19  func syscall_setsockopt(s, level, name int, val unsafe.Pointer, vallen uintptr) error
    20  
    21  //go:linkname syscall_recvmsg syscall.recvmsg
    22  func syscall_recvmsg(s int, msg *syscall.Msghdr, flags int) (int, error)
    23  
    24  //go:linkname syscall_sendmsg syscall.sendmsg
    25  func syscall_sendmsg(s int, msg *syscall.Msghdr, flags int) (int, error)
    26  
    27  func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
    28  	l := uint32(len(b))
    29  	err := syscall_getsockopt(int(s), level, name, unsafe.Pointer(&b[0]), &l)
    30  	return int(l), err
    31  }
    32  
    33  func setsockopt(s uintptr, level, name int, b []byte) error {
    34  	return syscall_setsockopt(int(s), level, name, unsafe.Pointer(&b[0]), uintptr(len(b)))
    35  }
    36  
    37  func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
    38  	return syscall_recvmsg(int(s), (*syscall.Msghdr)(unsafe.Pointer(h)), flags)
    39  }
    40  
    41  func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
    42  	return syscall_sendmsg(int(s), (*syscall.Msghdr)(unsafe.Pointer(h)), flags)
    43  }