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

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

Issue 5128048: code review 5128048: net: Set family in newFileFD to fix "unexpected socket ... (Closed)
Patch Set: diff -r 9be80dbcb0af https://go.googlecode.com/hg/ Created 13 years, 5 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/file.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 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 "os" 8 "os"
9 "reflect" 9 "reflect"
10 "runtime" 10 "runtime"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 testFileListener(t, "tcp", "[::ffff:127.0.0.1]") 66 testFileListener(t, "tcp", "[::ffff:127.0.0.1]")
67 testFileListener(t, "tcp", "127.0.0.1") 67 testFileListener(t, "tcp", "127.0.0.1")
68 testFileListener(t, "tcp", "[::ffff:127.0.0.1]") 68 testFileListener(t, "tcp", "[::ffff:127.0.0.1]")
69 } 69 }
70 if syscall.OS == "linux" { 70 if syscall.OS == "linux" {
71 testFileListener(t, "unix", "@gotest/net") 71 testFileListener(t, "unix", "@gotest/net")
72 testFileListener(t, "unixpacket", "@gotest/net") 72 testFileListener(t, "unixpacket", "@gotest/net")
73 } 73 }
74 } 74 }
75 75
76 func testFilePacketConn(t *testing.T, pcf packetConnFile) { 76 func testFilePacketConn(t *testing.T, pcf packetConnFile, listen bool) {
77 f, err := pcf.File() 77 f, err := pcf.File()
78 if err != nil { 78 if err != nil {
79 t.Fatalf("File failed: %v", err) 79 t.Fatalf("File failed: %v", err)
80 } 80 }
81 c, err := FilePacketConn(f) 81 c, err := FilePacketConn(f)
82 if err != nil { 82 if err != nil {
83 t.Fatalf("FilePacketConn failed: %v", err) 83 t.Fatalf("FilePacketConn failed: %v", err)
84 } 84 }
85 if !reflect.DeepEqual(pcf.LocalAddr(), c.LocalAddr()) { 85 if !reflect.DeepEqual(pcf.LocalAddr(), c.LocalAddr()) {
86 t.Fatalf("LocalAddrs not equal: %#v != %#v", pcf.LocalAddr(), c. LocalAddr()) 86 t.Fatalf("LocalAddrs not equal: %#v != %#v", pcf.LocalAddr(), c. LocalAddr())
87 } 87 }
88 if listen {
89 if _, err := c.WriteTo([]byte{}, c.LocalAddr()); err != nil {
90 t.Fatalf("WriteTo failed: %v", err)
91 }
92 }
88 if err := c.Close(); err != nil { 93 if err := c.Close(); err != nil {
89 t.Fatalf("Close failed: %v", err) 94 t.Fatalf("Close failed: %v", err)
90 } 95 }
91 if err := f.Close(); err != nil { 96 if err := f.Close(); err != nil {
92 t.Fatalf("Close failed: %v", err) 97 t.Fatalf("Close failed: %v", err)
93 } 98 }
94 } 99 }
95 100
96 func testFilePacketConnListen(t *testing.T, net, laddr string) { 101 func testFilePacketConnListen(t *testing.T, net, laddr string) {
97 l, err := ListenPacket(net, laddr) 102 l, err := ListenPacket(net, laddr)
98 if err != nil { 103 if err != nil {
99 t.Fatalf("Listen failed: %v", err) 104 t.Fatalf("Listen failed: %v", err)
100 } 105 }
101 » testFilePacketConn(t, l.(packetConnFile)) 106 » testFilePacketConn(t, l.(packetConnFile), true)
102 if err := l.Close(); err != nil { 107 if err := l.Close(); err != nil {
103 t.Fatalf("Close failed: %v", err) 108 t.Fatalf("Close failed: %v", err)
104 } 109 }
105 } 110 }
106 111
107 func testFilePacketConnDial(t *testing.T, net, raddr string) { 112 func testFilePacketConnDial(t *testing.T, net, raddr string) {
108 c, err := Dial(net, raddr) 113 c, err := Dial(net, raddr)
109 if err != nil { 114 if err != nil {
110 t.Fatalf("Dial failed: %v", err) 115 t.Fatalf("Dial failed: %v", err)
111 } 116 }
112 » testFilePacketConn(t, c.(packetConnFile)) 117 » testFilePacketConn(t, c.(packetConnFile), false)
113 if err := c.Close(); err != nil { 118 if err := c.Close(); err != nil {
114 t.Fatalf("Close failed: %v", err) 119 t.Fatalf("Close failed: %v", err)
115 } 120 }
116 } 121 }
117 122
118 func TestFilePacketConn(t *testing.T) { 123 func TestFilePacketConn(t *testing.T) {
119 if runtime.GOOS == "windows" || runtime.GOOS == "plan9" { 124 if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
120 return 125 return
121 } 126 }
122 testFilePacketConnListen(t, "udp", "127.0.0.1:0") 127 testFilePacketConnListen(t, "udp", "127.0.0.1:0")
123 testFilePacketConnDial(t, "udp", "127.0.0.1:12345") 128 testFilePacketConnDial(t, "udp", "127.0.0.1:12345")
124 if supportsIPv6 { 129 if supportsIPv6 {
125 testFilePacketConnListen(t, "udp", "[::1]:0") 130 testFilePacketConnListen(t, "udp", "[::1]:0")
126 } 131 }
127 if supportsIPv6 && supportsIPv4map { 132 if supportsIPv6 && supportsIPv4map {
128 testFilePacketConnDial(t, "udp", "[::ffff:127.0.0.1]:12345") 133 testFilePacketConnDial(t, "udp", "[::ffff:127.0.0.1]:12345")
129 } 134 }
130 if syscall.OS == "linux" { 135 if syscall.OS == "linux" {
131 testFilePacketConnListen(t, "unixgram", "@gotest1/net") 136 testFilePacketConnListen(t, "unixgram", "@gotest1/net")
132 } 137 }
133 } 138 }
OLDNEW
« no previous file with comments | « src/pkg/net/file.go ('k') | no next file » | no next file with comments »

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