From 95112824019394749e5d4a2441c637ba299d9724 Mon Sep 17 00:00:00 2001 From: Daniel Mangum Date: Mon, 10 Jul 2023 21:49:21 -0400 Subject: [PATCH] Use net.ErrClosed instead of io.EOF Updates to use net.ErrClosed when connection has been closed. Signed-off-by: Daniel Mangum --- netctx/conn.go | 2 +- netctx/conn_test.go | 4 ++-- netctx/packetconn.go | 2 +- netctx/packetconn_test.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/netctx/conn.go b/netctx/conn.go index d13a177..a3322dc 100644 --- a/netctx/conn.go +++ b/netctx/conn.go @@ -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: } diff --git a/netctx/conn_test.go b/netctx/conn_test.go index d3f2c92..4c920c2 100644 --- a/netctx/conn_test.go +++ b/netctx/conn_test.go @@ -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) diff --git a/netctx/packetconn.go b/netctx/packetconn.go index b158cf0..1b65276 100644 --- a/netctx/packetconn.go +++ b/netctx/packetconn.go @@ -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: } diff --git a/netctx/packetconn_test.go b/netctx/packetconn_test.go index 747c84b..f1fd571 100644 --- a/netctx/packetconn_test.go +++ b/netctx/packetconn_test.go @@ -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)