Source file
src/net/write_unix_test.go
1
2
3
4
5
6
7 package net
8
9 import (
10 "bytes"
11 "syscall"
12 "testing"
13 "time"
14 )
15
16
17
18
19 func TestEndlessWrite(t *testing.T) {
20 t.Parallel()
21 c := make(chan bool)
22 server := func(cs *TCPConn) error {
23 cs.CloseWrite()
24 <-c
25 return nil
26 }
27 client := func(ss *TCPConn) error {
28
29 defer close(c)
30
31
32
33 b := bytes.Repeat([]byte{'a'}, 8192)
34 cagain := 0
35 for {
36 n, err := ss.conn.fd.pfd.WriteOnce(b)
37 if n > 0 {
38 cagain = 0
39 }
40 switch err {
41 case nil:
42 case syscall.EAGAIN:
43 if cagain == 0 {
44
45
46
47 ss.SetWriteDeadline(time.Now().Add(5 * time.Millisecond))
48 }
49 cagain++
50 if cagain > 20 {
51 t.Error("looping on EAGAIN")
52 return nil
53 }
54 if err = ss.conn.fd.pfd.WaitWrite(); err != nil {
55 t.Logf("client WaitWrite: %v", err)
56 return nil
57 }
58 default:
59
60 t.Logf("client WriteOnce: %v", err)
61 return nil
62 }
63 }
64 }
65 withTCPConnPair(t, client, server)
66 }
67
View as plain text