rpcfetch/io_unix.go
Ophestra Umiker b3325f56b1
library: io: handle retryable errors
Discord client being absent/disconnecting is not fatal to the RPC sender, in cases like that we return ErrAgain and in the case of broken pipe (Discord client going away) also reset the Client state so the caller can choose to retry the operation and therefore initiate a new connection attempt.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
2024-06-20 01:14:04 +09:00

30 lines
452 B
Go

package rpcfetch
import (
"errors"
"io/fs"
"net"
"time"
)
var (
ErrAgain = errors.New("operation not performed")
)
func (d *Client) dial() error {
if d.dialed {
panic("attempted to dial on open client")
}
if conn, err := net.DialTimeout("unix", sockPath()+"/discord-ipc-0", 5*time.Second); err != nil {
if errors.Is(err, fs.ErrNotExist) {
return ErrAgain
}
return err
} else {
d.conn = conn
d.dialed = true
}
return nil
}