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

Side by Side Diff: src/pkg/net/server_test.go

Issue 1326042: code review 1326042: changes &x -> x[0:] for array to slice conversion (Closed)
Patch Set: code review 1326042: changes &x -> x[0:] for array to slice conversion Created 14 years, 10 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:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/ipsock.go ('k') | src/pkg/net/sock.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 ( 7 import (
8 "flag" 8 "flag"
9 "io" 9 "io"
10 "os" 10 "os"
11 "strings" 11 "strings"
12 "syscall" 12 "syscall"
13 "testing" 13 "testing"
14 ) 14 )
15 15
16 // Do not test empty datagrams by default. 16 // Do not test empty datagrams by default.
17 // It causes unexplained timeouts on some systems, 17 // It causes unexplained timeouts on some systems,
18 // including Snow Leopard. I think that the kernel 18 // including Snow Leopard. I think that the kernel
19 // doesn't quite expect them. 19 // doesn't quite expect them.
20 var testUDP = flag.Bool("udp", false, "whether to test UDP datagrams") 20 var testUDP = flag.Bool("udp", false, "whether to test UDP datagrams")
21 21
22 func runEcho(fd io.ReadWriter, done chan<- int) { 22 func runEcho(fd io.ReadWriter, done chan<- int) {
23 var buf [1024]byte 23 var buf [1024]byte
24 24
25 for { 25 for {
26 » » n, err := fd.Read(&buf) 26 » » n, err := fd.Read(buf[0:])
27 if err != nil || n == 0 { 27 if err != nil || n == 0 {
28 break 28 break
29 } 29 }
30 fd.Write(buf[0:n]) 30 fd.Write(buf[0:n])
31 } 31 }
32 done <- 1 32 done <- 1
33 } 33 }
34 34
35 func runServe(t *testing.T, network, addr string, listening chan<- string, done chan<- int) { 35 func runServe(t *testing.T, network, addr string, listening chan<- string, done chan<- int) {
36 l, err := Listen(network, addr) 36 l, err := Listen(network, addr)
(...skipping 30 matching lines...) Expand all
67 if !isEmpty { 67 if !isEmpty {
68 b = []byte("hello, world\n") 68 b = []byte("hello, world\n")
69 } 69 }
70 var b1 [100]byte 70 var b1 [100]byte
71 71
72 n, err1 := fd.Write(b) 72 n, err1 := fd.Write(b)
73 if n != len(b) { 73 if n != len(b) {
74 t.Fatalf("fd.Write(%q) = %d, %v", b, n, err1) 74 t.Fatalf("fd.Write(%q) = %d, %v", b, n, err1)
75 } 75 }
76 76
77 » n, err1 = fd.Read(&b1) 77 » n, err1 = fd.Read(b1[0:])
78 if n != len(b) || err1 != nil { 78 if n != len(b) || err1 != nil {
79 t.Fatalf("fd.Read() = %d, %v (want %d, nil)", n, err1, len(b)) 79 t.Fatalf("fd.Read() = %d, %v (want %d, nil)", n, err1, len(b))
80 } 80 }
81 fd.Close() 81 fd.Close()
82 } 82 }
83 83
84 func doTest(t *testing.T, network, listenaddr, dialaddr string) { 84 func doTest(t *testing.T, network, listenaddr, dialaddr string) {
85 t.Logf("Test %s %s %s\n", network, listenaddr, dialaddr) 85 t.Logf("Test %s %s %s\n", network, listenaddr, dialaddr)
86 listening := make(chan string) 86 listening := make(chan string)
87 done := make(chan int) 87 done := make(chan int)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 func runPacket(t *testing.T, network, addr string, listening chan<- string, done chan<- int) { 120 func runPacket(t *testing.T, network, addr string, listening chan<- string, done chan<- int) {
121 c, err := ListenPacket(network, addr) 121 c, err := ListenPacket(network, addr)
122 if err != nil { 122 if err != nil {
123 t.Fatalf("net.ListenPacket(%q, %q) = _, %v", network, addr, err) 123 t.Fatalf("net.ListenPacket(%q, %q) = _, %v", network, addr, err)
124 } 124 }
125 listening <- c.LocalAddr().String() 125 listening <- c.LocalAddr().String()
126 c.SetReadTimeout(10e6) // 10ms 126 c.SetReadTimeout(10e6) // 10ms
127 var buf [1000]byte 127 var buf [1000]byte
128 for { 128 for {
129 » » n, addr, err := c.ReadFrom(&buf) 129 » » n, addr, err := c.ReadFrom(buf[0:])
130 if e, ok := err.(Error); ok && e.Timeout() { 130 if e, ok := err.(Error); ok && e.Timeout() {
131 if done <- 1 { 131 if done <- 1 {
132 break 132 break
133 } 133 }
134 continue 134 continue
135 } 135 }
136 if err != nil { 136 if err != nil {
137 break 137 break
138 } 138 }
139 if _, err = c.WriteTo(buf[0:n], addr); err != nil { 139 if _, err = c.WriteTo(buf[0:n], addr); err != nil {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 os.Remove("/tmp/gotest1.net.local") 182 os.Remove("/tmp/gotest1.net.local")
183 doTestPacket(t, "unixgram", "/tmp/gotest1.net", "/tmp/gotest1.ne t", isEmpty) 183 doTestPacket(t, "unixgram", "/tmp/gotest1.net", "/tmp/gotest1.ne t", isEmpty)
184 os.Remove("/tmp/gotest1.net") 184 os.Remove("/tmp/gotest1.net")
185 os.Remove("/tmp/gotest1.net.local") 185 os.Remove("/tmp/gotest1.net.local")
186 if syscall.OS == "linux" { 186 if syscall.OS == "linux" {
187 // Test abstract unix domain socket, a Linux-ism 187 // Test abstract unix domain socket, a Linux-ism
188 doTestPacket(t, "unixgram", "@gotest1/net", "@gotest1/ne t", isEmpty) 188 doTestPacket(t, "unixgram", "@gotest1/net", "@gotest1/ne t", isEmpty)
189 } 189 }
190 } 190 }
191 } 191 }
OLDNEW
« no previous file with comments | « src/pkg/net/ipsock.go ('k') | src/pkg/net/sock.go » ('j') | no next file with comments »

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