]> Cypherpunks repositories - gostls13.git/commitdiff
net: make WriteTo, WriteToIP and WriteMsgIP fail when IPConn is already connected
authorMikio Hara <mikioh.mikioh@gmail.com>
Tue, 29 Apr 2014 03:37:16 +0000 (12:37 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Tue, 29 Apr 2014 03:37:16 +0000 (12:37 +0900)
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

src/pkg/net/iprawsock_posix.go

index 26fc06e1b6ccae9b6976d234efc060f9b2b13749..bbb3f3ed66c364948f86bd8ee2eb3632bf8e08ab 100644 (file)
@@ -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}
        }