github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/internal/socket/rawconn_msg.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 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows 6 7 package socket 8 9 import ( 10 "os" 11 "syscall" 12 ) 13 14 func (c *Conn) recvMsg(m *Message, flags int) error { 15 m.raceWrite() 16 var h msghdr 17 vs := make([]iovec, len(m.Buffers)) 18 var sa []byte 19 if c.network != "tcp" { 20 sa = make([]byte, sizeofSockaddrInet6) 21 } 22 h.pack(vs, m.Buffers, m.OOB, sa) 23 var operr error 24 var n int 25 fn := func(s uintptr) bool { 26 n, operr = recvmsg(s, &h, flags) 27 if operr == syscall.EAGAIN { 28 return false 29 } 30 return true 31 } 32 if err := c.c.Read(fn); err != nil { 33 return err 34 } 35 if operr != nil { 36 return os.NewSyscallError("recvmsg", operr) 37 } 38 if c.network != "tcp" { 39 var err error 40 m.Addr, err = parseInetAddr(sa[:], c.network) 41 if err != nil { 42 return err 43 } 44 } 45 m.N = n 46 m.NN = h.controllen() 47 m.Flags = h.flags() 48 return nil 49 } 50 51 func (c *Conn) sendMsg(m *Message, flags int) error { 52 m.raceRead() 53 var h msghdr 54 vs := make([]iovec, len(m.Buffers)) 55 var sa []byte 56 if m.Addr != nil { 57 sa = marshalInetAddr(m.Addr) 58 } 59 h.pack(vs, m.Buffers, m.OOB, sa) 60 var operr error 61 var n int 62 fn := func(s uintptr) bool { 63 n, operr = sendmsg(s, &h, flags) 64 if operr == syscall.EAGAIN { 65 return false 66 } 67 return true 68 } 69 if err := c.c.Write(fn); err != nil { 70 return err 71 } 72 if operr != nil { 73 return os.NewSyscallError("sendmsg", operr) 74 } 75 m.N = n 76 m.NN = len(m.OOB) 77 return nil 78 }