...
1
2
3 package hcs
4
5 import (
6 "context"
7 "net"
8
9 "github.com/Microsoft/go-winio"
10 "github.com/Microsoft/go-winio/pkg/guid"
11 "github.com/Microsoft/hcsshim/internal/vm"
12 "github.com/pkg/errors"
13 )
14
15 func (uvm *utilityVM) VMSocketListen(ctx context.Context, listenType vm.VMSocketType, connID interface{}) (net.Listener, error) {
16 switch listenType {
17 case vm.HvSocket:
18 serviceGUID, ok := connID.(guid.GUID)
19 if !ok {
20 return nil, errors.New("parameter passed to hvsocketlisten is not a GUID")
21 }
22 return uvm.hvSocketListen(ctx, serviceGUID)
23 case vm.VSock:
24 port, ok := connID.(uint32)
25 if !ok {
26 return nil, errors.New("parameter passed to vsocklisten is not the right type")
27 }
28 return uvm.vsockListen(ctx, port)
29 default:
30 return nil, errors.New("unknown vmsocket type requested")
31 }
32 }
33
34 func (uvm *utilityVM) hvSocketListen(ctx context.Context, serviceID guid.GUID) (net.Listener, error) {
35 return winio.ListenHvsock(&winio.HvsockAddr{
36 VMID: uvm.vmID,
37 ServiceID: serviceID,
38 })
39 }
40
41 func (uvm *utilityVM) vsockListen(ctx context.Context, port uint32) (net.Listener, error) {
42 return nil, vm.ErrNotSupported
43 }
44
View as plain text