From d64d305cf6ee8beafd2c821c390d416cc68e1a8f Mon Sep 17 00:00:00 2001 From: Leorize Date: Thu, 16 Jul 2020 00:04:29 -0500 Subject: [PATCH] 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 --- src/kits/network/libnetapi/GopherRequest.cpp | 37 ++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) 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 << "\n" "\n" "\n" "

" << pageTitle << "

\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) "\n" "\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); } }