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

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

Issue 4630081: code review 4630081: net: break up and simplify Dial a bit (Closed)
Left Patch Set: diff -r 49afab7d8d33 https://go.googlecode.com/hg/ Created 13 years, 8 months ago
Right Patch Set: diff -r c2bc251478f6 https://go.googlecode.com/hg/ Created 13 years, 8 months 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 | « no previous file | no next file » | 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 func resolveNetAddr(op, net, addr string) (a Addr, err os.Error) { 9 func resolveNetAddr(op, net, addr string) (a Addr, err os.Error) {
10 if addr == "" { 10 if addr == "" {
11 return nil, &OpError{op, net, nil, errMissingAddress} 11 return nil, &OpError{op, net, nil, errMissingAddress}
12 } 12 }
13 switch net { 13 switch net {
14 case "tcp", "tcp4", "tcp6": 14 case "tcp", "tcp4", "tcp6":
15 a, err = ResolveTCPAddr(net, addr) 15 a, err = ResolveTCPAddr(net, addr)
16 case "udp", "udp4", "udp6": 16 case "udp", "udp4", "udp6":
17 a, err = ResolveUDPAddr(net, addr) 17 a, err = ResolveUDPAddr(net, addr)
18 case "unix", "unixgram", "unixpacket": 18 case "unix", "unixgram", "unixpacket":
19 a, err = ResolveUnixAddr(net, addr) 19 a, err = ResolveUnixAddr(net, addr)
20 case "ip", "ip4", "ip6": 20 case "ip", "ip4", "ip6":
21 a, err = ResolveIPAddr(net, addr) 21 a, err = ResolveIPAddr(net, addr)
22 default: 22 default:
23 err = UnknownNetworkError(net) 23 err = UnknownNetworkError(net)
24 } 24 }
25 » if err == nil { 25 » if err != nil {
26 » » return 26 » » return nil, &OpError{op, net + " " + addr, nil, err}
27 } 27 }
28 » return nil, &OpError{op, net + " " + addr, nil, err} 28 » return
29 } 29 }
30 30
31 // Dial connects to the address addr on the network net. 31 // Dial connects to the address addr on the network net.
32 // 32 //
33 // Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), 33 // Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only),
34 // "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" 34 // "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4"
35 // (IPv4-only), "ip6" (IPv6-only), "unix" and "unixgram". 35 // (IPv4-only), "ip6" (IPv6-only), "unix" and "unixgram".
36 // 36 //
37 // For IP networks, addresses have the form host:port. If host is 37 // For IP networks, addresses have the form host:port. If host is
38 // a literal IPv6 address, it must be enclosed in square brackets. 38 // a literal IPv6 address, it must be enclosed in square brackets.
(...skipping 15 matching lines...) Expand all
54 c, err = DialTCP(net, nil, ra) 54 c, err = DialTCP(net, nil, ra)
55 case *UDPAddr: 55 case *UDPAddr:
56 c, err = DialUDP(net, nil, ra) 56 c, err = DialUDP(net, nil, ra)
57 case *UnixAddr: 57 case *UnixAddr:
58 c, err = DialUnix(net, nil, ra) 58 c, err = DialUnix(net, nil, ra)
59 case *IPAddr: 59 case *IPAddr:
60 c, err = DialIP(net, nil, ra) 60 c, err = DialIP(net, nil, ra)
61 default: 61 default:
62 err = UnknownNetworkError(net) 62 err = UnknownNetworkError(net)
63 } 63 }
64 » if err == nil { 64 » if err != nil {
65 » » return 65 » » return nil, &OpError{"dial", net + " " + addr, nil, err}
66 } 66 }
67 » return nil, &OpError{"dial", net + " " + addr, nil, err} 67 » return
68 } 68 }
69 69
70 // Listen announces on the local network address laddr. 70 // Listen announces on the local network address laddr.
71 // The network string net must be a stream-oriented 71 // The network string net must be a stream-oriented
72 // network: "tcp", "tcp4", "tcp6", or "unix", or "unixpacket". 72 // network: "tcp", "tcp4", "tcp6", or "unix", or "unixpacket".
73 func Listen(net, laddr string) (l Listener, err os.Error) { 73 func Listen(net, laddr string) (l Listener, err os.Error) {
74 switch net { 74 switch net {
75 case "tcp", "tcp4", "tcp6": 75 case "tcp", "tcp4", "tcp6":
76 var la *TCPAddr 76 var la *TCPAddr
77 if laddr != "" { 77 if laddr != "" {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 c, err := ListenIP(net, la) 144 c, err := ListenIP(net, la)
145 if err != nil { 145 if err != nil {
146 return nil, err 146 return nil, err
147 } 147 }
148 return c, nil 148 return c, nil
149 } 149 }
150 } 150 }
151 151
152 return nil, UnknownNetworkError(net) 152 return nil, UnknownNetworkError(net)
153 } 153 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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