diff --git a/go.mod b/go.mod index b395021..72f007c 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( require ( github.com/google/uuid v1.2.0 // indirect golang.org/x/net v0.20.0 // indirect - golang.org/x/sync v0.1.0 // indirect + golang.org/x/sync v0.1.0 golang.zx2c4.com/wireguard/windows v0.5.3 ) diff --git a/handle.go b/handle.go index 1355914..855b893 100644 --- a/handle.go +++ b/handle.go @@ -57,14 +57,6 @@ func (d *Handle) Recv(ip []byte, addr *Address) (int, error) { // notice: recvLen not work, use windows.GetOverlappedResult // todo: support batch recv func (d *Handle) RecvEx(ip []byte, addr *Address, recvLen *uint32, ol *windows.Overlapped) error { - err := d.recvEx(ip, addr, recvLen, ol) - if err != nil { - return handleError(err) - } - return nil -} - -func (d *Handle) recvEx(ip []byte, addr *Address, recvLen *uint32, ol *windows.Overlapped) error { var ipPtr uintptr if len(ip) > 0 { ipPtr = uintptr(unsafe.Pointer(unsafe.SliceData(ip))) @@ -82,7 +74,7 @@ func (d *Handle) recvEx(ip []byte, addr *Address, recvLen *uint32, ol *windows.O uintptr(unsafe.Pointer(ol)), // lpOverlapped ) if r1 == 0 { - return e + return handleError(e) } return nil } diff --git a/handle_test.go b/handle_test.go index 9b2669b..593800b 100644 --- a/handle_test.go +++ b/handle_test.go @@ -134,7 +134,7 @@ func Test_Recv_Error(t *testing.T) { defer d.Close() _, err = d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrClosed{})) + require.True(t, errors.Is(err, ErrClosed{}), err) }) t.Run("recv/close", func(t *testing.T) { @@ -148,7 +148,7 @@ func Test_Recv_Error(t *testing.T) { require.NoError(t, d.Close()) }() _, err = d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrClosed{})) + require.True(t, errors.Is(err, ErrClosed{}), err) } }) @@ -163,9 +163,9 @@ func Test_Recv_Error(t *testing.T) { require.NoError(t, d.Close()) }() _, err = d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrClosed{})) + require.True(t, errors.Is(err, ErrClosed{}), err) - require.True(t, errors.Is(d.Close(), ErrClosed{})) + require.True(t, errors.Is(d.Close(), ErrClosed{}), err) } }) @@ -181,14 +181,14 @@ func Test_Recv_Error(t *testing.T) { }() { _, err = d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrClosed{})) + require.True(t, errors.Is(err, ErrClosed{}), err) } { - require.True(t, errors.Is(d.Close(), ErrClosed{})) + require.True(t, errors.Is(d.Close(), ErrClosed{}), err) } { _, err = d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrClosed{})) + require.True(t, errors.Is(err, ErrClosed{}), err) } } }) @@ -200,7 +200,7 @@ func Test_Recv_Error(t *testing.T) { defer d.Close() n, err := d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrShutdown{})) + require.True(t, errors.Is(err, ErrShutdown{}), err) require.Zero(t, n) }) @@ -215,7 +215,7 @@ func Test_Recv_Error(t *testing.T) { }() n, err := d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrShutdown{})) + require.True(t, errors.Is(err, ErrShutdown{}), err) require.Zero(t, n) }) @@ -230,7 +230,7 @@ func Test_Recv_Error(t *testing.T) { }() n, err := d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrShutdown{})) + require.True(t, errors.Is(err, ErrShutdown{}), err) require.Zero(t, n) require.NoError(t, d.Shutdown(Both)) @@ -248,7 +248,7 @@ func Test_Recv_Error(t *testing.T) { { n, err := d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrShutdown{})) + require.True(t, errors.Is(err, ErrShutdown{}), err) require.Zero(t, n) } { @@ -256,7 +256,7 @@ func Test_Recv_Error(t *testing.T) { } { n, err := d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrShutdown{})) + require.True(t, errors.Is(err, ErrShutdown{}), err) require.Zero(t, n) } }) @@ -270,7 +270,7 @@ func Test_Recv_Error(t *testing.T) { require.NoError(t, err) n, err := d.Recv(make([]byte, 1536), nil) - require.True(t, errors.Is(err, ErrClosed{})) + require.True(t, errors.Is(err, ErrClosed{}), err) require.Zero(t, n) }) }