-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 support for passing client_data_t to flush_cache #7543
Add support for passing client_data_t to flush_cache #7543
Conversation
I've been considering doing something like this for a while now, but not just for this alert, but for all alerts that are triggered by the client. Do you think it would make sense to put the I'm thinking that it could be nice to enable clients to have more sophisticated dispatch of alerts on the client side, e.g. calling a handler function or something. |
either way, unfortunately either of these changes are ABI breaking, so should go into |
In my ideal world, I would have liked to:
This would allow for the following implementation: std::future<std::shared_ptr<lt::save_resume_data_alert>> f = th.async_save_resume_data();
try {
auto alert = f.get();
std::vector<char> buf = lt::write_torrent_file_buf(alert->params);
} catch (lt::save_resume_data_exception const& e) {
std::shared_ptr<lt::save_resume_data_failed_alert> alert = e.alert;
} Without this modification, I had considered using a callback that would be executed in the libtorrent thread (after the alert is placed in the queue, at the same level as the std::mutex m;
std::condition_variable cv;
bool done = false;
th.flush_cache([&cv, &done] (const cache_flushed_alert* alert) {
// for example: here, you must know that you can't sleep
done = true;
cv.notify_one();
});
{
std::unique_lock lk(m);
cv.wait(lk, []{ return processed; });
}
What do you think about these options? Do you have any others? |
A low-level interface is something that I also miss so much in |
here's an example with callbacks: https://github.com/joriscarrier/libtorrent/commits/callback_alert |
Allowing users to pass
client_data_t
as a parameter to thetorrent_handle::flush_cache
function.This enhancement allows users to associate custom data with the flush_cache operation;
this association will be retrieved in cache_flushed_alert by the custom data provided.