Use backoff to wait until there is enough room in the TCP write buffer (#34)

This commit is contained in:
ddirect
2026-02-09 02:27:18 +02:00
committed by GitHub
parent 085c7033cd
commit 1694e71e0c
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -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 {
+1 -1
View File
@@ -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()