licoffe / POE-Stash-indexer-NG

High performance Path of Exile stash indexer
MIT License
43 stars 12 forks source link

protect cout with mutex to prevent interleaving character output #1

Closed fourk closed 7 years ago

fourk commented 7 years ago

I had a few issues getting this up and working last night. This fixes a few of them.

First issue was interleaved characters due to multiple threads concurrently calling cout. Resolved this by protecting calls to cout with a mutex.

The other issue is that once you are rate-limited, the program behaved incorrectly in three ways:

When you get rate limited, you receive a JSON file that does not contain a 'next_change_id' member, causing document["next_change_id"].IsNull() to crash the program on a failed assertion inside rapidjson. Now it will check for presence of next_change_id before checking its nullity.

Also, it would push an invalid changeset file (containing only an error about rate limits) back into the downloaded_files deque.

Lastly, it did not introduce any sort of delay, it would just spam redownload the rate limit error without a sleep.

This PR should resolve all of those issues. I've never really written c++ before, so there might have been a more idiomatic way of resolving these issues, but this appears to work.