Skip to content

Commit

Permalink
revise
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman committed Sep 13, 2023
1 parent 428263b commit 1ee2f07
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions cmd/soroban-rpc/internal/network/requestdurationlimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,10 @@ func (w *bufferedResponseWriter) WriteOut(ctx context.Context, rw http.ResponseW
if w.statusCode != 0 {
rw.WriteHeader(w.statusCode)
}
// chunkSize defines the subset of the output buffer that we're going to attempt to write to the stream.
// we choose the typical ethernet MTU size here, to align with the expected transport layer characteristics.
const chunkSize = 1500
// iterate on the output buffer
for startChunkIdx := 0; startChunkIdx < len(w.buffer) && ctx.Err() == nil; {
// slice the output buffer into chunks.
chunkBuf := w.buffer[startChunkIdx:]
if len(chunkBuf) > chunkSize {
chunkBuf = chunkBuf[:chunkSize]
}
// write the chunk to the stream
n, err := rw.Write(chunkBuf)
// if we weren't able to write the chunk due to an error, abort writing.
if err != nil {
break
}
startChunkIdx += n

if ctx.Err() == nil {
// the following return size/error won't help us much at this point. The request is already finalized.
rw.Write(w.buffer) //nolint:errcheck
}
}

Expand Down

0 comments on commit 1ee2f07

Please sign in to comment.