msghdr_linux.go 781 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. package socket
  5. import "unsafe"
  6. func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
  7. for i := range vs {
  8. vs[i].set(bs[i])
  9. }
  10. h.setIov(vs)
  11. if len(oob) > 0 {
  12. h.setControl(oob)
  13. }
  14. if sa != nil {
  15. h.Name = (*byte)(unsafe.Pointer(&sa[0]))
  16. h.Namelen = uint32(len(sa))
  17. } else {
  18. h.Name = nil
  19. h.Namelen = 0
  20. }
  21. }
  22. func (h *msghdr) name() []byte {
  23. if h.Name != nil && h.Namelen > 0 {
  24. return (*[sizeofSockaddrInet6]byte)(unsafe.Pointer(h.Name))[:h.Namelen]
  25. }
  26. return nil
  27. }
  28. func (h *msghdr) controllen() int {
  29. return int(h.Controllen)
  30. }
  31. func (h *msghdr) flags() int {
  32. return int(h.Flags)
  33. }