MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / streamAndPrint

Function streamAndPrint

test/localrpc_client/main.go:140–163  ·  view source on GitHub ↗

streamAndPrint calls StreamCommand and prints each chunk as it arrives.

(ctx context.Context, client localrpc.CommandServiceClient, sessionID, command string)

Source from the content-addressed store, hash-verified

138
139// streamAndPrint calls StreamCommand and prints each chunk as it arrives.
140func streamAndPrint(ctx context.Context, client localrpc.CommandServiceClient, sessionID, command string) error {
141 sc, err := client.StreamCommand(ctx, &localrpc.ExecuteCommandRequest{
142 SessionId: sessionID,
143 Command: command,
144 })
145 if err != nil {
146 return fmt.Errorf("StreamCommand: %w", err)
147 }
148
149 for {
150 resp, err := sc.Recv()
151 if err == io.EOF {
152 return nil
153 }
154 if err != nil {
155 // Context cancelled is normal (Ctrl+C).
156 if ctx.Err() != nil {
157 return nil
158 }
159 return fmt.Errorf("recv: %w", err)
160 }
161 fmt.Print(resp.Output)
162 }
163}
164
165// isStreamingCommand returns true if the command name matches a known streaming command.
166func isStreamingCommand(command string) bool {

Callers 1

mainFunction · 0.85

Calls 1

RecvMethod · 0.80

Tested by

no test coverage detected