Skip to content

Commit

Permalink
transport: optimize stream read
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Dec 26, 2024
1 parent 3ef2202 commit 2b37e4a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fw/face/stream-transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func readTlvStream(
onFrame func([]byte),
ignoreError func(error) bool,
) error {
recvBuf := make([]byte, defn.MaxNDNPacketSize*32)
recvBuf := make([]byte, defn.MaxNDNPacketSize*8)
recvOff := 0
tlvOff := 0

Expand Down Expand Up @@ -60,8 +60,15 @@ func readTlvStream(
}
}

// If recvOff and tlvOff coincide, reset to beginning (for free!)
if recvOff == tlvOff {
recvOff = 0
tlvOff = 0
continue
}

// If less than one packet space remains in buffer, shift to beginning
if recvOff-tlvOff < defn.MaxNDNPacketSize {
if len(recvBuf)-recvOff < defn.MaxNDNPacketSize {
copy(recvBuf, recvBuf[tlvOff:recvOff])
recvOff -= tlvOff
tlvOff = 0
Expand Down

0 comments on commit 2b37e4a

Please sign in to comment.