开发者

What happens when you interrupt an HTTP stream?

Let me try to clarify my question, I wasn't sure how to word the title. This is purely out of my curiosity.

Between the raw bytes coming over your internet connection and your browser, there are many layers. Each layer adds more structure to the data, eventually ending up as HTML markup. I'm going with the assumption that the final length of the HTML data is unknown and bytes are being streamed in until the document is complete. Please correct me if this assumption is wrong.

You've grown impatient and you click "Stop" in your browser. What happens within those layers? Is the socket closed on the client side and an exception condition allowed to rise t开发者_高级运维hrough the layers? In at least one point in this chain, there must be a blocking operation that's waiting for the layer below it and that's no longer blocking, so how does that happen?

I apologize if this is not clear. I'm having trouble putting across the picture that's in my mind.


Since HTTP operates over TCP, the application knows when the connection is terminated, and may render the content it received.

Of course, you could always improperly terminate the connection, for example by physically removing the cable connecting you to the Internet. In such case, any TCP application will wait several seconds, then declare that the connection has timed out -- in case of browsers, usually not displaying any content.

As for handling exceptions, it's up to the application. Reading from sockets is blocking, when it finishes the application should check that it has received something, and that no error occurred.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜