mirror of
https://github.com/soypat/lneto.git
synced 2026-09-03 21:39:04 +00:00
Use backoff to wait until there is enough room in the TCP write buffer (#34)
This commit is contained in:
+3
-3
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errRingBufferFull = errors.New("lneto/ring: buffer full")
|
ErrRingBufferFull = errors.New("lneto/ring: buffer full")
|
||||||
errRingNoData = errors.New("lneto/ring: empty write")
|
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)
|
limit := r.FreeLimited(limitOffset)
|
||||||
if len(b) > limit {
|
if len(b) > limit {
|
||||||
return 0, errRingBufferFull
|
return 0, ErrRingBufferFull
|
||||||
}
|
}
|
||||||
return r.Write(b)
|
return r.Write(b)
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ func (r *Ring) Write(b []byte) (int, error) {
|
|||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
return 0, errRingNoData
|
return 0, errRingNoData
|
||||||
} else if r.IsFull() || r.Free() < len(b) {
|
} else if r.IsFull() || r.Free() < len(b) {
|
||||||
return 0, errRingBufferFull
|
return 0, ErrRingBufferFull
|
||||||
}
|
}
|
||||||
midFree := r.midFree()
|
midFree := r.midFree()
|
||||||
if midFree > 0 {
|
if midFree > 0 {
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ func (conn *Conn) Write(b []byte) (int, error) {
|
|||||||
conn.mu.Unlock()
|
conn.mu.Unlock()
|
||||||
n += ngot
|
n += ngot
|
||||||
b = b[ngot:]
|
b = b[ngot:]
|
||||||
if err != nil || n == plen {
|
if (err != nil && err != internal.ErrRingBufferFull) || n == plen {
|
||||||
break
|
break
|
||||||
} else if ngot > 0 {
|
} else if ngot > 0 {
|
||||||
backoff.Hit()
|
backoff.Hit()
|
||||||
|
|||||||
Reference in New Issue
Block a user