From 1694e71e0c27e89b0d34d175f60b665f6b66554f Mon Sep 17 00:00:00 2001 From: ddirect <62487612+ddirect@users.noreply.github.com> Date: Mon, 9 Feb 2026 02:27:18 +0200 Subject: [PATCH] Use backoff to wait until there is enough room in the TCP write buffer (#34) --- internal/ring.go | 6 +++--- tcp/conn.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/ring.go b/internal/ring.go index 5300cd5..25ae469 100644 --- a/internal/ring.go +++ b/internal/ring.go @@ -9,7 +9,7 @@ import ( ) var ( - errRingBufferFull = errors.New("lneto/ring: buffer full") + ErrRingBufferFull = errors.New("lneto/ring: buffer full") errRingNoData = errors.New("lneto/ring: empty write") ) @@ -39,7 +39,7 @@ func (r *Ring) WriteLimited(b []byte, limitOffset int) (int, error) { } limit := r.FreeLimited(limitOffset) if len(b) > limit { - return 0, errRingBufferFull + return 0, ErrRingBufferFull } return r.Write(b) } @@ -55,7 +55,7 @@ func (r *Ring) Write(b []byte) (int, error) { if len(b) == 0 { return 0, errRingNoData } else if r.IsFull() || r.Free() < len(b) { - return 0, errRingBufferFull + return 0, ErrRingBufferFull } midFree := r.midFree() if midFree > 0 { diff --git a/tcp/conn.go b/tcp/conn.go index e7cd591..d703b7c 100644 --- a/tcp/conn.go +++ b/tcp/conn.go @@ -218,7 +218,7 @@ func (conn *Conn) Write(b []byte) (int, error) { conn.mu.Unlock() n += ngot b = b[ngot:] - if err != nil || n == plen { + if (err != nil && err != internal.ErrRingBufferFull) || n == plen { break } else if ngot > 0 { backoff.Hit()