library: io: implement Windows platform support

Discord on Windows makes use of Windows named pipes for the socket instead of UNIX domain sockets.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-06-30 03:00:02 +09:00
parent 50e3f3a03f
commit 1d28743f31
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 29 additions and 1 deletions

3
go.mod
View File

@ -4,7 +4,9 @@ go 1.22
require (
fyne.io/fyne/v2 v2.4.5
github.com/Microsoft/go-winio v0.6.2
github.com/google/uuid v1.6.0
golang.org/x/image v0.17.0
)
require (
@ -28,7 +30,6 @@ require (
github.com/stretchr/testify v1.8.4 // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/yuin/goldmark v1.5.5 // indirect
golang.org/x/image v0.17.0 // indirect
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.21.0 // indirect

27
io_windows.go Normal file
View File

@ -0,0 +1,27 @@
package rpcfetch
import (
"errors"
"github.com/Microsoft/go-winio"
"io/fs"
"syscall"
)
var errPipe = syscall.Errno(232)
func (d *Client) dial() error {
if d.dialed {
panic("attempted to dial on open client")
}
if conn, err := winio.DialPipe(`\\.\pipe\discord-ipc-0`, nil); err != nil {
if errors.Is(err, winio.ErrTimeout) || errors.Is(err, fs.ErrNotExist) {
return ErrAgain
}
return err
} else {
d.conn = conn
d.dialed = true
}
return nil
}