Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter for download progress? #16

Closed
hrydgard opened this issue Jul 21, 2023 · 0 comments · Fixed by #23
Closed

Add getter for download progress? #16

hrydgard opened this issue Jul 21, 2023 · 0 comments · Fixed by #23

Comments

@hrydgard
Copy link
Contributor

hrydgard commented Jul 21, 2023

It would be nice to check the progress of larger downloads.

Something like this:

	if (!naettComplete(res_)) {
		// Update progress
		int downloadedBytes = 0, totalBytes= 0;
		naettGetProgress(res_, &downloadedBytes , &totalBytes);
                // ...
	}

If the size is unknown, *totalSize would be set to -1.

I guess cleanest would be if naettComplete also had two output parameters, downloadedBytes and totalBytes.

Actually I guess this can be hacked by manually reading the Content-Length header, and then checking res->body.size.

Though it occurs to me that there's a data race - if I read headers while !completed, it may be that the headers are currently being filled in.

Here's my current hack that 'works' (doing the below if naettComplete() didn't return true) but has at least two races:

	const char *header = naettGetHeader(res_, "Content-Length");
	if (header) {
		strlcpy(buf, sizeof(buf), header);
		sscanf(buf, "%d", &total);
		int size;
		naettGetBody(res_, &size);
		progress_.Update(size, total);
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant