Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(760)

Delta Between Two Patch Sets: src/pkg/net/dial.go

Issue 4244055: code review 4244055: net: drop laddr from Dial, cname from LookupHost; new f... (Closed)
Left Patch Set: diff -r 424b74bdf29e https://go.googlecode.com/hg/ Created 13 years ago
Right Patch Set: diff -r 8b9c0b903333 https://go.googlecode.com/hg/ Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/cgo_stub.go ('k') | src/pkg/net/dialgoogle_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package net 5 package net
6 6
7 import "os" 7 import "os"
8 8
9 // Dial connects to the address addr on the network net. 9 // Dial connects to the address addr on the network net.
10 // 10 //
11 // Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), 11 // Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only),
12 // "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" 12 // "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4"
13 // (IPv4-only), "ip6" (IPv6-only), "unix" and "unixgram". 13 // (IPv4-only), "ip6" (IPv6-only), "unix" and "unixgram".
14 // 14 //
15 // For IP networks, addresses have the form host:port. If host is 15 // For IP networks, addresses have the form host:port. If host is
16 // a literal IPv6 address, it must be enclosed in square brackets. 16 // a literal IPv6 address, it must be enclosed in square brackets.
17 // The functions JoinHostPort and SplitHostPort manipulate· 17 // The functions JoinHostPort and SplitHostPort manipulate·
18 // addresses in this form. 18 // addresses in this form.
19 // 19 //
20 // Examples: 20 // Examples:
21 // Dial("tcp", "12.34.56.78:80") 21 // Dial("tcp", "12.34.56.78:80")
22 // Dial("tcp", "google.com:80") 22 // Dial("tcp", "google.com:80")
23 // Dial("tcp", "[de:ad:be:ef::ca:fe]:80") 23 // Dial("tcp", "[de:ad:be:ef::ca:fe]:80")
24 // 24 //
25 func Dial(net, addr string) (c Conn, err os.Error) { 25 func Dial(net, addr string) (c Conn, err os.Error) {
26 raddr := addr 26 raddr := addr
27 if raddr == "" {
28 return nil, &OpError{"dial", net, nil, errMissingAddress}
29 }
27 switch net { 30 switch net {
28 case "tcp", "tcp4", "tcp6": 31 case "tcp", "tcp4", "tcp6":
29 var ra *TCPAddr 32 var ra *TCPAddr
30 » » if raddr != "" { 33 » » if ra, err = ResolveTCPAddr(raddr); err != nil {
31 » » » if ra, err = ResolveTCPAddr(raddr); err != nil { 34 » » » goto Error
32 » » » » goto Error
33 » » » }
34 } 35 }
35 c, err := DialTCP(net, nil, ra) 36 c, err := DialTCP(net, nil, ra)
36 if err != nil { 37 if err != nil {
37 return nil, err 38 return nil, err
38 } 39 }
39 return c, nil 40 return c, nil
40 case "udp", "udp4", "udp6": 41 case "udp", "udp4", "udp6":
41 var ra *UDPAddr 42 var ra *UDPAddr
42 » » if raddr != "" { 43 » » if ra, err = ResolveUDPAddr(raddr); err != nil {
43 » » » if ra, err = ResolveUDPAddr(raddr); err != nil { 44 » » » goto Error
44 » » » » goto Error
45 » » » }
46 } 45 }
47 c, err := DialUDP(net, nil, ra) 46 c, err := DialUDP(net, nil, ra)
48 if err != nil { 47 if err != nil {
49 return nil, err 48 return nil, err
50 } 49 }
51 return c, nil 50 return c, nil
52 case "unix", "unixgram", "unixpacket": 51 case "unix", "unixgram", "unixpacket":
53 var ra *UnixAddr 52 var ra *UnixAddr
54 » » if raddr != "" { 53 » » if ra, err = ResolveUnixAddr(net, raddr); err != nil {
55 » » » if ra, err = ResolveUnixAddr(net, raddr); err != nil { 54 » » » goto Error
56 » » » » goto Error
57 » » » }
58 } 55 }
59 c, err = DialUnix(net, nil, ra) 56 c, err = DialUnix(net, nil, ra)
60 if err != nil { 57 if err != nil {
61 return nil, err 58 return nil, err
62 } 59 }
63 return c, nil 60 return c, nil
64 case "ip", "ip4", "ip6": 61 case "ip", "ip4", "ip6":
65 var ra *IPAddr 62 var ra *IPAddr
66 » » if raddr != "" { 63 » » if ra, err = ResolveIPAddr(raddr); err != nil {
67 » » » if ra, err = ResolveIPAddr(raddr); err != nil { 64 » » » goto Error
68 » » » » goto Error
69 » » » }
70 } 65 }
71 c, err := DialIP(net, nil, ra) 66 c, err := DialIP(net, nil, ra)
72 if err != nil { 67 if err != nil {
73 return nil, err 68 return nil, err
74 } 69 }
75 return c, nil 70 return c, nil
76 71
77 } 72 }
78 err = UnknownNetworkError(net) 73 err = UnknownNetworkError(net)
79 Error: 74 Error:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 c, err := ListenIP(net, la) 151 c, err := ListenIP(net, la)
157 if err != nil { 152 if err != nil {
158 return nil, err 153 return nil, err
159 } 154 }
160 return c, nil 155 return c, nil
161 } 156 }
162 } 157 }
163 158
164 return nil, UnknownNetworkError(net) 159 return nil, UnknownNetworkError(net)
165 } 160 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b