Skip to content

Commit

Permalink
avoid unnecessary flush
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaydenr committed Dec 20, 2024
1 parent a95faa1 commit 8df3653
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/NIOHTTPResponsiveness/HTTPDrippingDownloadHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ public final class HTTPDrippingDownloadHandler: ChannelDuplexHandler {
drippingState.currentChunkBytesLeft -= toSend
dataWritten = true
}
if dataWritten {
context.flush()
}

// If we weren't able to send the full chunk, it's because the channel isn't writable. We yield until it is
if drippingState.currentChunkBytesLeft > 0 {
self.pendingWrite = true
self.phase = .dripping(drippingState)
if dataWritten {
context.flush()
}
return
}

Expand All @@ -218,6 +218,10 @@ public final class HTTPDrippingDownloadHandler: ChannelDuplexHandler {
return
}

if dataWritten {
context.flush()
}

// More chunks to write.. Kick off timer
drippingState.currentChunkBytesLeft = self.size
self.phase = .dripping(drippingState)
Expand Down

0 comments on commit 8df3653

Please sign in to comment.