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>
30 lines
452 B
Go
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
|
|
}
|