MCPcopy
hub / github.com/caddyserver/caddy / Write

Method Write

modules/caddyhttp/reverseproxy/streaming.go:588–615  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

586}
587
588func (m *maxLatencyWriter) Write(p []byte) (n int, err error) {
589 m.mu.Lock()
590 defer m.mu.Unlock()
591 n, err = m.dst.Write(p)
592 if c := m.logger.Check(zapcore.DebugLevel, "wrote bytes"); c != nil {
593 c.Write(zap.Int("n", n), zap.Error(err))
594 }
595 if m.latency < 0 {
596 m.logger.Debug("flushing immediately")
597 //nolint:errcheck
598 m.flush()
599 return n, err
600 }
601 if m.flushPending {
602 m.logger.Debug("delayed flush already pending")
603 return n, err
604 }
605 if m.t == nil {
606 m.t = time.AfterFunc(m.latency, m.delayedFlush)
607 } else {
608 m.t.Reset(m.latency)
609 }
610 if c := m.logger.Check(zapcore.DebugLevel, "timer set for delayed flush"); c != nil {
611 c.Write(zap.Duration("duration", m.latency))
612 }
613 m.flushPending = true
614 return n, err
615}
616
617func (m *maxLatencyWriter) delayedFlush() {
618 m.mu.Lock()

Callers 15

ServeHTTPMethod · 0.45
TestDialErrorBodyRetryFunction · 0.45
TestResponseRetryHeaderFunction · 0.45
WriteMethod · 0.45
handleUpgradeResponseMethod · 0.45
copyBufferMethod · 0.45
cleanupConnectionsMethod · 0.45

Calls 5

DurationMethod · 0.80
ResetMethod · 0.65
CheckMethod · 0.45
IntMethod · 0.45
ErrorMethod · 0.45