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 messa
(ms []Message, flags int)
| 94 | // On Linux, a batch write will be optimized. |
| 95 | // On other platforms, this method will write only a single message. |
| 96 | func (c *payloadHandler) WriteBatch(ms []Message, flags int) (int, error) { |
| 97 | if !c.ok() { |
| 98 | return 0, errInvalidConn |
| 99 | } |
| 100 | switch runtime.GOOS { |
| 101 | case "linux": |
| 102 | n, err := c.SendMsgs([]socket.Message(ms), flags) |
| 103 | if err != nil { |
| 104 | err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err} |
| 105 | } |
| 106 | return n, err |
| 107 | default: |
| 108 | n := 1 |
| 109 | err := c.SendMsg(&ms[0], flags) |
| 110 | if err != nil { |
| 111 | n = 0 |
| 112 | err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err} |
| 113 | } |
| 114 | return n, err |
| 115 | } |
| 116 | } |