mirror of
https://github.com/golang/go.git
synced 2025-05-31 23:25:39 +00:00
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: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
897c0ebf61
commit
e727e37090
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user