mirror of
https://github.com/golang/go
synced 2024-11-23 13:00: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:
parent
4cc708ae1d
commit
7e41abbc6b
@ -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}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user