github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/internal/socket/rawconn_mmsg.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 linux 6 7 package socket 8 9 import ( 10 "net" 11 "os" 12 "syscall" 13 ) 14 15 func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) { 16 for i := range ms { 17 ms[i].raceWrite() 18 } 19 hs := make(mmsghdrs, len(ms)) 20 var parseFn func([]byte, string) (net.Addr, error) 21 if c.network != "tcp" { 22 parseFn = parseInetAddr 23 } 24 if err := hs.pack(ms, parseFn, nil); err != nil { 25 return 0, err 26 } 27 var operr error 28 var n int 29 fn := func(s uintptr) bool { 30 n, operr = recvmmsg(s, hs, flags) 31 if operr == syscall.EAGAIN { 32 return false 33 } 34 return true 35 } 36 if err := c.c.Read(fn); err != nil { 37 return n, err 38 } 39 if operr != nil { 40 return n, os.NewSyscallError("recvmmsg", operr) 41 } 42 if err := hs[:n].unpack(ms[:n], parseFn, c.network); err != nil { 43 return n, err 44 } 45 return n, nil 46 } 47 48 func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) { 49 for i := range ms { 50 ms[i].raceRead() 51 } 52 hs := make(mmsghdrs, len(ms)) 53 var marshalFn func(net.Addr) []byte 54 if c.network != "tcp" { 55 marshalFn = marshalInetAddr 56 } 57 if err := hs.pack(ms, nil, marshalFn); err != nil { 58 return 0, err 59 } 60 var operr error 61 var n int 62 fn := func(s uintptr) bool { 63 n, operr = sendmmsg(s, hs, 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 n, err 71 } 72 if operr != nil { 73 return n, os.NewSyscallError("sendmmsg", operr) 74 } 75 if err := hs[:n].unpack(ms[:n], nil, ""); err != nil { 76 return n, err 77 } 78 return n, nil 79 }