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