Skip to content

Commit cf73425

Browse files
committed
Create a SocketMonitor by listening for a Qemu connection.
1 parent 73697a4 commit cf73425

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

qmp/socket.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ func NewSocketMonitor(network, addr string, timeout time.Duration) (*SocketMonit
6868
return mon, nil
6969
}
7070

71+
// NewListeningSocketMonitor listens for a monitor socket connection from Qemu.
72+
// An error is returned if the connection fails to accept.
73+
func NewListeningSocketMonitor(network, addr string) (*SocketMonitor, error) {
74+
listener, listenerErr := net.Listen(network, addr)
75+
if listenerErr != nil {
76+
return nil, listenerErr
77+
}
78+
c, err := listener.Accept()
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
mon := &SocketMonitor{
84+
c: c,
85+
listeners: new(int32),
86+
}
87+
88+
return mon, nil
89+
}
90+
7191
// Disconnect closes the QEMU monitor socket connection.
7292
func (mon *SocketMonitor) Disconnect() error {
7393
atomic.StoreInt32(mon.listeners, 0)

0 commit comments

Comments
 (0)