MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / DialContext

Method DialContext

dialer/command.go:51–77  ·  view source on GitHub ↗
(ctx context.Context, network, address string)

Source from the content-addressed store, hash-verified

49}
50
51func (d *CommandDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
52 killCtx, kill := context.WithCancel(context.Background())
53 cmd := exec.CommandContext(killCtx, d.command[0], d.command[1:]...)
54 cmd.Env = append(os.Environ(),
55 "DUMBPROXY_DST_ADDR="+address,
56 "DUMBPROXY_DST_NET="+network,
57 )
58 cmdIn, err := cmd.StdinPipe()
59 if err != nil {
60 return nil, fmt.Errorf("can't create stdin pipe for subprocess: %w", err)
61 }
62 cmdOut, err := cmd.StdoutPipe()
63 if err != nil {
64 return nil, fmt.Errorf("can't create stdout pipe for subprocess: %w", err)
65 }
66 cmd.Stderr = os.Stderr
67 cmd.WaitDelay = d.waitDelay
68 if err := cmd.Start(); err != nil {
69 return nil, fmt.Errorf("unable to start subprocess: %w", err)
70 }
71 go func() {
72 cmd.Wait()
73 cmdIn.Close()
74 cmdOut.Close()
75 }()
76 return NewPipeConn(cmdOut.(ReadPipe), cmdIn.(WritePipe), kill), nil
77}
78
79func (d *CommandDialer) WantsHostname(_ context.Context, _, _ string) bool {
80 return true

Callers 1

DialMethod · 0.95

Calls 4

NewPipeConnFunction · 0.85
ErrorfMethod · 0.80
WaitMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected