From 5bb6f9f1a80a83b4ee7df87281446d50c3a9c6a5 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sun, 30 Jun 2024 02:56:15 +0900 Subject: [PATCH] library: io: move ErrAgain to shared and errPipe value to platform-specific ErrAgain is not platform specific however EPIPE equivalent is different on Windows. Signed-off-by: Ophestra Umiker --- io.go | 7 +++++-- io_unix.go | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/io.go b/io.go index ac2cf71..cb56559 100644 --- a/io.go +++ b/io.go @@ -7,7 +7,10 @@ import ( "net" "os" "strconv" - "syscall" +) + +var ( + ErrAgain = errors.New("operation not performed") ) type Client struct { @@ -62,7 +65,7 @@ func Raw[T any](d *Client, opcode uint32, payload any) (uint32, T, error) { // Raw writes a raw payload to Discord and returns the response opcode and payload func (d *Client) Raw(opcode uint32, payload any) (uint32, []byte, error) { opcodeResp, payloadResp, err := d.raw(opcode, payload) - if errors.Is(err, syscall.EPIPE) { + if errors.Is(err, errPipe) { // clean up as much as possible _ = d.Close() // advise retry diff --git a/io_unix.go b/io_unix.go index 32d3284..8043392 100644 --- a/io_unix.go +++ b/io_unix.go @@ -1,15 +1,16 @@ +//go:build !windows + package rpcfetch import ( "errors" "io/fs" "net" + "syscall" "time" ) -var ( - ErrAgain = errors.New("operation not performed") -) +var errPipe = syscall.EPIPE func (d *Client) dial() error { if d.dialed {