Преглед на файлове

icmp: drop the use of syscall package in platform-independent code

Also re-adjusts build constraints on stubs.

Change-Id: I9c6d8487e17bb1f9e5204e363938a67a7f646c1c
Reviewed-on: https://go-review.googlesource.com/121881
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Mikio Hara преди 7 години
родител
ревизия
a46fb682f0
променени са 3 файла, в които са добавени 10 реда и са изтрити 11 реда
  1. 6 7
      icmp/endpoint.go
  2. 1 1
      icmp/listen_stub.go
  3. 3 3
      icmp/message.go

+ 6 - 7
icmp/endpoint.go

@@ -7,7 +7,6 @@ package icmp
 import (
 	"net"
 	"runtime"
-	"syscall"
 	"time"
 
 	"golang.org/x/net/ipv4"
@@ -47,7 +46,7 @@ func (c *PacketConn) IPv6PacketConn() *ipv6.PacketConn {
 // ReadFrom reads an ICMP message from the connection.
 func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
 	if !c.ok() {
-		return 0, nil, syscall.EINVAL
+		return 0, nil, errInvalidConn
 	}
 	// Please be informed that ipv4.NewPacketConn enables
 	// IP_STRIPHDR option by default on Darwin.
@@ -64,7 +63,7 @@ func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error) {
 // datagram-oriented ICMP endpoint. Otherwise it must be net.IPAddr.
 func (c *PacketConn) WriteTo(b []byte, dst net.Addr) (int, error) {
 	if !c.ok() {
-		return 0, syscall.EINVAL
+		return 0, errInvalidConn
 	}
 	return c.c.WriteTo(b, dst)
 }
@@ -72,7 +71,7 @@ func (c *PacketConn) WriteTo(b []byte, dst net.Addr) (int, error) {
 // Close closes the endpoint.
 func (c *PacketConn) Close() error {
 	if !c.ok() {
-		return syscall.EINVAL
+		return errInvalidConn
 	}
 	return c.c.Close()
 }
@@ -89,7 +88,7 @@ func (c *PacketConn) LocalAddr() net.Addr {
 // endpoint.
 func (c *PacketConn) SetDeadline(t time.Time) error {
 	if !c.ok() {
-		return syscall.EINVAL
+		return errInvalidConn
 	}
 	return c.c.SetDeadline(t)
 }
@@ -98,7 +97,7 @@ func (c *PacketConn) SetDeadline(t time.Time) error {
 // endpoint.
 func (c *PacketConn) SetReadDeadline(t time.Time) error {
 	if !c.ok() {
-		return syscall.EINVAL
+		return errInvalidConn
 	}
 	return c.c.SetReadDeadline(t)
 }
@@ -107,7 +106,7 @@ func (c *PacketConn) SetReadDeadline(t time.Time) error {
 // endpoint.
 func (c *PacketConn) SetWriteDeadline(t time.Time) error {
 	if !c.ok() {
-		return syscall.EINVAL
+		return errInvalidConn
 	}
 	return c.c.SetWriteDeadline(t)
 }

+ 1 - 1
icmp/listen_stub.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build js nacl plan9
+// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
 
 package icmp
 

+ 3 - 3
icmp/message.go

@@ -18,7 +18,6 @@ import (
 	"encoding/binary"
 	"errors"
 	"net"
-	"syscall"
 
 	"golang.org/x/net/internal/iana"
 	"golang.org/x/net/ipv4"
@@ -28,6 +27,7 @@ import (
 // BUG(mikio): This package is not implemented on JS, NaCl and Plan 9.
 
 var (
+	errInvalidConn      = errors.New("invalid connection")
 	errMessageTooShort  = errors.New("message too short")
 	errHeaderTooShort   = errors.New("header too short")
 	errBufferTooShort   = errors.New("buffer too short")
@@ -80,7 +80,7 @@ func (m *Message) Marshal(psh []byte) ([]byte, error) {
 	case ipv6.ICMPType:
 		mtype = int(typ)
 	default:
-		return nil, syscall.EINVAL
+		return nil, errInvalidConn
 	}
 	b := []byte{byte(mtype), byte(m.Code), 0, 0}
 	if m.Type.Protocol() == iana.ProtocolIPv6ICMP && psh != nil {
@@ -143,7 +143,7 @@ func ParseMessage(proto int, b []byte) (*Message, error) {
 	case iana.ProtocolIPv6ICMP:
 		m.Type = ipv6.ICMPType(b[0])
 	default:
-		return nil, syscall.EINVAL
+		return nil, errInvalidConn
 	}
 	if fn, ok := parseFns[m.Type]; !ok {
 		m.Body, err = parseDefaultMessageBody(proto, b[4:])