Reputation: 4202
In .NET, the description of httpResponse.end()
states "Sends all currently buffered output to the client". Can anyone explain to me what that means? Specifically what is 'buffered output'? I am asking because I was asked to replace httpResponse.end
with HttpContext.Current.ApplicationInstance.CompleteRequest()
. This is causing issues when there are files involved, so I'm guessing that phrase has something to do with it.
Upvotes: 4
Views: 1503
Reputation: 726599
Buffered output is the output that your program has already produced, but has not forwarded to its intended destination yet.
Buffering is used a lot with I/O operations to avoid the cost of sending/writing the data in small increments: rather than passing the output to its destination as you write, the system collects larger chunks of it in a memory area called "the buffer", and sends/writes the data only when a certain size is reached.
There are two ways a buffered data makes it to its destination:
httpResponse.end
is one such method: it empties the buffer by sending everything that you have written so far to the client.
Upvotes: 1
Reputation: 203834
Rather than sending every single bit of information as soon as you write it to the output stream, it stores what you've written in memory until it has "enough" data that it considers it worth taking the time to send it to the client. The size of the buffer can vary widely depending on the context and reason for buffering data. To "flush" a buffer is to process all pending data in the buffer (in this case, the processing means sending it over the network to the client). That's what end
is doing in your case.
Buffering can be done for many reasons, but usually it's a matter of performance. It would be very wasteful and time consuming if you sent a network packet for every single character you wrote to your stream, or (in many cases) every string passed to Write
. The application will perform faster by sending fewer, larger, packets of information.
Upvotes: 2
Reputation: 26290
Buffered output means any output that is ready to be sent to the client, but not sent to the client yet.
Upvotes: 1