MCPcopy Create free account
hub / github.com/PostHog/duckgres / copyWithLatency

Function copyWithLatency

tests/integration/latency_proxy.go:111–130  ·  view source on GitHub ↗

copyWithLatency copies data from src to dst, injecting a delay before each write. For zero latency this degrades to a plain io.Copy.

(dst, src net.Conn, latency time.Duration)

Source from the content-addressed store, hash-verified

109// copyWithLatency copies data from src to dst, injecting a delay before each
110// write. For zero latency this degrades to a plain io.Copy.
111func copyWithLatency(dst, src net.Conn, latency time.Duration) {
112 if latency <= 0 {
113 _, _ = io.Copy(dst, src)
114 return
115 }
116 buf := make([]byte, 32*1024)
117 for {
118 n, readErr := src.Read(buf)
119 if n > 0 {
120 time.Sleep(latency)
121 _, writeErr := dst.Write(buf[:n])
122 if writeErr != nil {
123 return
124 }
125 }
126 if readErr != nil {
127 return
128 }
129 }
130}

Callers 1

handleConnMethod · 0.85

Calls 2

ReadMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected