Dave Cheney | 8c2b131 | 2012-10-17 09:41:00 +1100 | [diff] [blame] | 1 | // Copyright 2012 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Mikio Hara | a877e81 | 2014-12-31 10:08:51 +0900 | [diff] [blame] | 5 | // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows |
Dave Cheney | 8c2b131 | 2012-10-17 09:41:00 +1100 | [diff] [blame] | 6 | |
| 7 | package net |
| 8 | |
| 9 | import ( |
Dave Cheney | 28b59942 | 2012-11-28 11:29:25 +1100 | [diff] [blame] | 10 | "io" |
| 11 | "syscall" |
Dave Cheney | 8c2b131 | 2012-10-17 09:41:00 +1100 | [diff] [blame] | 12 | "testing" |
| 13 | ) |
| 14 | |
Mikio Hara | a877e81 | 2014-12-31 10:08:51 +0900 | [diff] [blame] | 15 | var eofErrorTests = []struct { |
Dave Cheney | 28b59942 | 2012-11-28 11:29:25 +1100 | [diff] [blame] | 16 | n int |
| 17 | err error |
| 18 | fd *netFD |
| 19 | expected error |
| 20 | }{ |
Dave Cheney | 28b59942 | 2012-11-28 11:29:25 +1100 | [diff] [blame] | 21 | {100, nil, &netFD{sotype: syscall.SOCK_STREAM}, nil}, |
| 22 | {100, io.EOF, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF}, |
| 23 | {100, errClosing, &netFD{sotype: syscall.SOCK_STREAM}, errClosing}, |
| 24 | {0, nil, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF}, |
| 25 | {0, io.EOF, &netFD{sotype: syscall.SOCK_STREAM}, io.EOF}, |
| 26 | {0, errClosing, &netFD{sotype: syscall.SOCK_STREAM}, errClosing}, |
| 27 | |
| 28 | {100, nil, &netFD{sotype: syscall.SOCK_DGRAM}, nil}, |
| 29 | {100, io.EOF, &netFD{sotype: syscall.SOCK_DGRAM}, io.EOF}, |
| 30 | {100, errClosing, &netFD{sotype: syscall.SOCK_DGRAM}, errClosing}, |
| 31 | {0, nil, &netFD{sotype: syscall.SOCK_DGRAM}, nil}, |
| 32 | {0, io.EOF, &netFD{sotype: syscall.SOCK_DGRAM}, io.EOF}, |
| 33 | {0, errClosing, &netFD{sotype: syscall.SOCK_DGRAM}, errClosing}, |
| 34 | |
| 35 | {100, nil, &netFD{sotype: syscall.SOCK_SEQPACKET}, nil}, |
| 36 | {100, io.EOF, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF}, |
| 37 | {100, errClosing, &netFD{sotype: syscall.SOCK_SEQPACKET}, errClosing}, |
| 38 | {0, nil, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF}, |
| 39 | {0, io.EOF, &netFD{sotype: syscall.SOCK_SEQPACKET}, io.EOF}, |
| 40 | {0, errClosing, &netFD{sotype: syscall.SOCK_SEQPACKET}, errClosing}, |
| 41 | |
| 42 | {100, nil, &netFD{sotype: syscall.SOCK_RAW}, nil}, |
| 43 | {100, io.EOF, &netFD{sotype: syscall.SOCK_RAW}, io.EOF}, |
| 44 | {100, errClosing, &netFD{sotype: syscall.SOCK_RAW}, errClosing}, |
| 45 | {0, nil, &netFD{sotype: syscall.SOCK_RAW}, nil}, |
| 46 | {0, io.EOF, &netFD{sotype: syscall.SOCK_RAW}, io.EOF}, |
| 47 | {0, errClosing, &netFD{sotype: syscall.SOCK_RAW}, errClosing}, |
| 48 | } |
| 49 | |
Mikio Hara | a877e81 | 2014-12-31 10:08:51 +0900 | [diff] [blame] | 50 | func TestEOFError(t *testing.T) { |
| 51 | for _, tt := range eofErrorTests { |
| 52 | actual := tt.fd.eofError(tt.n, tt.err) |
Dave Cheney | 28b59942 | 2012-11-28 11:29:25 +1100 | [diff] [blame] | 53 | if actual != tt.expected { |
Mikio Hara | a877e81 | 2014-12-31 10:08:51 +0900 | [diff] [blame] | 54 | t.Errorf("eofError(%v, %v, %v): expected %v, actual %v", tt.n, tt.err, tt.fd.sotype, tt.expected, actual) |
Dave Cheney | 28b59942 | 2012-11-28 11:29:25 +1100 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |