mirror of
https://github.com/soypat/lneto.git
synced 2026-08-19 14:14:07 +00:00
Error rewrites (#43)
* pcap: reuse Frame memory * slog: reduce heap allocations of addresses; also prevent heap alloc of dhcp options in pcap * dns: heapless improvement; add StackAsync buffer for more heapless operation; start thinking of errors * errors: begin standardise errors in lneto * errors: finish standardization of errors * fix merge issues * add more lneto errors to rest of package * format errors.go
This commit is contained in:
+9
-16
@@ -1,20 +1,12 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
"github.com/soypat/lneto/internal"
|
||||
)
|
||||
|
||||
var (
|
||||
errPacketQueueFull = errors.New("packet queue full")
|
||||
errQueuedPacketsLEZ = errors.New("queued packets <=0")
|
||||
errInvalidBufSize = errors.New("invalid buffer size")
|
||||
errSeqLessThanLast = errors.New("sequence number less than last sequence number")
|
||||
errNoPacketToAck = errors.New("no packet to ack")
|
||||
errAckUnsent = errors.New("ack of unsent packet")
|
||||
)
|
||||
|
||||
const (
|
||||
// this must be at least 2 for buffer to work.
|
||||
minBufferSize = 2
|
||||
@@ -60,9 +52,9 @@ type ringidx struct {
|
||||
func (rtx *ringTx) Reset(buf []byte, maxqueuedPackets int, iss Value) error {
|
||||
buf = buf[:len(buf):len(buf)] // safely omit capacity section.
|
||||
if maxqueuedPackets <= 0 {
|
||||
return errQueuedPacketsLEZ
|
||||
return lneto.ErrInvalidConfig
|
||||
} else if len(buf) < minBufferSize || len(buf) < maxqueuedPackets {
|
||||
return errInvalidBufSize
|
||||
return lneto.ErrShortBuffer
|
||||
}
|
||||
|
||||
*rtx = ringTx{
|
||||
@@ -127,11 +119,12 @@ func (rtx *ringTx) Write(b []byte) (n int, err error) {
|
||||
func (rtx *ringTx) MakePacket(b []byte, currentSeq Value) (int, error) {
|
||||
free := rtx.slist.Free()
|
||||
if free == 0 {
|
||||
return 0, errPacketQueueFull
|
||||
return 0, lneto.ErrBufferFull
|
||||
}
|
||||
endSeq, ok := rtx.sentEndSeq()
|
||||
if ok && currentSeq.LessThan(endSeq) {
|
||||
return 0, errSeqLessThanLast
|
||||
internal.LogAttrs(nil, slog.LevelError, "txqueue:seq<endseq", slog.Uint64("seq", uint64(currentSeq)), slog.Uint64("endseq", uint64(endSeq)))
|
||||
return 0, lneto.ErrBug
|
||||
}
|
||||
// Reading unsent ring consumes unsent and converts it to "sent".
|
||||
unsent, _ := rtx.unsentRing()
|
||||
@@ -321,11 +314,11 @@ func (sl *sentlist) AddPacket(datalen, off, bufsize int, seq Value) *ringidx {
|
||||
func (sl *sentlist) RecvAck(ack Value, bufsize int) error {
|
||||
newest := sl.Newest()
|
||||
if newest == nil {
|
||||
return errNoPacketToAck
|
||||
return lneto.ErrPacketDrop
|
||||
}
|
||||
endseq := newest.endSeq()
|
||||
if endseq.LessThan(ack) {
|
||||
return errAckUnsent
|
||||
return lneto.ErrPacketDrop
|
||||
}
|
||||
// Mark fully acked.
|
||||
for i := 0; i < len(sl.pkts); i++ {
|
||||
|
||||
Reference in New Issue
Block a user