mirror of
https://github.com/golang/go
synced 2024-11-18 09:24:54 -07:00
net: update documentation on Dial{TCP,UDP,IP,Unix}
This change clarifies the documentation on Dial{TCP,UDP,IP,Unix} to avoid unnecessary confusion about how the arguments for the connection setup functions are used to make connections. Change-Id: I2e378182948fbe221f6ae786ab55e77ae90c3f3b Reviewed-on: https://go-review.googlesource.com/34877 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
424b0654f8
commit
1ed79b87f5
@ -200,13 +200,17 @@ func (c *IPConn) WriteMsgIP(b, oob []byte, addr *IPAddr) (n, oobn int, err error
|
|||||||
|
|
||||||
func newIPConn(fd *netFD) *IPConn { return &IPConn{conn{fd}} }
|
func newIPConn(fd *netFD) *IPConn { return &IPConn{conn{fd}} }
|
||||||
|
|
||||||
// DialIP connects to the remote address raddr on the network protocol
|
// DialIP acts like Dial for IP networks.
|
||||||
// netProto, which must be "ip", "ip4", or "ip6" followed by a colon
|
//
|
||||||
// and a protocol number or name.
|
// The network must be an IP network name; see func Dial for details.
|
||||||
func DialIP(netProto string, laddr, raddr *IPAddr) (*IPConn, error) {
|
//
|
||||||
c, err := dialIP(context.Background(), netProto, laddr, raddr)
|
// If laddr is nil, a local address is automatically chosen.
|
||||||
|
// If the IP field of raddr is nil or an unspecified IP address, the
|
||||||
|
// local system is assumed.
|
||||||
|
func DialIP(network string, laddr, raddr *IPAddr) (*IPConn, error) {
|
||||||
|
c, err := dialIP(context.Background(), network, laddr, raddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &OpError{Op: "dial", Net: netProto, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -190,21 +190,25 @@ func newTCPConn(fd *netFD) *TCPConn {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialTCP connects to the remote address raddr on the network net,
|
// DialTCP acts like Dial for TCP networks.
|
||||||
// which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is
|
//
|
||||||
// used as the local address for the connection.
|
// The network must be a TCP network name; see func Dial for details.
|
||||||
func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
|
//
|
||||||
switch net {
|
// If laddr is nil, a local address is automatically chosen.
|
||||||
|
// If the IP field of raddr is nil or an unspecified IP address, the
|
||||||
|
// local system is assumed.
|
||||||
|
func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPConn, error) {
|
||||||
|
switch network {
|
||||||
case "tcp", "tcp4", "tcp6":
|
case "tcp", "tcp4", "tcp6":
|
||||||
default:
|
default:
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: UnknownNetworkError(net)}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: UnknownNetworkError(network)}
|
||||||
}
|
}
|
||||||
if raddr == nil {
|
if raddr == nil {
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: nil, Err: errMissingAddress}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: nil, Err: errMissingAddress}
|
||||||
}
|
}
|
||||||
c, err := dialTCP(context.Background(), net, laddr, raddr)
|
c, err := dialTCP(context.Background(), network, laddr, raddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -193,21 +193,25 @@ func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *UDPAddr) (n, oobn int, err er
|
|||||||
|
|
||||||
func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{conn{fd}} }
|
func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{conn{fd}} }
|
||||||
|
|
||||||
// DialUDP connects to the remote address raddr on the network net,
|
// DialUDP acts like Dial for UDP networks.
|
||||||
// which must be "udp", "udp4", or "udp6". If laddr is not nil, it is
|
//
|
||||||
// used as the local address for the connection.
|
// The network must be a UDP network name; see func Dial for details.
|
||||||
func DialUDP(net string, laddr, raddr *UDPAddr) (*UDPConn, error) {
|
//
|
||||||
switch net {
|
// If laddr is nil, a local address is automatically chosen.
|
||||||
|
// If the IP field of raddr is nil or an unspecified IP address, the
|
||||||
|
// local system is assumed.
|
||||||
|
func DialUDP(network string, laddr, raddr *UDPAddr) (*UDPConn, error) {
|
||||||
|
switch network {
|
||||||
case "udp", "udp4", "udp6":
|
case "udp", "udp4", "udp6":
|
||||||
default:
|
default:
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: UnknownNetworkError(net)}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: UnknownNetworkError(network)}
|
||||||
}
|
}
|
||||||
if raddr == nil {
|
if raddr == nil {
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: nil, Err: errMissingAddress}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: nil, Err: errMissingAddress}
|
||||||
}
|
}
|
||||||
c, err := dialUDP(context.Background(), net, laddr, raddr)
|
c, err := dialUDP(context.Background(), network, laddr, raddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -196,18 +196,21 @@ func (c *UnixConn) WriteMsgUnix(b, oob []byte, addr *UnixAddr) (n, oobn int, err
|
|||||||
|
|
||||||
func newUnixConn(fd *netFD) *UnixConn { return &UnixConn{conn{fd}} }
|
func newUnixConn(fd *netFD) *UnixConn { return &UnixConn{conn{fd}} }
|
||||||
|
|
||||||
// DialUnix connects to the remote address raddr on the network net,
|
// DialUnix acts like Dial for Unix networks.
|
||||||
// which must be "unix", "unixgram" or "unixpacket". If laddr is not
|
//
|
||||||
// nil, it is used as the local address for the connection.
|
// The network must be a Unix network name; see func Dial for details.
|
||||||
func DialUnix(net string, laddr, raddr *UnixAddr) (*UnixConn, error) {
|
//
|
||||||
switch net {
|
// If laddr is non-nil, it is used as the local address for the
|
||||||
|
// connection.
|
||||||
|
func DialUnix(network string, laddr, raddr *UnixAddr) (*UnixConn, error) {
|
||||||
|
switch network {
|
||||||
case "unix", "unixgram", "unixpacket":
|
case "unix", "unixgram", "unixpacket":
|
||||||
default:
|
default:
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: UnknownNetworkError(net)}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: UnknownNetworkError(network)}
|
||||||
}
|
}
|
||||||
c, err := dialUnix(context.Background(), net, laddr, raddr)
|
c, err := dialUnix(context.Background(), network, laddr, raddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &OpError{Op: "dial", Net: net, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user