ReadBatch reads a batch of messages. The provided flags is a set of platform-dependent flags, such as syscall.MSG_PEEK. On a successful read it returns the number of messages received, up to len(ms). On Linux, a batch read will be optimized. On other platforms, this method will read only a single
(ms []Message, flags int)
| 72 | // must be large enough to accommodate an IPv4 header and option |
| 73 | // headers. |
| 74 | func (c *payloadHandler) ReadBatch(ms []Message, flags int) (int, error) { |
| 75 | if !c.ok() { |
| 76 | return 0, errInvalidConn |
| 77 | } |
| 78 | switch runtime.GOOS { |
| 79 | case "linux": |
| 80 | n, err := c.RecvMsgs([]socket.Message(ms), flags) |
| 81 | if err != nil { |
| 82 | err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err} |
| 83 | } |
| 84 | return n, err |
| 85 | default: |
| 86 | n := 1 |
| 87 | err := c.RecvMsg(&ms[0], flags) |
| 88 | if err != nil { |
| 89 | n = 0 |
| 90 | err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err} |
| 91 | } |
| 92 | if compatFreeBSD32 && ms[0].NN > 0 { |
| 93 | adjustFreeBSD32(&ms[0]) |
| 94 | } |
| 95 | return n, err |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // WriteBatch writes a batch of messages. |
| 100 | // |