Source File
batch.go
Belonging Package
golang.org/x/net/ipv4
// Copyright 2017 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package ipv4import ()// BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of// PacketConn are not implemented.// BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of// RawConn are not implemented.// A Message represents an IO message.//// type Message struct {// Buffers [][]byte// OOB []byte// Addr net.Addr// N int// NN int// Flags int// }//// The Buffers fields represents a list of contiguous buffers, which// can be used for vectored IO, for example, putting a header and a// payload in each slice.// When writing, the Buffers field must contain at least one byte to// write.// When reading, the Buffers field will always contain a byte to read.//// The OOB field contains protocol-specific control or miscellaneous// ancillary data known as out-of-band data.// It can be nil when not required.//// The Addr field specifies a destination address when writing.// It can be nil when the underlying protocol of the endpoint uses// connection-oriented communication.// After a successful read, it may contain the source address on the// received packet.//// The N field indicates the number of bytes read or written from/to// Buffers.//// The NN field indicates the number of bytes read or written from/to// OOB.//// The Flags field contains protocol-specific information on the// received message.type Message = socket.Message// 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 message.//// Unlike the ReadFrom method, it doesn't strip the IPv4 header// followed by option headers from the received IPv4 datagram when the// underlying transport is net.IPConn. Each Buffers field of Message// must be large enough to accommodate an IPv4 header and option// headers.func ( *payloadHandler) ( []Message, int) (int, error) {if !.ok() {return 0, errInvalidConn}switch runtime.GOOS {case "linux":, := .RecvMsgs([]socket.Message(), )if != nil {= &net.OpError{Op: "read", Net: .PacketConn.LocalAddr().Network(), Source: .PacketConn.LocalAddr(), Err: }}return ,default::= 1:= .RecvMsg(&[0], )if != nil {= 0= &net.OpError{Op: "read", Net: .PacketConn.LocalAddr().Network(), Source: .PacketConn.LocalAddr(), Err: }}if compatFreeBSD32 && [0].NN > 0 {adjustFreeBSD32(&[0])}return ,}}// WriteBatch writes a batch of messages.//// The provided flags is a set of platform-dependent flags, such as// syscall.MSG_DONTROUTE.//// It returns the number of messages written on a successful write.//// On Linux, a batch write will be optimized.// On other platforms, this method will write only a single message.func ( *payloadHandler) ( []Message, int) (int, error) {if !.ok() {return 0, errInvalidConn}switch runtime.GOOS {case "linux":, := .SendMsgs([]socket.Message(), )if != nil {= &net.OpError{Op: "write", Net: .PacketConn.LocalAddr().Network(), Source: .PacketConn.LocalAddr(), Err: }}return ,default::= 1:= .SendMsg(&[0], )if != nil {= 0= &net.OpError{Op: "write", Net: .PacketConn.LocalAddr().Network(), Source: .PacketConn.LocalAddr(), Err: }}return ,}}// 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 message.func ( *packetHandler) ( []Message, int) (int, error) {if !.ok() {return 0, errInvalidConn}switch runtime.GOOS {case "linux":, := .RecvMsgs([]socket.Message(), )if != nil {= &net.OpError{Op: "read", Net: .IPConn.LocalAddr().Network(), Source: .IPConn.LocalAddr(), Err: }}return ,default::= 1:= .RecvMsg(&[0], )if != nil {= 0= &net.OpError{Op: "read", Net: .IPConn.LocalAddr().Network(), Source: .IPConn.LocalAddr(), Err: }}if compatFreeBSD32 && [0].NN > 0 {adjustFreeBSD32(&[0])}return ,}}// WriteBatch writes a batch of messages.//// The provided flags is a set of platform-dependent flags, such as// syscall.MSG_DONTROUTE.//// It returns the number of messages written on a successful write.//// On Linux, a batch write will be optimized.// On other platforms, this method will write only a single message.func ( *packetHandler) ( []Message, int) (int, error) {if !.ok() {return 0, errInvalidConn}switch runtime.GOOS {case "linux":, := .SendMsgs([]socket.Message(), )if != nil {= &net.OpError{Op: "write", Net: .IPConn.LocalAddr().Network(), Source: .IPConn.LocalAddr(), Err: }}return ,default::= 1:= .SendMsg(&[0], )if != nil {= 0= &net.OpError{Op: "write", Net: .IPConn.LocalAddr().Network(), Source: .IPConn.LocalAddr(), Err: }}return ,}}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |