Commit 7e41abbc authored by Mikio Hara's avatar Mikio Hara

net: make WriteTo, WriteToIP and WriteMsgIP fail when IPConn is already connected

This CL tries to fill the gap between Linux and other Unix-like systems
in the same way UDPConn and UnixConn already did.

Fixes #7887.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/97810043
parent 4cc708ae
......@@ -133,6 +133,9 @@ func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (int, error) {
if !c.ok() {
return 0, syscall.EINVAL
}
if c.fd.isConnected {
return 0, &OpError{Op: "write", Net: c.fd.net, Addr: addr, Err: ErrWriteToConnected}
}
if addr == nil {
return 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress}
}
......@@ -162,6 +165,9 @@ func (c *IPConn) WriteMsgIP(b, oob []byte, addr *IPAddr) (n, oobn int, err error
if !c.ok() {
return 0, 0, syscall.EINVAL
}
if c.fd.isConnected {
return 0, 0, &OpError{Op: "write", Net: c.fd.net, Addr: addr, Err: ErrWriteToConnected}
}
if addr == nil {
return 0, 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress}
}
......
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