1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:50:07 -07:00

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
This commit is contained in:
Mikio Hara 2014-04-29 12:37:16 +09:00
parent 4cc708ae1d
commit 7e41abbc6b

View File

@ -133,6 +133,9 @@ func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
if c.fd.isConnected {
return 0, &OpError{Op: "write", Net: c.fd.net, Addr: addr, Err: ErrWriteToConnected}
}
if addr == nil { if addr == nil {
return 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress} 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() { if !c.ok() {
return 0, 0, syscall.EINVAL 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 { if addr == nil {
return 0, 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress} return 0, 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress}
} }