[haiku-commits] haiku: hrev54463 - src/kits/network/libnetapi src/tests/kits/net/service docs/user/net

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 25 Jul 2020 14:13:26 -0400 (EDT)

hrev54463 adds 9 changesets to branch 'master'
old head: 5b98fa06d512ee9bacc9b8ecbf4b0926465683a4
new head: b4024938bd6e186a07cf13f75dc3e90beebd501c
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=b4024938bd6e+%5E5b98fa06d512

----------------------------------------------------------------------------

1f569db0861b: FileRequest: Make Stop() cancel the request as soon as possible
  
  This commit implements a check for the flag raised by Stop() to cancel
  a given request as soon as possible. Cancelled requests will return
  B_INTERRUPTED regardless of whether the request has completed,
  on par with how BHttpRequest is behaving at the moment.
  
  Change-Id: Ia8a95b910cff158c710c5b2ed58b4675e705642e
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3071
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

9e404c539f8f: FileRequest: More consistent progress reporting
  
  Make BFileRequest reports download progress after every DataReceived()
  calls.
  
  DownloadProgress() format has also been changed to use 0 as
  `bytesTotal` when the total size is unknown. This is similar to
  BHttpRequest functions currently.
  
  Change-Id: I2920ea00c4f841bb666425be6f8da418e913c727
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3072
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

e1de8e8c21cf: DataRequest: More consistent progress report
  
  Trigger DownloadProgress after DataReceived, similar to how other BUrlRequest
  classes behave.
  
  Change-Id: I4858c3736b1b1ebec55af9903dbfd4b976a77df3
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3073
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

2056d60ff1cf: DataRequest: Use ArrayDeleter to manage the temporary buffer
  
  This simplify the clean up code path and make sure that the temporary
  buffer will always be freed on exit.
  
  Change-Id: I70c1a25bfa66c4f4a96dd3d0af3765a67e305fb2
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3074
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

d64d305cf6ee: GopherRequest: Accurate progress reports and listener bugfixes
  
  This commit brings the following changes:
  - DownloadProgress() should now be reported for every DataReceived()
  calls, similar to other BUrlRequest classes.
  - Properly verify whether a listener has been set before invoking them.
  
  Change-Id: I4ded82e318ba580b8869c3d1751da4e36882c39f
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3075
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

0d0f613f17f9: GopherRequest: Don't wait for socket to be readable
  
  Instead we can trigger a Read() immediately, as our socket is blocking
  and won't return until some data has been made available. This avoids a
  potentially costly syscall in the loop body.
  
  Change-Id: I899f55ede41af7cb7e9311aa04006b33c40d3ee4
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3076
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

846c12f5df3c: HttpRequest: Use an ArrayDeleter to manage the temporary buffer
  
  This make sure that the temporary buffer will always be deleted should
  any premature return happens.
  
  Change-Id: I448ec7c3f3eeca1ef2b6473b49323f34bcb7bf86
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3077
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

7bac04e684cb: HttpRequest: Don't wait for socket to be readable
  
  The socket is a blocking one, which means Read() will block unless data
  is available, thus WaitForReadable() is useless in this context.
  
  Testing also shows a 2x performance increase from removing this call due
  to poll() performance being botched when KDEBUG_LEVEL >= 2.
  
  Change-Id: I3170f865e961112b420c1548726bb6fd38e94cb2
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3078
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

b4024938bd6e: BUrlProtocolListener: Update DownloadProgress() docs
  
  Updated to reflect the consistency changes done to
  BUrlProtocolListener::DownloadProgress().
  
  Change-Id: I05cfac647507a3fff294900a107293b85eff60fb
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/3079
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                       [ Leorize <leorize+oss@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

9 files changed, 181 insertions(+), 40 deletions(-)
docs/user/net/UrlProtocolListener.dox            | 13 +--
src/kits/network/libnetapi/DataRequest.cpp       | 17 ++--
src/kits/network/libnetapi/FileRequest.cpp       | 28 ++++---
src/kits/network/libnetapi/GopherRequest.cpp     | 38 ++++++---
src/kits/network/libnetapi/HttpRequest.cpp       |  7 +-
src/tests/kits/net/service/FileTest.cpp          | 84 ++++++++++++++++++++
src/tests/kits/net/service/FileTest.h            | 31 ++++++++
src/tests/kits/net/service/Jamfile               |  1 +
.../kits/net/service/ServiceKitTestAddon.cpp     |  2 +

############################################################################

Commit:      1f569db0861bb9e1be59585570165e13458b2f5b
URL:         https://git.haiku-os.org/haiku/commit/?id=1f569db0861b
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 03:56:53 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

FileRequest: Make Stop() cancel the request as soon as possible

This commit implements a check for the flag raised by Stop() to cancel
a given request as soon as possible. Cancelled requests will return
B_INTERRUPTED regardless of whether the request has completed,
on par with how BHttpRequest is behaving at the moment.

Change-Id: Ia8a95b910cff158c710c5b2ed58b4675e705642e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3071
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/FileRequest.cpp 
b/src/kits/network/libnetapi/FileRequest.cpp
index f8af6555b4..82c5f35e00 100644
--- a/src/kits/network/libnetapi/FileRequest.cpp
+++ b/src/kits/network/libnetapi/FileRequest.cpp
@@ -79,12 +79,19 @@ BFileRequest::_ProtocolLoop()
 
                        fListener->HeadersReceived(this, fResult);
 
-                       ssize_t chunkSize;
+                       ssize_t chunkSize = 0;
                        char chunk[4096];
-                       while ((chunkSize = file.Read(chunk, sizeof(chunk))) > 
0) {
-                               fListener->DataReceived(this, chunk, 
transferredSize, chunkSize);
-                               transferredSize += chunkSize;
+                       while (!fQuit) {
+                               chunkSize = file.Read(chunk, sizeof(chunk));
+                               if (chunkSize > 0) {
+                                       fListener->DataReceived(this, chunk, 
transferredSize,
+                                               chunkSize);
+                                       transferredSize += chunkSize;
+                               } else
+                                       break;
                        }
+                       if (fQuit)
+                               return B_INTERRUPTED;
                        // Return error if we didn't transfer everything
                        if (transferredSize != size) {
                                if (chunkSize < 0)
@@ -122,7 +129,7 @@ BFileRequest::_ProtocolLoop()
 
        char name[B_FILE_NAME_LENGTH];
        BEntry entry;
-       while (directory.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
+       while (!fQuit && directory.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
                // We read directories using the EPLF (Easily Parsed List 
Format)
                // This happens to be one of the formats that WebKit can 
understand,
                // and it is not too hard to parse or generate.
@@ -160,7 +167,8 @@ BFileRequest::_ProtocolLoop()
 
        if (fListener != NULL)
                fListener->DownloadProgress(this, transferredSize, 
transferredSize);
-       fResult.SetLength(transferredSize);
+       if (!fQuit)
+               fResult.SetLength(transferredSize);
 
-       return B_OK;
+       return fQuit ? B_INTERRUPTED : B_OK;
 }
diff --git a/src/tests/kits/net/service/FileTest.cpp 
b/src/tests/kits/net/service/FileTest.cpp
new file mode 100644
index 0000000000..71f68cedd4
--- /dev/null
+++ b/src/tests/kits/net/service/FileTest.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2020, Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ */
+
+#include "FileTest.h"
+
+#include <stdlib.h>
+
+#include <File.h>
+#include <FileRequest.h>
+#include <Url.h>
+#include <UrlProtocolRoster.h>
+#include <UrlProtocolListener.h>
+
+#include <ThreadedTestCaller.h>
+#include <TestUtils.h>
+
+#include "TestServer.h"
+
+
+class StopTestListener : public BUrlProtocolListener {
+public:
+       StopTestListener() {}
+
+       void DataReceived(BUrlRequest *caller, const char*, off_t, ssize_t)
+       {
+               caller->Stop();
+       }
+};
+
+
+void
+FileTest::StopTest()
+{
+       StopTestListener listener;
+       char tmpl[] = "/tmp/filestoptestXXXXXX";
+       int fd = mkstemp(tmpl);
+       CHK(fd != -1);
+       close(fd);
+
+       BFile file(tmpl, O_WRONLY | O_CREAT);
+       CHK(file.InitCheck() == B_OK);
+       BString content;
+       /* number chosen to be larger than BFileRequest buffer, adjust as 
needed */
+       content.Append('f', 40960);
+
+       CHK(file.WriteExactly(content.String(), content.Length()) == B_OK);
+
+       BUrl url("file://");
+       url.SetPath(tmpl);
+       BUrlRequest *request = BUrlProtocolRoster::MakeRequest(url, &listener);
+       CHK(request != NULL);
+
+       thread_id thr = request->Run();
+       status_t dummy;
+       wait_for_thread(thr, &dummy);
+
+       CHK(request->Status() == B_INTERRUPTED);
+
+       delete request;
+
+       request = BUrlProtocolRoster::MakeRequest("file:///", &listener);
+       CHK(request != NULL);
+
+       thr = request->Run();
+       wait_for_thread(thr, &dummy);
+
+       CHK(request->Status() == B_INTERRUPTED);
+
+       delete request;
+}
+
+
+/* static */ void
+FileTest::AddTests(BTestSuite& parent)
+{
+       CppUnit::TestSuite *suite = new CppUnit::TestSuite("FileTest");
+
+       suite->addTest(new CppUnit::TestCaller<FileTest>("FileTest: Stop 
requests",
+               &FileTest::StopTest));
+
+       parent.addTest("FileTest", suite);
+}
diff --git a/src/tests/kits/net/service/FileTest.h 
b/src/tests/kits/net/service/FileTest.h
new file mode 100644
index 0000000000..1c9bfd4d73
--- /dev/null
+++ b/src/tests/kits/net/service/FileTest.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2014-2020 Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ */
+
+#ifndef FILE_TEST_H
+#define FILE_TEST_H
+
+
+#include <Url.h>
+
+#include <TestCase.h>
+#include <TestSuite.h>
+
+#include <cppunit/TestSuite.h>
+#include <tools/cppunit/ThreadedTestCase.h>
+
+#include "TestServer.h"
+
+
+class FileTest : public BThreadedTestCase {
+public:
+                                               FileTest() {};
+
+                       void            StopTest();
+
+       static  void            AddTests(BTestSuite& suite);
+};
+
+
+#endif
diff --git a/src/tests/kits/net/service/Jamfile 
b/src/tests/kits/net/service/Jamfile
index de793aa8ea..defd5447a1 100644
--- a/src/tests/kits/net/service/Jamfile
+++ b/src/tests/kits/net/service/Jamfile
@@ -9,6 +9,7 @@ UnitTestLib servicekittest.so :
        DataTest.cpp
        HttpTest.cpp
        UrlTest.cpp
+       FileTest.cpp
        TestServer.cpp
 
        : be $(TARGET_NETWORK_LIBS) $(HAIKU_NETAPI_LIB) [ TargetLibstdc++ ]
diff --git a/src/tests/kits/net/service/ServiceKitTestAddon.cpp 
b/src/tests/kits/net/service/ServiceKitTestAddon.cpp
index d79c8d5f89..cce251b5ee 100644
--- a/src/tests/kits/net/service/ServiceKitTestAddon.cpp
+++ b/src/tests/kits/net/service/ServiceKitTestAddon.cpp
@@ -11,6 +11,7 @@
 #include "DataTest.h"
 #include "HttpTest.h"
 #include "UrlTest.h"
+#include "FileTest.h"
 
 
 BTestSuite*
@@ -22,6 +23,7 @@ getTestSuite()
        UrlTest::AddTests(*suite);
        HttpTest::AddTests(*suite);
        DataTest::AddTests(*suite);
+       FileTest::AddTests(*suite);
 
        return suite;
 }

############################################################################

Commit:      9e404c539f8ff384f9617f8dec53e9e18bce99df
URL:         https://git.haiku-os.org/haiku/commit/?id=9e404c539f8f
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 04:12:53 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

FileRequest: More consistent progress reporting

Make BFileRequest reports download progress after every DataReceived()
calls.

DownloadProgress() format has also been changed to use 0 as
`bytesTotal` when the total size is unknown. This is similar to
BHttpRequest functions currently.

Change-Id: I2920ea00c4f841bb666425be6f8da418e913c727
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3072
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/FileRequest.cpp 
b/src/kits/network/libnetapi/FileRequest.cpp
index 82c5f35e00..02b0103480 100644
--- a/src/kits/network/libnetapi/FileRequest.cpp
+++ b/src/kits/network/libnetapi/FileRequest.cpp
@@ -87,6 +87,7 @@ BFileRequest::_ProtocolLoop()
                                        fListener->DataReceived(this, chunk, 
transferredSize,
                                                chunkSize);
                                        transferredSize += chunkSize;
+                                       fListener->DownloadProgress(this, 
transferredSize, size);
                                } else
                                        break;
                        }
@@ -99,7 +100,6 @@ BFileRequest::_ProtocolLoop()
                                else
                                        return B_IO_ERROR;
                        }
-                       fListener->DownloadProgress(this, size, size);
                }
 
                return B_OK;
@@ -124,6 +124,7 @@ BFileRequest::_ProtocolLoop()
 
                // Add a parent directory entry.
                fListener->DataReceived(this, "+/,\t..\r\n", transferredSize, 
8);
+               fListener->DownloadProgress(this, transferredSize, 0);
                transferredSize += 8;
        }
 
@@ -161,12 +162,11 @@ BFileRequest::_ProtocolLoop()
                if (fListener != NULL) {
                        fListener->DataReceived(this, eplf.String(), 
transferredSize,
                                eplf.Length());
+                       fListener->DownloadProgress(this, transferredSize, 0);
                }
                transferredSize += eplf.Length();
        }
 
-       if (fListener != NULL)
-               fListener->DownloadProgress(this, transferredSize, 
transferredSize);
        if (!fQuit)
                fResult.SetLength(transferredSize);
 

############################################################################

Commit:      e1de8e8c21cf8b6796660f4f218f6cd5a34d7de5
URL:         https://git.haiku-os.org/haiku/commit/?id=e1de8e8c21cf
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 04:34:18 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

DataRequest: More consistent progress report

Trigger DownloadProgress after DataReceived, similar to how other BUrlRequest
classes behave.

Change-Id: I4858c3736b1b1ebec55af9903dbfd4b976a77df3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3073
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/DataRequest.cpp 
b/src/kits/network/libnetapi/DataRequest.cpp
index 2870b9f725..6afd33c10b 100644
--- a/src/kits/network/libnetapi/DataRequest.cpp
+++ b/src/kits/network/libnetapi/DataRequest.cpp
@@ -118,9 +118,10 @@ BDataRequest::_ProtocolLoop()
 
        if (fListener != NULL) {
                fListener->HeadersReceived(this, fResult);
-               fListener->DownloadProgress(this, length, length);
-               if (length > 0)
+               if (length > 0) {
                        fListener->DataReceived(this, payload, 0, length);
+                       fListener->DownloadProgress(this, length, length);
+               }
        }
 
        if (isBase64)

############################################################################

Commit:      2056d60ff1cf632ae3777bbacdd15326f741adfa
URL:         https://git.haiku-os.org/haiku/commit/?id=2056d60ff1cf
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 04:49:44 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

DataRequest: Use ArrayDeleter to manage the temporary buffer

This simplify the clean up code path and make sure that the temporary
buffer will always be freed on exit.

Change-Id: I70c1a25bfa66c4f4a96dd3d0af3765a67e305fb2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3074
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/DataRequest.cpp 
b/src/kits/network/libnetapi/DataRequest.cpp
index 6afd33c10b..a9ece68851 100644
--- a/src/kits/network/libnetapi/DataRequest.cpp
+++ b/src/kits/network/libnetapi/DataRequest.cpp
@@ -9,6 +9,7 @@
 
 #include "DataRequest.h"
 
+#include <AutoDeleter.h>
 #include <HttpAuthentication.h>
 #include <mail_encoding.h>
 #include <stdio.h>
@@ -88,6 +89,7 @@ BDataRequest::_ProtocolLoop()
 
        }
 
+       ArrayDeleter<char> buffer;
        if (isBase64) {
                // Check that the base64 data is properly padded (we process 
characters
                // by groups of 4 and there must not be stray chars at the end 
as
@@ -95,18 +97,17 @@ BDataRequest::_ProtocolLoop()
                if (data.Length() & 3)
                        return B_BAD_DATA;
 
-               char* buffer = new char[data.Length() * 3 / 4];
-               payload = buffer;
+               buffer.SetTo(new char[data.Length() * 3 / 4]);
+               payload = buffer.Get();
                        // payload must be a const char* so we can assign 
data.String() to
                        // it below, but decode_64 modifies buffer.
-               length = decode_base64(buffer, data.String(), data.Length());
+               length = decode_base64(buffer.Get(), data.String(), 
data.Length());
 
                // There may be some padding at the end of the base64 stream. 
This
                // prevents us from computing the exact length we should get, 
so allow
                // for some error margin.
                if (length > data.Length() * 3 / 4
                        || length < data.Length() * 3 / 4 - 3) {
-                       delete[] buffer;
                        return B_BAD_DATA;
                }
        } else {
@@ -124,8 +125,5 @@ BDataRequest::_ProtocolLoop()
                }
        }
 
-       if (isBase64)
-               delete[] payload;
-
        return B_OK;
 }

############################################################################

Commit:      d64d305cf6ee8beafd2c821c390d416cc68e1a8f
URL:         https://git.haiku-os.org/haiku/commit/?id=d64d305cf6ee
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 05:04:29 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

GopherRequest: Accurate progress reports and listener bugfixes

This commit brings the following changes:
- DownloadProgress() should now be reported for every DataReceived()
calls, similar to other BUrlRequest classes.
- Properly verify whether a listener has been set before invoking them.

Change-Id: I4ded82e318ba580b8869c3d1751da4e36882c39f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3075
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/GopherRequest.cpp 
b/src/kits/network/libnetapi/GopherRequest.cpp
index 8b4bf68555..6c1fca7e95 100644
--- a/src/kits/network/libnetapi/GopherRequest.cpp
+++ b/src/kits/network/libnetapi/GopherRequest.cpp
@@ -360,6 +360,9 @@ BGopherRequest::_ProtocolLoop()
 
                        fPosition += fInputBuffer.Size();
 
+                       if (fListener != NULL)
+                               fListener->DownloadProgress(this, fPosition, 0);
+
                        // XXX: this is plain stupid, we already copied the data
                        // and just want to drop it...
                        char *inputTempBuffer = new(std::nothrow) 
char[bytesRead];
@@ -372,11 +375,8 @@ BGopherRequest::_ProtocolLoop()
                }
        }
 
-       if (fPosition > 0) {
+       if (fPosition > 0)
                fResult.SetLength(fPosition);
-               if (fListener != NULL)
-                       fListener->DownloadProgress(this, fPosition, fPosition);
-       }
 
        fSocket->Disconnect();
 
@@ -650,7 +650,7 @@ BGopherRequest::_ParseInput(bool last)
 
                        // emit header
                        BString header;
-                       header << 
+                       header <<
                                "<html>\n"
                                "<head>\n"
                                "<meta http-equiv=\"Content-Type\""
@@ -668,17 +668,27 @@ BGopherRequest::_ParseInput(bool last)
                                "</div>\n"
                                "<h1>" << pageTitle << "</h1>\n";
 
-                       fListener->DataReceived(this, header.String(), 
fPosition,
-                               header.Length());
+                       if (fListener != NULL) {
+                               fListener->DataReceived(this, header.String(), 
fPosition,
+                                       header.Length());
+                       }
 
                        fPosition += header.Length();
+
+                       if (fListener != NULL)
+                               fListener->DownloadProgress(this, fPosition, 0);
                }
 
                if (item.Length()) {
-                       fListener->DataReceived(this, item.String(), fPosition,
-                               item.Length());
+                       if (fListener != NULL) {
+                               fListener->DataReceived(this, item.String(), 
fPosition,
+                                       item.Length());
+                       }
 
                        fPosition += item.Length();
+
+                       if (fListener != NULL)
+                               fListener->DownloadProgress(this, fPosition, 0);
                }
        }
 
@@ -689,10 +699,15 @@ BGopherRequest::_ParseInput(bool last)
                        "</body>\n"
                        "</html>\n";
 
-               fListener->DataReceived(this, footer.String(), fPosition,
-                       footer.Length());
+               if (fListener != NULL) {
+                       fListener->DataReceived(this, footer.String(), 
fPosition,
+                               footer.Length());
+               }
 
                fPosition += footer.Length();
+
+               if (fListener != NULL)
+                       fListener->DownloadProgress(this, fPosition, 0);
        }
 }
 

############################################################################

Commit:      0d0f613f17f9e06519ce5921145e69f0252ca546
URL:         https://git.haiku-os.org/haiku/commit/?id=0d0f613f17f9
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 05:10:34 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

GopherRequest: Don't wait for socket to be readable

Instead we can trigger a Read() immediately, as our socket is blocking
and won't return until some data has been made available. This avoids a
potentially costly syscall in the loop body.

Change-Id: I899f55ede41af7cb7e9311aa04006b33c40d3ee4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3076
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/GopherRequest.cpp 
b/src/kits/network/libnetapi/GopherRequest.cpp
index 6c1fca7e95..9e5765456f 100644
--- a/src/kits/network/libnetapi/GopherRequest.cpp
+++ b/src/kits/network/libnetapi/GopherRequest.cpp
@@ -272,7 +272,6 @@ BGopherRequest::_ProtocolLoop()
        BStackOrHeapArray<char, 4096> chunk(kGopherBufferSize);
 
        while (!fQuit && !receiveEnd) {
-               fSocket->WaitForReadable();
                bytesRead = fSocket->Read(chunk, kGopherBufferSize);
 
                if (bytesRead < 0) {

############################################################################

Commit:      846c12f5df3c8d5c6af77fa108a7e570ff5efc47
URL:         https://git.haiku-os.org/haiku/commit/?id=846c12f5df3c
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 05:29:34 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

HttpRequest: Use an ArrayDeleter to manage the temporary buffer

This make sure that the temporary buffer will always be deleted should
any premature return happens.

Change-Id: I448ec7c3f3eeca1ef2b6473b49323f34bcb7bf86
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3077
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/HttpRequest.cpp 
b/src/kits/network/libnetapi/HttpRequest.cpp
index 2638e66888..a7ff40f932 100644
--- a/src/kits/network/libnetapi/HttpRequest.cpp
+++ b/src/kits/network/libnetapi/HttpRequest.cpp
@@ -575,6 +575,7 @@ BHttpRequest::_MakeRequest()
        size_t previousBufferSize = 0;
        off_t bytesUnpacked = 0;
        char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize];
+       ArrayDeleter<char> inputTempBufferDeleter(inputTempBuffer);
        ssize_t inputTempSize = kHttpBufferSize;
        ssize_t chunkSize = -1;
        DynamicBuffer decompressorStorage;
@@ -664,10 +665,10 @@ BHttpRequest::_MakeRequest()
                                                        // 2 more bytes to 
handle the closing CR+LF
                                                bytesRead = chunkSize;
                                                if (inputTempSize < chunkSize + 
2) {
-                                                       delete[] 
inputTempBuffer;
                                                        inputTempSize = 
chunkSize + 2;
                                                        inputTempBuffer
                                                                = 
new(std::nothrow) char[inputTempSize];
+                                                       
inputTempBufferDeleter.SetTo(inputTempBuffer);
                                                }
 
                                                if (inputTempBuffer == NULL) {
@@ -715,8 +716,8 @@ BHttpRequest::_MakeRequest()
                                if (bytesRead > 0) {
                                        if (inputTempSize < bytesRead) {
                                                inputTempSize = bytesRead;
-                                               delete[] inputTempBuffer;
                                                inputTempBuffer = 
new(std::nothrow) char[bytesRead];
+                                               
inputTempBufferDeleter.SetTo(inputTempBuffer);
                                        }
 
                                        if (inputTempBuffer == NULL) {
@@ -781,7 +782,6 @@ BHttpRequest::_MakeRequest()
        }
 
        fSocket->Disconnect();
-       delete[] inputTempBuffer;
 
        if (readError != B_OK)
                return readError;

############################################################################

Commit:      7bac04e684cbe14ea4c7ed8180071a40fc948a96
URL:         https://git.haiku-os.org/haiku/commit/?id=7bac04e684cb
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Thu Jul 16 06:47:57 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

HttpRequest: Don't wait for socket to be readable

The socket is a blocking one, which means Read() will block unless data
is available, thus WaitForReadable() is useless in this context.

Testing also shows a 2x performance increase from removing this call due
to poll() performance being botched when KDEBUG_LEVEL >= 2.

Change-Id: I3170f865e961112b420c1548726bb6fd38e94cb2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3078
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/HttpRequest.cpp 
b/src/kits/network/libnetapi/HttpRequest.cpp
index a7ff40f932..1490e2efdf 100644
--- a/src/kits/network/libnetapi/HttpRequest.cpp
+++ b/src/kits/network/libnetapi/HttpRequest.cpp
@@ -584,7 +584,6 @@ BHttpRequest::_MakeRequest()
 
        while (!fQuit && !(receiveEnd && parseEnd)) {
                if ((!receiveEnd) && (fInputBuffer.Size() == 
previousBufferSize)) {
-                       fSocket->WaitForReadable();
                        BStackOrHeapArray<char, 4096> chunk(kHttpBufferSize);
                        bytesRead = fSocket->Read(chunk, kHttpBufferSize);
 

############################################################################

Revision:    hrev54463
Commit:      b4024938bd6e186a07cf13f75dc3e90beebd501c
URL:         https://git.haiku-os.org/haiku/commit/?id=b4024938bd6e
Author:      Leorize <leorize+oss@xxxxxxxxxxx>
Date:        Sat Jul 25 02:15:31 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat Jul 25 18:13:20 2020 UTC

BUrlProtocolListener: Update DownloadProgress() docs

Updated to reflect the consistency changes done to
BUrlProtocolListener::DownloadProgress().

Change-Id: I05cfac647507a3fff294900a107293b85eff60fb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3079
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/docs/user/net/UrlProtocolListener.dox 
b/docs/user/net/UrlProtocolListener.dox
index bf0535ef4d..113721f013 100644
--- a/docs/user/net/UrlProtocolListener.dox
+++ b/docs/user/net/UrlProtocolListener.dox
@@ -130,16 +130,19 @@
 /*!
        \fn virtual void BUrlProtocolListener::DownloadProgress(BUrlRequest* 
caller,
                ssize_t bytesReceived, ssize_t bytesTotal)
-       \brief Called each time a block of data is received.
+       \brief Called each time a block of data is downloaded.
 
-       This callback will be called after DataReceived().
+       This callback will usually be called after DataReceived().
 
        \b Frequency: Once or more
 
        \param caller The BUrlRequest that invoked this callback.
-       \param bytesReceived Number of data bytes received.
-       \param bytesTotal Total number of data bytes expected. This value is not
-               guaranteed to be meaningful.
+       \param bytesReceived Number of data bytes received. This is the number 
of
+               bytes received prior to any processing and can be smaller than 
the
+               size of the data block sent to DataReceived() as the transport 
might
+               be compressed.
+       \param bytesTotal Total number of data bytes expected. \c 0 will be 
passed
+               if the total number of data bytes is not available.
 */
 
 /*!


Other related posts:

  • » [haiku-commits] haiku: hrev54463 - src/kits/network/libnetapi src/tests/kits/net/service docs/user/net - waddlesplash