From e727e37090de987f2fafd48a02cd39455dff2ca5 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Thu, 15 Sep 2016 02:32:44 +0100 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/unixsock.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/net/unixsock.go b/src/net/unixsock.go index bacdaa41d9..fffcb87550 100644 --- a/src/net/unixsock.go +++ b/src/net/unixsock.go @@ -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 // 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. +// +// 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) { if !c.ok() { return 0, 0, 0, nil, syscall.EINVAL @@ -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 // from b and the associated out-of-band data from oob. It returns // 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) { if !c.ok() { return 0, 0, syscall.EINVAL -- 2.48.1