| 983 | } |
| 984 | |
| 985 | func testConnReadShortBuffer(t *testing.T, conn *Conn) { |
| 986 | if _, err := conn.Write([]byte("Hello World!")); err != nil { |
| 987 | t.Fatal(err) |
| 988 | } |
| 989 | |
| 990 | b := make([]byte, 4) |
| 991 | |
| 992 | for i := 0; i != 10; i++ { |
| 993 | b[0] = 0 |
| 994 | b[1] = 0 |
| 995 | b[2] = 0 |
| 996 | b[3] = 0 |
| 997 | |
| 998 | n, err := conn.Read(b) |
| 999 | if !errors.Is(err, io.ErrShortBuffer) { |
| 1000 | t.Error("bad error:", i, err) |
| 1001 | } |
| 1002 | if n != 4 { |
| 1003 | t.Error("bad byte count:", i, n) |
| 1004 | } |
| 1005 | if s := string(b); s != "Hell" { |
| 1006 | t.Error("bad content:", i, s) |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | func testConnReadEmptyWithDeadline(t *testing.T, conn *Conn) { |
| 1012 | b := make([]byte, 100) |