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:
Mikio Hara 2017-01-08 17:18:20 +09:00
parent 424b0654f8
commit 1ed79b87f5
4 changed files with 47 additions and 32 deletions

View file

@ -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}} }
// DialUnix connects to the remote address raddr on the network net,
// which must be "unix", "unixgram" or "unixpacket". If laddr is not
// nil, it is used as the local address for the connection.
func DialUnix(net string, laddr, raddr *UnixAddr) (*UnixConn, error) {
switch net {
// DialUnix acts like Dial for Unix networks.
//
// The network must be a Unix network name; see func Dial for details.
//
// 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":
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 {
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
}