From 7e41abbc6b9f00f84374c69f3acb63b56fcf4728 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Tue, 29 Apr 2014 12:37:16 +0900 Subject: [PATCH] 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 --- src/pkg/net/iprawsock_posix.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pkg/net/iprawsock_posix.go b/src/pkg/net/iprawsock_posix.go index 26fc06e1b6c..bbb3f3ed66c 100644 --- a/src/pkg/net/iprawsock_posix.go +++ b/src/pkg/net/iprawsock_posix.go @@ -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} }