Skip to content

Commit

Permalink
refactor: Shrink buffer if subsequent requests can work with smaller …
Browse files Browse the repository at this point in the history
…request sizes
  • Loading branch information
pojntfx committed Oct 5, 2023
1 parent 7183cde commit b9d19c2
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions pkg/server/nbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,7 @@ n:
}

// Transmission
var (
b = []byte{}
maxObservedLength = uint32(0)
)
b := []byte{}
for {
var requestHeader protocol.TransmissionRequestHeader
if err := binary.Read(conn, binary.BigEndian, &requestHeader); err != nil {
Expand All @@ -349,10 +346,8 @@ n:
return ErrInvalidBlocksize
}

if length > maxObservedLength {
if length != uint32(len(b)) {
b = make([]byte, length)

maxObservedLength = length
}

switch requestHeader.Type {
Expand Down

0 comments on commit b9d19c2

Please sign in to comment.