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