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 <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-06-30 02:56:15 +09:00
parent c23e6120c8
commit 5bb6f9f1a8
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 9 additions and 5 deletions

7
io.go
View File

@ -7,7 +7,10 @@ import (
"net" "net"
"os" "os"
"strconv" "strconv"
"syscall" )
var (
ErrAgain = errors.New("operation not performed")
) )
type Client struct { 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 // 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) { func (d *Client) Raw(opcode uint32, payload any) (uint32, []byte, error) {
opcodeResp, payloadResp, err := d.raw(opcode, payload) opcodeResp, payloadResp, err := d.raw(opcode, payload)
if errors.Is(err, syscall.EPIPE) { if errors.Is(err, errPipe) {
// clean up as much as possible // clean up as much as possible
_ = d.Close() _ = d.Close()
// advise retry // advise retry

View File

@ -1,15 +1,16 @@
//go:build !windows
package rpcfetch package rpcfetch
import ( import (
"errors" "errors"
"io/fs" "io/fs"
"net" "net"
"syscall"
"time" "time"
) )
var ( var errPipe = syscall.EPIPE
ErrAgain = errors.New("operation not performed")
)
func (d *Client) dial() error { func (d *Client) dial() error {
if d.dialed { if d.dialed {