github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/net/internal/socket/msghdr_linux.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  package socket
     6  
     7  import "unsafe"
     8  
     9  func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
    10  	for i := range vs {
    11  		vs[i].set(bs[i])
    12  	}
    13  	h.setIov(vs)
    14  	if len(oob) > 0 {
    15  		h.setControl(oob)
    16  	}
    17  	if sa != nil {
    18  		h.Name = (*byte)(unsafe.Pointer(&sa[0]))
    19  		h.Namelen = uint32(len(sa))
    20  	} else {
    21  		h.Name = nil
    22  		h.Namelen = 0
    23  	}
    24  }
    25  
    26  func (h *msghdr) name() []byte {
    27  	if h.Name != nil && h.Namelen > 0 {
    28  		return (*[sizeofSockaddrInet6]byte)(unsafe.Pointer(h.Name))[:h.Namelen]
    29  	}
    30  	return nil
    31  }
    32  
    33  func (h *msghdr) controllen() int {
    34  	return int(h.Controllen)
    35  }
    36  
    37  func (h *msghdr) flags() int {
    38  	return int(h.Flags)
    39  }