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

Unified Diff: src/pkg/net/net_test.go

Issue 5136052: code review 5136052: net: add shutdown: TCPConn.CloseWrite and CloseRead (Closed)
Patch Set: diff -r 6c5c19791fae https://go.googlecode.com/hg/ Created 13 years, 6 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/net/fd_windows.go ('k') | src/pkg/net/tcpsock_posix.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/net/net_test.go
===================================================================
--- a/src/pkg/net/net_test.go
+++ b/src/pkg/net/net_test.go
@@ -6,6 +6,7 @@
import (
"flag"
+ "os"
"regexp"
"testing"
)
@@ -119,3 +120,46 @@
}
}
}
+
+func TestShutdown(t *testing.T) {
+ l, err := Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ if l, err = Listen("tcp6", "[::1]:0"); err != nil {
+ t.Fatalf("ListenTCP on :0: %v", err)
+ }
+ }
+
+ go func() {
+ c, err := l.Accept()
+ if err != nil {
+ t.Fatalf("Accept: %v", err)
+ }
+ var buf [10]byte
+ n, err := c.Read(buf[:])
+ if n != 0 || err != os.EOF {
+ t.Fatalf("server Read = %d, %v; want 0, os.EOF", n, err)
+ }
+ c.Write([]byte("response"))
+ c.Close()
+ }()
+
+ c, err := Dial("tcp", l.Addr().String())
+ if err != nil {
+ t.Fatalf("Dial: %v", err)
+ }
+ defer c.Close()
+
+ err = c.(*TCPConn).CloseWrite()
+ if err != nil {
+ t.Fatalf("CloseWrite: %v", err)
+ }
+ var buf [10]byte
+ n, err := c.Read(buf[:])
+ if err != nil {
+ t.Fatalf("client Read: %d, %v", n, err)
+ }
+ got := string(buf[:n])
+ if got != "response" {
+ t.Errorf("read = %q, want \"response\"", got)
+ }
+}
« no previous file with comments | « src/pkg/net/fd_windows.go ('k') | src/pkg/net/tcpsock_posix.go » ('j') | no next file with comments »

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