MCPcopy Index your code
hub / github.com/docker/cli / NewPluginServer

Function NewPluginServer

cli-plugins/socket/socket.go:23–57  ·  view source on GitHub ↗

NewPluginServer creates a plugin server that listens on a new Unix domain socket. h is called for each new connection to the socket in a goroutine.

(h func(net.Conn))

Source from the content-addressed store, hash-verified

21// NewPluginServer creates a plugin server that listens on a new Unix domain
22// socket. h is called for each new connection to the socket in a goroutine.
23func NewPluginServer(h func(net.Conn)) (*PluginServer, error) {
24 // Listen on a Unix socket, with the address being platform-dependent.
25 // When a non-abstract address is used, Go will unlink(2) the socket
26 // for us once the listener is closed, as documented in
27 // [net.UnixListener.SetUnlinkOnClose].
28 l, err := net.ListenUnix("unix", &net.UnixAddr{
29 Name: socketName("docker_cli_" + randomID()),
30 Net: "unix",
31 })
32 if err != nil {
33 return nil, err
34 }
35 logrus.Trace("Plugin server listening on ", l.Addr())
36
37 if h == nil {
38 h = func(net.Conn) {}
39 }
40
41 pl := &PluginServer{
42 l: l,
43 h: h,
44 }
45
46 go func() {
47 defer pl.Close()
48 for {
49 err := pl.accept()
50 if err != nil {
51 return
52 }
53 }
54 }()
55
56 return pl, nil
57}
58
59type PluginServer struct {
60 mu sync.Mutex

Callers 2

TestPluginServerFunction · 0.85
TestConnectAndWaitFunction · 0.85

Calls 5

CloseMethod · 0.95
acceptMethod · 0.95
randomIDFunction · 0.85
AddrMethod · 0.80
socketNameFunction · 0.70

Tested by 2

TestPluginServerFunction · 0.68
TestConnectAndWaitFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…