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 // BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of
21 // RawConn are not implemented.
23 // A Message represents an IO message.
25 // type Message struct {
34 // The Buffers fields represents a list of contiguous buffers, which
35 // can be used for vectored IO, for example, putting a header and a
36 // payload in each slice.
37 // When writing, the Buffers field must contain at least one byte to
39 // When reading, the Buffers field will always contain a byte to read.
41 // The OOB field contains protocol-specific control or miscellaneous
42 // ancillary data known as out-of-band data.
43 // It can be nil when not required.
45 // The Addr field specifies a destination address when writing.
46 // It can be nil when the underlying protocol of the endpoint uses
47 // connection-oriented communication.
48 // After a successful read, it may contain the source address on the
51 // The N field indicates the number of bytes read or written from/to
54 // The NN field indicates the number of bytes read or written from/to
57 // The Flags field contains protocol-specific information on the
59 type Message = socket.Message
61 // ReadBatch reads a batch of messages.
63 // The provided flags is a set of platform-dependent flags, such as
66 // On a successful read it returns the number of messages received, up
69 // On Linux, a batch read will be optimized.
70 // On other platforms, this method will read only a single message.
72 // Unlike the ReadFrom method, it doesn't strip the IPv4 header
73 // followed by option headers from the received IPv4 datagram when the
74 // underlying transport is net.IPConn. Each Buffers field of Message
75 // must be large enough to accommodate an IPv4 header and option
77 func (c *payloadHandler) ReadBatch(ms []Message, flags int) (int, error) {
79 return 0, syscall.EINVAL
83 n, err := c.RecvMsgs([]socket.Message(ms), flags)
85 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
90 err := c.RecvMsg(&ms[0], flags)
93 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
99 // WriteBatch writes a batch of messages.
101 // The provided flags is a set of platform-dependent flags, such as
102 // syscall.MSG_DONTROUTE.
104 // It returns the number of messages written on a successful write.
106 // On Linux, a batch write will be optimized.
107 // On other platforms, this method will write only a single message.
108 func (c *payloadHandler) WriteBatch(ms []Message, flags int) (int, error) {
110 return 0, syscall.EINVAL
112 switch runtime.GOOS {
114 n, err := c.SendMsgs([]socket.Message(ms), flags)
116 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
121 err := c.SendMsg(&ms[0], flags)
124 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
130 // ReadBatch reads a batch of messages.
132 // The provided flags is a set of platform-dependent flags, such as
135 // On a successful read it returns the number of messages received, up
138 // On Linux, a batch read will be optimized.
139 // On other platforms, this method will read only a single message.
140 func (c *packetHandler) ReadBatch(ms []Message, flags int) (int, error) {
142 return 0, syscall.EINVAL
144 switch runtime.GOOS {
146 n, err := c.RecvMsgs([]socket.Message(ms), flags)
148 err = &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
153 err := c.RecvMsg(&ms[0], flags)
156 err = &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
162 // WriteBatch writes a batch of messages.
164 // The provided flags is a set of platform-dependent flags, such as
165 // syscall.MSG_DONTROUTE.
167 // It returns the number of messages written on a successful write.
169 // On Linux, a batch write will be optimized.
170 // On other platforms, this method will write only a single message.
171 func (c *packetHandler) WriteBatch(ms []Message, flags int) (int, error) {
173 return 0, syscall.EINVAL
175 switch runtime.GOOS {
177 n, err := c.SendMsgs([]socket.Message(ms), flags)
179 err = &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
184 err := c.SendMsg(&ms[0], flags)
187 err = &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}