From 275755401dabce1b625fd33960bd1d12eaab7ebb Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Tue, 21 Apr 2015 23:15:12 +0900 Subject: [PATCH] net: fix WriteTo on Plan 9 This change excludes internal UDP header size from a result of number of bytes written on WriteTo. Change-Id: I847d57f7f195657b6f14efdf1b4cfab13d4490dd Reviewed-on: https://go-review.googlesource.com/9196 Reviewed-by: Brad Fitzpatrick Reviewed-by: David du Colombier <0intro@gmail.com> --- src/net/udpsock_plan9.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/net/udpsock_plan9.go b/src/net/udpsock_plan9.go index 4749dab8f1..8acbb20163 100644 --- a/src/net/udpsock_plan9.go +++ b/src/net/udpsock_plan9.go @@ -86,11 +86,10 @@ func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (int, error) { buf := make([]byte, udpHeaderSize+len(b)) i := copy(buf, h.Bytes()) copy(buf[i:], b) - n, err := c.fd.data.Write(buf) - if err != nil { - err = &OpError{Op: "write", Net: c.fd.dir, Addr: addr, Err: err} + if _, err := c.fd.data.Write(buf); err != nil { + return 0, &OpError{Op: "write", Net: c.fd.dir, Addr: addr, Err: err} } - return n, err + return len(b), nil } // WriteTo implements the PacketConn WriteTo method.