gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/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 //go:build linux 6 // +build linux 7 8 package socket 9 10 import ( 11 "net" 12 ) 13 14 func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) { 15 for i := range ms { 16 ms[i].raceWrite() 17 } 18 tmps := defaultMmsgTmpsPool.Get() 19 defer defaultMmsgTmpsPool.Put(tmps) 20 var parseFn func([]byte, string) (net.Addr, error) 21 if c.network != "tcp" { 22 parseFn = parseInetAddr 23 } 24 hs := tmps.packer.pack(ms, parseFn, nil) 25 n, err := tmps.syscaller.recvmmsg(c.c, hs, flags) 26 if err != nil { 27 return n, err 28 } 29 if err := hs[:n].unpack(ms[:n], parseFn, c.network); err != nil { 30 return n, err 31 } 32 return n, nil 33 } 34 35 func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) { 36 for i := range ms { 37 ms[i].raceRead() 38 } 39 tmps := defaultMmsgTmpsPool.Get() 40 defer defaultMmsgTmpsPool.Put(tmps) 41 var marshalFn func(net.Addr, []byte) int 42 if c.network != "tcp" { 43 marshalFn = marshalInetAddr 44 } 45 hs := tmps.packer.pack(ms, nil, marshalFn) 46 n, err := tmps.syscaller.sendmmsg(c.c, hs, flags) 47 if err != nil { 48 return n, err 49 } 50 if err := hs[:n].unpack(ms[:n], nil, ""); err != nil { 51 return n, err 52 } 53 return n, nil 54 }