tags:

views:

30

answers:

1

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 through 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.

A: 

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.

Mewp
@Mewp: HTTP 1.0 most certainly DOES have the Content-Length header (RFC 1945 Section 10.4). What it does not have is default persistent connections (ie the 'Connection: keep-alive' header is not assumed) like HTTP 1.1 has. The default behavior of an HTTP 1.0 reply is to close the socket after the data is sent, unless the client explicitally asks for a persistent connection in its request.
Remy Lebeau - TeamB
Oh, sorry, I didn't remember corectly.
Mewp