mirror of
https://github.com/golang/go
synced 2024-11-21 21:24:45 -07:00
net: consistent OpError message
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5562047
This commit is contained in:
parent
c1b4be6a4d
commit
77cb8956a0
@ -191,7 +191,7 @@ func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (int, error) {
|
||||
}
|
||||
sa, err := addr.sockaddr(c.fd.family)
|
||||
if err != nil {
|
||||
return 0, &OpError{"writetoip", "ip", addr, err}
|
||||
return 0, &OpError{"write", c.fd.net, addr, err}
|
||||
}
|
||||
return c.fd.WriteTo(b, sa)
|
||||
}
|
||||
@ -203,7 +203,7 @@ func (c *IPConn) WriteTo(b []byte, addr Addr) (int, error) {
|
||||
}
|
||||
a, ok := addr.(*IPAddr)
|
||||
if !ok {
|
||||
return 0, &OpError{"writeto", "ip", addr, os.EINVAL}
|
||||
return 0, &OpError{"write", c.fd.net, addr, os.EINVAL}
|
||||
}
|
||||
return c.WriteToIP(b, a)
|
||||
}
|
||||
@ -221,7 +221,7 @@ func DialIP(netProto string, laddr, raddr *IPAddr) (*IPConn, error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if raddr == nil {
|
||||
return nil, &OpError{"dialip", netProto, nil, errMissingAddress}
|
||||
return nil, &OpError{"dial", netProto, nil, errMissingAddress}
|
||||
}
|
||||
fd, err := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_RAW, proto, "dial", sockaddrToIP)
|
||||
if err != nil {
|
||||
|
@ -60,7 +60,7 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if raddr == nil {
|
||||
return nil, &OpError{"dial", "tcp", nil, errMissingAddress}
|
||||
return nil, &OpError{"dial", net, nil, errMissingAddress}
|
||||
}
|
||||
c1, err := dialPlan9(net, laddr, raddr)
|
||||
if err != nil {
|
||||
@ -87,7 +87,7 @@ func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if laddr == nil {
|
||||
return nil, &OpError{"listen", "tcp", nil, errMissingAddress}
|
||||
return nil, &OpError{"listen", net, nil, errMissingAddress}
|
||||
}
|
||||
l1, err := listenPlan9(net, laddr)
|
||||
if err != nil {
|
||||
|
@ -225,7 +225,7 @@ func (c *TCPConn) File() (f *os.File, err error) { return c.fd.dup() }
|
||||
// as the local address for the connection.
|
||||
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err error) {
|
||||
if raddr == nil {
|
||||
return nil, &OpError{"dial", "tcp", nil, errMissingAddress}
|
||||
return nil, &OpError{"dial", net, nil, errMissingAddress}
|
||||
}
|
||||
fd, e := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_STREAM, 0, "dial", sockaddrToTCP)
|
||||
if e != nil {
|
||||
@ -253,7 +253,7 @@ func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err error) {
|
||||
err = syscall.Listen(fd.sysfd, listenerBacklog)
|
||||
if err != nil {
|
||||
closesocket(fd.sysfd)
|
||||
return nil, &OpError{"listen", "tcp", laddr, err}
|
||||
return nil, &OpError{"listen", net, laddr, err}
|
||||
}
|
||||
l = new(TCPListener)
|
||||
l.fd = fd
|
||||
|
@ -110,7 +110,7 @@ func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
}
|
||||
a, ok := addr.(*UDPAddr)
|
||||
if !ok {
|
||||
return 0, &OpError{"writeto", "udp", addr, os.EINVAL}
|
||||
return 0, &OpError{"write", c.dir, addr, os.EINVAL}
|
||||
}
|
||||
return c.WriteToUDP(b, a)
|
||||
}
|
||||
@ -125,7 +125,7 @@ func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if raddr == nil {
|
||||
return nil, &OpError{"dial", "udp", nil, errMissingAddress}
|
||||
return nil, &OpError{"dial", net, nil, errMissingAddress}
|
||||
}
|
||||
c1, err := dialPlan9(net, laddr, raddr)
|
||||
if err != nil {
|
||||
@ -173,7 +173,7 @@ func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if laddr == nil {
|
||||
return nil, &OpError{"listen", "udp", nil, errMissingAddress}
|
||||
return nil, &OpError{"listen", net, nil, errMissingAddress}
|
||||
}
|
||||
l, err := listenPlan9(net, laddr)
|
||||
if err != nil {
|
||||
|
@ -178,25 +178,25 @@ func (c *UDPConn) ReadFrom(b []byte) (n int, addr Addr, err error) {
|
||||
// an error with Timeout() == true after a fixed time limit;
|
||||
// see SetDeadline and SetWriteDeadline.
|
||||
// On packet-oriented connections, write timeouts are rare.
|
||||
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err error) {
|
||||
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
sa, err1 := addr.sockaddr(c.fd.family)
|
||||
if err1 != nil {
|
||||
return 0, &OpError{Op: "write", Net: "udp", Addr: addr, Err: err1}
|
||||
sa, err := addr.sockaddr(c.fd.family)
|
||||
if err != nil {
|
||||
return 0, &OpError{"write", c.fd.net, addr, err}
|
||||
}
|
||||
return c.fd.WriteTo(b, sa)
|
||||
}
|
||||
|
||||
// WriteTo implements the net.PacketConn WriteTo method.
|
||||
func (c *UDPConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
func (c *UDPConn) WriteTo(b []byte, addr Addr) (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, os.EINVAL
|
||||
}
|
||||
a, ok := addr.(*UDPAddr)
|
||||
if !ok {
|
||||
return 0, &OpError{"writeto", "udp", addr, os.EINVAL}
|
||||
return 0, &OpError{"write", c.fd.net, addr, os.EINVAL}
|
||||
}
|
||||
return c.WriteToUDP(b, a)
|
||||
}
|
||||
@ -211,7 +211,7 @@ func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if raddr == nil {
|
||||
return nil, &OpError{"dial", "udp", nil, errMissingAddress}
|
||||
return nil, &OpError{"dial", net, nil, errMissingAddress}
|
||||
}
|
||||
fd, e := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_DGRAM, 0, "dial", sockaddrToUDP)
|
||||
if e != nil {
|
||||
@ -224,18 +224,18 @@ func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err error) {
|
||||
// local address laddr. The returned connection c's ReadFrom
|
||||
// and WriteTo methods can be used to receive and send UDP
|
||||
// packets with per-packet addressing.
|
||||
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err error) {
|
||||
func ListenUDP(net string, laddr *UDPAddr) (*UDPConn, error) {
|
||||
switch net {
|
||||
case "udp", "udp4", "udp6":
|
||||
default:
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if laddr == nil {
|
||||
return nil, &OpError{"listen", "udp", nil, errMissingAddress}
|
||||
return nil, &OpError{"listen", net, nil, errMissingAddress}
|
||||
}
|
||||
fd, e := internetSocket(net, laddr.toAddr(), nil, syscall.SOCK_DGRAM, 0, "listen", sockaddrToUDP)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
fd, err := internetSocket(net, laddr.toAddr(), nil, syscall.SOCK_DGRAM, 0, "listen", sockaddrToUDP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newUDPConn(fd), nil
|
||||
}
|
||||
@ -275,7 +275,7 @@ func (c *UDPConn) LeaveGroup(ifi *Interface, addr IP) error {
|
||||
func joinIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
err := joinIPv4Group(c.fd, ifi, ip)
|
||||
if err != nil {
|
||||
return &OpError{"joinipv4group", "udp", &IPAddr{ip}, err}
|
||||
return &OpError{"joinipv4group", c.fd.net, &IPAddr{ip}, err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -283,7 +283,7 @@ func joinIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
func leaveIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
err := leaveIPv4Group(c.fd, ifi, ip)
|
||||
if err != nil {
|
||||
return &OpError{"leaveipv4group", "udp", &IPAddr{ip}, err}
|
||||
return &OpError{"leaveipv4group", c.fd.net, &IPAddr{ip}, err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -291,7 +291,7 @@ func leaveIPv4GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
func joinIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
err := joinIPv6Group(c.fd, ifi, ip)
|
||||
if err != nil {
|
||||
return &OpError{"joinipv6group", "udp", &IPAddr{ip}, err}
|
||||
return &OpError{"joinipv6group", c.fd.net, &IPAddr{ip}, err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -299,7 +299,7 @@ func joinIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
func leaveIPv6GroupUDP(c *UDPConn, ifi *Interface, ip IP) error {
|
||||
err := leaveIPv6Group(c.fd, ifi, ip)
|
||||
if err != nil {
|
||||
return &OpError{"leaveipv6group", "udp", &IPAddr{ip}, err}
|
||||
return &OpError{"leaveipv6group", c.fd.net, &IPAddr{ip}, err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ func (c *UnixConn) WriteTo(b []byte, addr Addr) (n int, err error) {
|
||||
}
|
||||
a, ok := addr.(*UnixAddr)
|
||||
if !ok {
|
||||
return 0, &OpError{"writeto", "unix", addr, os.EINVAL}
|
||||
return 0, &OpError{"write", c.fd.net, addr, os.EINVAL}
|
||||
}
|
||||
return c.WriteToUnix(b, a)
|
||||
}
|
||||
@ -330,7 +330,7 @@ func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error) {
|
||||
err = syscall.Listen(fd.sysfd, listenerBacklog)
|
||||
if err != nil {
|
||||
closesocket(fd.sysfd)
|
||||
return nil, &OpError{Op: "listen", Net: "unix", Addr: laddr, Err: err}
|
||||
return nil, &OpError{Op: "listen", Net: net, Addr: laddr, Err: err}
|
||||
}
|
||||
return &UnixListener{fd, laddr.Name}, nil
|
||||
}
|
||||
@ -412,7 +412,7 @@ func ListenUnixgram(net string, laddr *UnixAddr) (c *UDPConn, err error) {
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if laddr == nil {
|
||||
return nil, &OpError{"listen", "unixgram", nil, errMissingAddress}
|
||||
return nil, &OpError{"listen", net, nil, errMissingAddress}
|
||||
}
|
||||
fd, e := unixSocket(net, laddr, nil, "listen")
|
||||
if e != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user