]> Cypherpunks repositories - gostls13.git/commitdiff
net: document dummy byte in ReadMsgUnix and WriteMsgUnix
authorAlberto Bertogli <albertito@blitiri.com.ar>
Thu, 15 Sep 2016 01:32:44 +0000 (02:32 +0100)
committerIan Lance Taylor <iant@golang.org>
Thu, 15 Sep 2016 23:42:46 +0000 (23:42 +0000)
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: Ian Lance Taylor <iant@golang.org>
src/net/unixsock.go

index bacdaa41d9079bc94cc04cd973932dee56819ed3..fffcb87550935c552a74d1b34bb7fdba85143036 100644 (file)
@@ -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