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.
14 "golang.org/x/net/internal/socket"
17 // BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of
18 // PacketConn are not implemented.
20 // A Message represents an IO message.
22 // type Message struct {
31 // The Buffers fields represents a list of contiguous buffers, which
32 // can be used for vectored IO, for example, putting a header and a
33 // payload in each slice.
34 // When writing, the Buffers field must contain at least one byte to
36 // When reading, the Buffers field will always contain a byte to read.
38 // The OOB field contains protocol-specific control or miscellaneous
39 // ancillary data known as out-of-band data.
40 // It can be nil when not required.
42 // The Addr field specifies a destination address when writing.
43 // It can be nil when the underlying protocol of the endpoint uses
44 // connection-oriented communication.
45 // After a successful read, it may contain the source address on the
48 // The N field indicates the number of bytes read or written from/to
51 // The NN field indicates the number of bytes read or written from/to
54 // The Flags field contains protocol-specific information on the
56 type Message = socket.Message
58 // ReadBatch reads a batch of messages.
60 // The provided flags is a set of platform-dependent flags, such as
63 // On a successful read it returns the number of messages received, up
66 // On Linux, a batch read will be optimized.
67 // On other platforms, this method will read only a single message.
68 func (c *payloadHandler) ReadBatch(ms []Message, flags int) (int, error) {
70 return 0, syscall.EINVAL
74 n, err := c.RecvMsgs([]socket.Message(ms), flags)
76 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
81 err := c.RecvMsg(&ms[0], flags)
84 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
90 // WriteBatch writes a batch of messages.
92 // The provided flags is a set of platform-dependent flags, such as
93 // syscall.MSG_DONTROUTE.
95 // It returns the number of messages written on a successful write.
97 // On Linux, a batch write will be optimized.
98 // On other platforms, this method will write only a single message.
99 func (c *payloadHandler) WriteBatch(ms []Message, flags int) (int, error) {
101 return 0, syscall.EINVAL
103 switch runtime.GOOS {
105 n, err := c.SendMsgs([]socket.Message(ms), flags)
107 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
112 err := c.SendMsg(&ms[0], flags)
115 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}