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 naettGetTotalBytesRead #18

Closed
wants to merge 11 commits into from
Closed

Conversation

hrydgard
Copy link
Contributor

@hrydgard hrydgard commented Jul 21, 2023

This lets you implement a progress bar for downloads safely and efficiently by calling naettGetTotalBytesRead() after checking naettComplete() and finding out it's not done yet.

The first commit makes sure that res->headers only gets written to once by the various backends. This is not actually needed for the two later commits, and still doesn't technically make it safe to read headers before the full request is complete (although in practice it'll be), but it's still good practice and probably a slight performance improvement. Not implemented in linux.c though because it's less convenient to do there.

Fixes #16

Copy link
Owner

@erkkah erkkah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The only issue with this is that it extends the non-thread-safe handling of the completed field with the progress field. I'll add an issue about that.

@erkkah
Copy link
Owner

erkkah commented Jul 31, 2023

Of course some conflicts. If you rebase on main, I'll merge!

@hrydgard
Copy link
Contributor Author

hrydgard commented Jul 31, 2023

will do!

also, accesses to 32-bit fields are effectively atomic - although unlike actual atomics not with respect to surrounding operations since the compiler can move stuff around, but progress only needs to be approximate anyway, so...

@hrydgard
Copy link
Contributor Author

hrydgard commented Jul 31, 2023

Rebased on main.

@hrydgard
Copy link
Contributor Author

hrydgard commented Jul 31, 2023

Hm, looks like a linking error with the "min" function. I don't get that error myself, but I'll try to do something.

@erkkah
Copy link
Owner

erkkah commented Jul 31, 2023

Yep, it's just the reordering that can be an issue.

Yes, the definition of min is different on the mingw pipeline used in tests. That's why I had the define earlier, but I was a bit too eager.

@erkkah
Copy link
Owner

erkkah commented Jul 31, 2023

BTW, I've fixed the warnings in the test rig locally.

@hrydgard
Copy link
Contributor Author

hrydgard commented Jul 31, 2023

Took the easy way out.

By the way, thanks for this convenient little library. Exactly what I needed, and I'll probably end up using it in more projects in the future.

@erkkah
Copy link
Owner

erkkah commented Jul 31, 2023

Still fails on the old uses of min. I don't have an MSVC setup available.
Wouldn't it work to keep the old #define min(a,b) (((a)<(b))?(a):(b)) define, and the NOMINMAX define?

You're welcome. This little library was just what I needed as well :)

@hrydgard
Copy link
Contributor Author

hrydgard commented Jul 31, 2023

Alright, I'll move back to that. Although, I don't see where those old uses are - I don't see any in the code.

@hrydgard
Copy link
Contributor Author

hrydgard commented Jul 31, 2023

OK the windows test runner is clearly not even using my latest changes, it seems to be running an older build. Not sure what's going on.

@erkkah
Copy link
Owner

erkkah commented Jul 31, 2023

Weird. I'll fix!

@erkkah erkkah mentioned this pull request Jul 31, 2023
@erkkah
Copy link
Owner

erkkah commented Jul 31, 2023

Moved this to a new PR #23 For branching / workflow reasons.

@erkkah erkkah closed this Jul 31, 2023
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 this pull request may close these issues.

Add getter for download progress?
2 participants