MCPcopy Index your code
hub / github.com/smallstep/cli / proxyDirectWithIO

Function proxyDirectWithIO

command/ssh/proxycommand.go:233–264  ·  view source on GitHub ↗
(host, port string, stdin io.Reader, stdout io.Writer)

Source from the content-addressed store, hash-verified

231}
232
233func proxyDirectWithIO(host, port string, stdin io.Reader, stdout io.Writer) error {
234 address := net.JoinHostPort(host, port)
235 addr, err := net.ResolveTCPAddr("tcp", address)
236 if err != nil {
237 return errors.Wrap(err, "error resolving address")
238 }
239
240 conn, err := net.DialTCP("tcp", nil, addr)
241 if err != nil {
242 return errors.Wrapf(err, "error connecting to %s", address)
243 }
244 defer conn.Close()
245
246 // Return as soon as either direction finishes. Waiting for both can
247 // deadlock when the server closes the connection while stdin stays open.
248 // See smallstep/cli#1641. Buffered so the slower goroutine never blocks
249 // sending after we've stopped receiving.
250 done := make(chan struct{}, 2)
251 go func() {
252 io.Copy(conn, stdin)
253 conn.CloseWrite()
254 done <- struct{}{}
255 }()
256 go func() {
257 io.Copy(stdout, conn)
258 conn.CloseRead()
259 done <- struct{}{}
260 }()
261
262 <-done
263 return nil
264}
265
266func proxyBastion(r *api.SSHBastionResponse, user, host, port string) error {
267 sshPath, err := exec.LookPath("ssh")

Callers 2

proxyDirectFunction · 0.85

Calls 1

CloseMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…