[haiku-commits] Re: haiku: hrev46743 - src/kits/network/libnetapi src/apps/haiku-depot/textview headers/private/kernel/util src/apps/haiku-depot

  • From: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 22 Jan 2014 22:37:11 +0100

On 01/22/2014 10:23 PM, superstippi@xxxxxx wrote:
14652ec: trim support code: The passed in MemoryDeleter was never used.

Oh, thanks!

--- a/src/kits/network/libnetapi/FileRequest.cpp
+++ b/src/kits/network/libnetapi/FileRequest.cpp
@@ -73,12 +73,11 @@ BFileRequest::_ProtocolLoop()
                        char chunk[4096];
                        while ((chunkSize = file.Read(chunk, sizeof(chunk))) > 
0) {
                                fListener->DataReceived(this, chunk, chunkSize);
-                               if (chunkSize > 0)
-                                       transferredSize += chunkSize;
-                               else if (transferredSize != size)
-                                       return chunkSize;
+                               transferredSize += chunkSize;
+                       // Return last error if we didn't transfer everything
+                       if (transferredSize != size)
+                               return chunkSize;
                        fListener->DownloadProgress(this, size, size);

The code is still not really correct, though; a chunkSize of zero would just mean EOF, and it would return B_OK this way, which probably isn't what should happen.

Why not just check for "chunkSize < 0" there, and use the "transferredSize != size" to return an additional error (not sure if there is one for "unexpected EOF" yet)?

Also, one probably will want to notify the listener before that, and also from time to time during the copy. Although I wonder what DownloadProgress() is meant for when there is already a DataReceived() hook. That doesn't look like a very thought through API, at least. Is there no hook for the error case either?


Other related posts: