Skip to content

Commit 601d8ab

Browse files
committed
Add support for windows named pipe monitor
In addition to the existing unix sockets
1 parent ac9e0b6 commit 601d8ab

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ require (
66
github.com/digitalocean/go-libvirt v0.0.0-20201209184759-e2a69bcd5bd1
77
github.com/fatih/camelcase v1.0.0
88
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
9+
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
910
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IV
3636
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
3737
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3838
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
39+
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
40+
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
3941
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
4042
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

qmp/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ If your QEMU instances are not managed by libvirt, direct communication over its
3535
monitor, err := qmp.NewSocketMonitor("unix", "/var/lib/qemu/example.monitor", 2*time.Second)
3636
```
3737

38+
The Windows version of QEMU doesn't have UNIX sockets, but instead uses named pipes (fifo) for communication.
39+
40+
```go
41+
monitor, err := qmp.NewPipeMonitor("example", 2*time.Second) // will open `\\.\pipe\example`
42+
```
43+
3844
## Examples
3945

4046
Using the above to establish a new `qmp.Monitor`, the following examples provide a brief overview of QMP usage.

qmp/socket_unix.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717
package qmp
1818

1919
import (
20+
"fmt"
2021
"os"
22+
"time"
2123

2224
"golang.org/x/sys/unix"
2325
)
2426

27+
// NewPipeMonitor configures a connection to the provided QEMU monitor pipe.
28+
// An error is returned if the pipe cannot be successfully dialed, or the
29+
// dial attempt times out.
30+
func NewPipeMonitor(addr string, timeout time.Duration) (*SocketMonitor, error) {
31+
return nil, fmt.Errorf("unimplemented")
32+
}
33+
2534
func getUnixRights(file *os.File) []byte {
2635
return unix.UnixRights(int(file.Fd()))
2736
}

qmp/socket_windows.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,28 @@ package qmp
1818

1919
import (
2020
"os"
21+
"time"
22+
23+
"gopkg.in/natefinch/npipe.v2"
2124
)
2225

26+
// NewPipeMonitor configures a connection to the provided QEMU monitor pipe.
27+
// An error is returned if the pipe cannot be successfully dialed, or the
28+
// dial attempt times out.
29+
func NewPipeMonitor(addr string, timeout time.Duration) (*SocketMonitor, error) {
30+
c, err := npipe.DialTimeout(addr, timeout)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
mon := &SocketMonitor{
36+
c: c,
37+
listeners: new(int32),
38+
}
39+
40+
return mon, nil
41+
}
42+
2343
func getUnixRights(file *os.File) []byte {
2444
return nil
2545
}

0 commit comments

Comments
 (0)