Commit e727e370 authored by Alberto Bertogli's avatar Alberto Bertogli Committed by Ian Lance Taylor

net: document dummy byte in ReadMsgUnix and WriteMsgUnix

ReadMsgUnix and WriteMsgUnix both will read/write 1 byte from/to the
socket if they were given no buffer to read/write, to avoid a common
pitfall in out of band operations (they will usually block
indefinitely if there's no actual data to read).

This patch adds a note about this behaviour in their documentation, so
users can be aware of it.

Change-Id: I751f0e12bb4d80311e94ea8de023595c5d40ec3e
Reviewed-on: https://go-review.googlesource.com/29180
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 897c0ebf
...@@ -120,6 +120,9 @@ func (c *UnixConn) ReadFrom(b []byte) (int, Addr, error) { ...@@ -120,6 +120,9 @@ func (c *UnixConn) ReadFrom(b []byte) (int, Addr, error) {
// the associated out-of-band data into oob. It returns the number of // the associated out-of-band data into oob. It returns the number of
// bytes copied into b, the number of bytes copied into oob, the flags // bytes copied into b, the number of bytes copied into oob, the flags
// that were set on the packet, and the source address of the packet. // that were set on the packet, and the source address of the packet.
//
// Note that if len(b) == 0 and len(oob) > 0, this function will still
// read (and discard) 1 byte from the connection.
func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err error) { func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAddr, err error) {
if !c.ok() { if !c.ok() {
return 0, 0, 0, nil, syscall.EINVAL return 0, 0, 0, nil, syscall.EINVAL
...@@ -167,6 +170,9 @@ func (c *UnixConn) WriteTo(b []byte, addr Addr) (int, error) { ...@@ -167,6 +170,9 @@ func (c *UnixConn) WriteTo(b []byte, addr Addr) (int, error) {
// WriteMsgUnix writes a packet to addr via c, copying the payload // WriteMsgUnix writes a packet to addr via c, copying the payload
// from b and the associated out-of-band data from oob. It returns // from b and the associated out-of-band data from oob. It returns
// the number of payload and out-of-band bytes written. // the number of payload and out-of-band bytes written.
//
// Note that if len(b) == 0 and len(oob) > 0, this function will still
// write 1 byte to the connection.
func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err error) { func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err error) {
if !c.ok() { if !c.ok() {
return 0, 0, syscall.EINVAL return 0, 0, syscall.EINVAL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment