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@gmail.com>
This commit is contained in:
Leorize 2020-07-16 00:04:29 -05:00 committed by waddlesplash
parent 2056d60ff1
commit d64d305cf6

View File

@ -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);
}
}