MCPcopy
hub / github.com/coder/websocket / EchoLoop

Function EchoLoop

internal/test/wstest/echo.go:18–48  ·  view source on GitHub ↗

EchoLoop echos every msg received from c until an error occurs or the context expires. The read limit is set to 1 << 30.

(ctx context.Context, c *websocket.Conn)

Source from the content-addressed store, hash-verified

16// occurs or the context expires.
17// The read limit is set to 1 << 30.
18func EchoLoop(ctx context.Context, c *websocket.Conn) error {
19 defer c.Close(websocket.StatusInternalError, "")
20
21 c.SetReadLimit(1 << 30)
22
23 ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
24 defer cancel()
25
26 b := make([]byte, 32<<10)
27 for {
28 typ, r, err := c.Reader(ctx)
29 if err != nil {
30 return err
31 }
32
33 w, err := c.Writer(ctx, typ)
34 if err != nil {
35 return err
36 }
37
38 _, err = io.CopyBuffer(w, r, b)
39 if err != nil {
40 return err
41 }
42
43 err = w.Close()
44 if err != nil {
45 return err
46 }
47 }
48}
49
50// Echo writes a message and ensures the same is sent back on c.
51func Echo(ctx context.Context, c *websocket.Conn, max int) error {

Callers 4

goEchoLoopMethod · 0.92
echoServerFunction · 0.92
TestAutobahnFunction · 0.92
echoServerFunction · 0.92

Calls 4

CloseMethod · 0.45
SetReadLimitMethod · 0.45
ReaderMethod · 0.45
WriterMethod · 0.45

Tested by 4

goEchoLoopMethod · 0.74
echoServerFunction · 0.74
TestAutobahnFunction · 0.74
echoServerFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…