Skip to content

Commit

Permalink
Use net.ErrClosed instead of io.EOF
Browse files Browse the repository at this point in the history
Updates to use net.ErrClosed when connection has been closed.

Signed-off-by: Daniel Mangum <[email protected]>
  • Loading branch information
hasheddan committed Jul 11, 2023
1 parent d7008fb commit 9511282
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion netctx/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *conn) ReadContext(ctx context.Context, b []byte) (int, error) {

select {
case <-c.closed:
return 0, io.EOF
return 0, net.ErrClosed
default:
}

Expand Down
4 changes: 2 additions & 2 deletions netctx/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func TestReadClosed(t *testing.T) {

b := make([]byte, 100)
n, err := c.ReadContext(context.Background(), b)
if !errors.Is(err, io.EOF) {
t.Errorf("Expected error '%v', got '%v'", io.EOF, err)
if !errors.Is(err, net.ErrClosed) {
t.Errorf("Expected error '%v', got '%v'", net.ErrClosed, err)
}
if n != 0 {
t.Errorf("Wrong data length, expected %d, got %d", 0, n)
Expand Down
2 changes: 1 addition & 1 deletion netctx/packetconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *packetConn) ReadFromContext(ctx context.Context, b []byte) (int, net.Ad

select {
case <-p.closed:
return 0, nil, io.EOF
return 0, nil, net.ErrClosed
default:
}

Expand Down
4 changes: 2 additions & 2 deletions netctx/packetconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func TestReadFromClosed(t *testing.T) {

b := make([]byte, 100)
n, _, err := c.ReadFromContext(context.Background(), b)
if !errors.Is(err, io.EOF) {
t.Errorf("Expected error '%v', got '%v'", io.EOF, err)
if !errors.Is(err, net.ErrClosed) {
t.Errorf("Expected error '%v', got '%v'", net.ErrClosed, err)
}
if n != 0 {
t.Errorf("Wrong data length, expected %d, got %d", 0, n)
Expand Down

0 comments on commit 9511282

Please sign in to comment.