ufairiya / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

If a download is cancelled and the connection terminated, the server keeps on trying to read and send the file. #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the mongoose server.
2. Download a file from the server using a client browser (I am using 
Internet Explorer version 7).
3. Cancel the download before it is completed.

What is the expected output? What do you see instead?
The server will keep on 'reading' and 'sending' the file. As I am using 
this server in an embedded system, and the final product will be running 
other heavy libraries/modules as well, conservation of resources is of 
utmost importance. Therefore, I believe that it is wise to cancel the 
download on the server side if the connection is lost or the file download 
is cancelled by the client. I am not exactly sure what the HTTP RFC says 
in this regard, but I believe changing this would definitely lighten the 
load on the server.

What version of the product are you using? On what operating system?
I am using Mongoose 2.5 on Windows XP Professional Service Pack 3 and on a 
TriMedia embedded system.

Please provide any additional information below.
To change the above mentioned behaviour, I used the following: In the push
() API, inside the while loop, if the return value 'n' is less than zero 
the push() function returns a value of '-1'. mg_write() returns the return 
value of push(). In send_opened_file_stream() I simply use this check:

        rval =  mg_write(conn, buf, n);
        if(rval == -1)
            break;

Again, this prevents the server from reading and sending a file on a 
closed connection (when the client cancels a download and the connection 
is terminated).

I hope this would be of use. If I am missing out something, please point 
it out. Thank you.

Kind regards,
Hasaan A. Raza
Software Engineer
Streaming Networks

Original issue reported on code.google.com by hasaanan...@gmail.com on 15 May 2009 at 6:09

GoogleCodeExporter commented 9 years ago
Submitted http://code.google.com/p/mongoose/source/detail?r=353

Thank you.

Original comment by valenok on 15 May 2009 at 9:04