MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / OptimizedCopyWithBufferSizeAndMetrics

Function OptimizedCopyWithBufferSizeAndMetrics

pkg/shared/network.go:307–331  ·  view source on GitHub ↗

OptimizedCopyWithBufferSizeAndMetrics performs optimized copying with custom buffer size and metrics

(dst, src net.Conn, bufferSize int, recordBytes func(int64))

Source from the content-addressed store, hash-verified

305
306// OptimizedCopyWithBufferSizeAndMetrics performs optimized copying with custom buffer size and metrics
307func OptimizedCopyWithBufferSizeAndMetrics(dst, src net.Conn, bufferSize int, recordBytes func(int64)) {
308 done := make(chan struct{}, 2)
309
310 // Copy from src to dst
311 go func() {
312 defer func() { done <- struct{}{} }()
313 copyWithBufferAndMetrics(dst, src, bufferSize, recordBytes)
314 }()
315
316 // Copy from dst to src
317 go func() {
318 defer func() { done <- struct{}{} }()
319 copyWithBufferAndMetrics(src, dst, bufferSize, recordBytes)
320 }()
321
322 // Wait for either direction to complete
323 <-done
324
325 // Close both connections to stop the other direction
326 dst.Close()
327 src.Close()
328
329 // Wait for the other direction to complete
330 <-done
331}
332
333// OptimizedCopyWithContextAndMetrics performs high-performance bidirectional copying with context and metrics
334func OptimizedCopyWithContextAndMetrics(ctx context.Context, dst, src net.Conn, recordBytes func(int64)) {

Callers 1

OptimizedCopyWithMetricsFunction · 0.85

Calls 1

copyWithBufferAndMetricsFunction · 0.85

Tested by

no test coverage detected