...
1
2
3
4
5
6
7 package socket
8
9 import (
10 "net"
11 )
12
13 func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
14 for i := range ms {
15 ms[i].raceWrite()
16 }
17 tmps := defaultMmsgTmpsPool.Get()
18 defer defaultMmsgTmpsPool.Put(tmps)
19 var parseFn func([]byte, string) (net.Addr, error)
20 if c.network != "tcp" {
21 parseFn = parseInetAddr
22 }
23 hs := tmps.packer.pack(ms, parseFn, nil)
24 n, err := tmps.syscaller.recvmmsg(c.c, hs, flags)
25 if err != nil {
26 return n, err
27 }
28 if err := hs[:n].unpack(ms[:n], parseFn, c.network); err != nil {
29 return n, err
30 }
31 return n, nil
32 }
33
34 func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) {
35 for i := range ms {
36 ms[i].raceRead()
37 }
38 tmps := defaultMmsgTmpsPool.Get()
39 defer defaultMmsgTmpsPool.Put(tmps)
40 var marshalFn func(net.Addr, []byte) int
41 if c.network != "tcp" {
42 marshalFn = marshalInetAddr
43 }
44 hs := tmps.packer.pack(ms, nil, marshalFn)
45 n, err := tmps.syscaller.sendmmsg(c.c, hs, flags)
46 if err != nil {
47 return n, err
48 }
49 if err := hs[:n].unpack(ms[:n], nil, ""); err != nil {
50 return n, err
51 }
52 return n, nil
53 }
54
View as plain text