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.
13 "golang.org/x/net/internal/socket"
16 // BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of
17 // PacketConn are not implemented.
19 // A Message represents an IO message.
21 // type Message struct {
30 // The Buffers fields represents a list of contiguous buffers, which
31 // can be used for vectored IO, for example, putting a header and a
32 // payload in each slice.
33 // When writing, the Buffers field must contain at least one byte to
35 // When reading, the Buffers field will always contain a byte to read.
37 // The OOB field contains protocol-specific control or miscellaneous
38 // ancillary data known as out-of-band data.
39 // It can be nil when not required.
41 // The Addr field specifies a destination address when writing.
42 // It can be nil when the underlying protocol of the endpoint uses
43 // connection-oriented communication.
44 // After a successful read, it may contain the source address on the
47 // The N field indicates the number of bytes read or written from/to
50 // The NN field indicates the number of bytes read or written from/to
53 // The Flags field contains protocol-specific information on the
55 type Message = socket.Message
57 // ReadBatch reads a batch of messages.
59 // The provided flags is a set of platform-dependent flags, such as
62 // On a successful read it returns the number of messages received, up
65 // On Linux, a batch read will be optimized.
66 // On other platforms, this method will read only a single message.
67 func (c *payloadHandler) ReadBatch(ms []Message, flags int) (int, error) {
69 return 0, errInvalidConn
73 n, err := c.RecvMsgs([]socket.Message(ms), flags)
75 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
80 err := c.RecvMsg(&ms[0], flags)
83 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
89 // WriteBatch writes a batch of messages.
91 // The provided flags is a set of platform-dependent flags, such as
92 // syscall.MSG_DONTROUTE.
94 // It returns the number of messages written on a successful write.
96 // On Linux, a batch write will be optimized.
97 // On other platforms, this method will write only a single message.
98 func (c *payloadHandler) WriteBatch(ms []Message, flags int) (int, error) {
100 return 0, errInvalidConn
102 switch runtime.GOOS {
104 n, err := c.SendMsgs([]socket.Message(ms), flags)
106 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
111 err := c.SendMsg(&ms[0], flags)
114 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}