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

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

Issue 163072: code review 163072: net: test and fix support for 0-length datagram packets. (Closed)
Left Patch Set: code review 163072: net: test and fix support for 0-length datagram packets. Created 15 years, 3 months ago
Right Patch Set: code review 163072: net: test and fix support for 0-length datagram packets. Created 15 years, 3 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 | « src/pkg/net/fd.go ('k') | 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 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 "io"; 8 "io";
9 "os"; 9 "os";
10 "strings"; 10 "strings";
(...skipping 27 matching lines...) Expand all
38 break 38 break
39 } 39 }
40 echodone := make(chan int); 40 echodone := make(chan int);
41 go runEcho(fd, echodone); 41 go runEcho(fd, echodone);
42 <-echodone; // make sure Echo stops 42 <-echodone; // make sure Echo stops
43 l.Close(); 43 l.Close();
44 } 44 }
45 done <- 1; 45 done <- 1;
46 } 46 }
47 47
48 func connect(t *testing.T, network, addr string, zerolen bool) { 48 func connect(t *testing.T, network, addr string, isEmpty bool) {
r 2009/12/02 16:03:36 zeroLen? empty? isEmpty?
49 var laddr string; 49 var laddr string;
50 if network == "unixgram" { 50 if network == "unixgram" {
51 laddr = addr + ".local" 51 laddr = addr + ".local"
52 } 52 }
53 fd, err := Dial(network, laddr, addr); 53 fd, err := Dial(network, laddr, addr);
54 if err != nil { 54 if err != nil {
55 t.Fatalf("net.Dial(%q, %q, %q) = _, %v", network, laddr, addr, e rr) 55 t.Fatalf("net.Dial(%q, %q, %q) = _, %v", network, laddr, addr, e rr)
56 } 56 }
57 fd.SetReadTimeout(10e6); // 10ms 57 fd.SetReadTimeout(10e6); // 10ms
58 58
59 var b []byte; 59 var b []byte;
60 » if !zerolen { 60 » if !isEmpty {
61 b = strings.Bytes("hello, world\n") 61 b = strings.Bytes("hello, world\n")
62 } 62 }
63 var b1 [100]byte; 63 var b1 [100]byte;
64 64
65 n, err := fd.Write(b); 65 n, err := fd.Write(b);
66 if n != len(b) { 66 if n != len(b) {
67 t.Fatalf("fd.Write(%q) = %d, %v", b, n, err) 67 t.Fatalf("fd.Write(%q) = %d, %v", b, n, err)
68 } 68 }
69 69
70 n, err = fd.Read(&b1); 70 n, err = fd.Read(&b1);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 break 130 break
131 } 131 }
132 if _, err = c.WriteTo(buf[0:n], addr); err != nil { 132 if _, err = c.WriteTo(buf[0:n], addr); err != nil {
133 t.Fatalf("WriteTo %v: %v", addr, err) 133 t.Fatalf("WriteTo %v: %v", addr, err)
134 } 134 }
135 } 135 }
136 c.Close(); 136 c.Close();
137 done <- 1; 137 done <- 1;
138 } 138 }
139 139
140 func doTestPacket(t *testing.T, network, listenaddr, dialaddr string, zerolen bo ol) { 140 func doTestPacket(t *testing.T, network, listenaddr, dialaddr string, isEmpty bo ol) {
r 2009/12/02 16:03:36 ditto
141 t.Logf("TestPacket %s %s %s\n", network, listenaddr, dialaddr); 141 t.Logf("TestPacket %s %s %s\n", network, listenaddr, dialaddr);
142 listening := make(chan string); 142 listening := make(chan string);
143 done := make(chan int); 143 done := make(chan int);
144 if network == "udp" { 144 if network == "udp" {
145 listenaddr += ":0" // any available port 145 listenaddr += ":0" // any available port
146 } 146 }
147 go runPacket(t, network, listenaddr, listening, done); 147 go runPacket(t, network, listenaddr, listening, done);
148 addr := <-listening; // wait for server to start 148 addr := <-listening; // wait for server to start
149 if network == "udp" { 149 if network == "udp" {
150 dialaddr += addr[strings.LastIndex(addr, ":"):] 150 dialaddr += addr[strings.LastIndex(addr, ":"):]
151 } 151 }
152 » connect(t, network, dialaddr, zerolen); 152 » connect(t, network, dialaddr, isEmpty);
153 <-done; // tell server to stop 153 <-done; // tell server to stop
154 <-done; // wait for stop 154 <-done; // wait for stop
155 } 155 }
156 156
157 func TestUDPServer(t *testing.T) { 157 func TestUDPServer(t *testing.T) {
158 » for i := 0; i < 2; i++ { 158 » for _, isEmpty := range []bool{false, true} {
159 » » doTestPacket(t, "udp", "0.0.0.0", "127.0.0.1", i > 0); 159 » » doTestPacket(t, "udp", "0.0.0.0", "127.0.0.1", isEmpty);
160 » » doTestPacket(t, "udp", "", "127.0.0.1", i > 0); 160 » » doTestPacket(t, "udp", "", "127.0.0.1", isEmpty);
r 2009/12/02 16:03:36 looks to me like what you want to pass is not i >
161 if kernelSupportsIPv6() { 161 if kernelSupportsIPv6() {
162 » » » doTestPacket(t, "udp", "[::]", "[::ffff:127.0.0.1]", i > 0); 162 » » » doTestPacket(t, "udp", "[::]", "[::ffff:127.0.0.1]", isE mpty);
163 » » » doTestPacket(t, "udp", "[::]", "127.0.0.1", i > 0); 163 » » » doTestPacket(t, "udp", "[::]", "127.0.0.1", isEmpty);
164 » » » doTestPacket(t, "udp", "0.0.0.0", "[::ffff:127.0.0.1]", i > 0); 164 » » » doTestPacket(t, "udp", "0.0.0.0", "[::ffff:127.0.0.1]", isEmpty);
165 } 165 }
166 } 166 }
167 } 167 }
168 168
169 func TestUnixDatagramServer(t *testing.T) { 169 func TestUnixDatagramServer(t *testing.T) {
170 » for i := 0; i < 2; i++ { 170 » for _, isEmpty := range []bool{false, true} {
171 os.Remove("/tmp/gotest1.net"); 171 os.Remove("/tmp/gotest1.net");
172 os.Remove("/tmp/gotest1.net.local"); 172 os.Remove("/tmp/gotest1.net.local");
173 » » doTestPacket(t, "unixgram", "/tmp/gotest1.net", "/tmp/gotest1.ne t", i > 0); 173 » » doTestPacket(t, "unixgram", "/tmp/gotest1.net", "/tmp/gotest1.ne t", isEmpty);
174 os.Remove("/tmp/gotest1.net"); 174 os.Remove("/tmp/gotest1.net");
175 os.Remove("/tmp/gotest1.net.local"); 175 os.Remove("/tmp/gotest1.net.local");
176 if syscall.OS == "linux" { 176 if syscall.OS == "linux" {
177 // Test abstract unix domain socket, a Linux-ism 177 // Test abstract unix domain socket, a Linux-ism
178 » » » doTestPacket(t, "unixgram", "@gotest1/net", "@gotest1/ne t", i > 0) 178 » » » doTestPacket(t, "unixgram", "@gotest1/net", "@gotest1/ne t", isEmpty)
179 } 179 }
180 } 180 }
181 } 181 }
LEFTRIGHT

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