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

Function ConnectAndWait

cli-plugins/socket/socket.go:142–169  ·  view source on GitHub ↗

ConnectAndWait connects to the socket passed via well-known env var, if present, and attempts to read from it until it receives an EOF, at which point cb is called.

(cb func())

Source from the content-addressed store, hash-verified

140// if present, and attempts to read from it until it receives an EOF, at which
141// point cb is called.
142func ConnectAndWait(cb func()) {
143 socketAddr, ok := os.LookupEnv(EnvKey)
144 if !ok {
145 // if a plugin compiled against a more recent version of docker/cli
146 // is executed by an older CLI binary, ignore missing environment
147 // variable and behave as usual
148 return
149 }
150 addr, err := net.ResolveUnixAddr("unix", socketAddr)
151 if err != nil {
152 return
153 }
154 conn, err := net.DialUnix("unix", nil, addr)
155 if err != nil {
156 return
157 }
158
159 go func() {
160 b := make([]byte, 1)
161 for {
162 _, err := conn.Read(b)
163 if errors.Is(err, io.EOF) {
164 cb()
165 return
166 }
167 }
168 }()
169}

Callers 1

TestConnectAndWaitFunction · 0.85

Calls 2

LookupEnvMethod · 0.80
ReadMethod · 0.45

Tested by 1

TestConnectAndWaitFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…