mirror of
https://github.com/tstack/lnav
synced 2024-11-03 23:15:38 +00:00
[cleanup] some curl-related fixes
This commit is contained in:
parent
076d730fa2
commit
a871ad5dbc
@ -679,13 +679,13 @@ void execute_init_commands(exec_context &ec, vector<pair<Result<string, string>,
|
||||
|
||||
if (!lnav_data.ld_pt_search.empty()) {
|
||||
#ifdef HAVE_LIBCURL
|
||||
unique_ptr<papertrail_proc> pt(new papertrail_proc(
|
||||
lnav_data.ld_pt_search.substr(3),
|
||||
lnav_data.ld_pt_min_time,
|
||||
lnav_data.ld_pt_max_time));
|
||||
auto pt = make_shared<papertrail_proc>(
|
||||
lnav_data.ld_pt_search.substr(3),
|
||||
lnav_data.ld_pt_min_time,
|
||||
lnav_data.ld_pt_max_time);
|
||||
lnav_data.ld_active_files.fc_file_names[lnav_data.ld_pt_search]
|
||||
.with_fd(pt->copy_fd());
|
||||
lnav_data.ld_curl_looper.add_request(pt.release());
|
||||
lnav_data.ld_curl_looper.add_request(pt);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -41,14 +41,14 @@
|
||||
using namespace std;
|
||||
|
||||
struct curl_request_eq {
|
||||
curl_request_eq(const std::string &name) : cre_name(name) {
|
||||
explicit curl_request_eq(const std::string &name) : cre_name(name) {
|
||||
};
|
||||
|
||||
bool operator()(const curl_request *cr) const {
|
||||
bool operator()(const std::shared_ptr<curl_request>& cr) const {
|
||||
return this->cre_name == cr->get_name();
|
||||
};
|
||||
|
||||
bool operator()(const pair<mstime_t, curl_request *> &pair) const {
|
||||
bool operator()(const pair<mstime_t, std::shared_ptr<curl_request>> &pair) const {
|
||||
return this->cre_name == pair.second->get_name();
|
||||
};
|
||||
|
||||
@ -147,10 +147,10 @@ void curl_looper::requeue_requests(mstime_t up_to_time)
|
||||
{
|
||||
while (!this->cl_poll_queue.empty() &&
|
||||
this->cl_poll_queue.front().first <= up_to_time) {
|
||||
curl_request *cr = this->cl_poll_queue.front().second;
|
||||
auto cr = this->cl_poll_queue.front().second;
|
||||
|
||||
log_debug("%s:polling request is ready again -- %p",
|
||||
cr->get_name().c_str(), cr);
|
||||
cr->get_name().c_str(), cr.get());
|
||||
this->cl_handle_to_request[cr->get_handle()] = cr;
|
||||
curl_multi_add_handle(this->cl_curl_multi, cr->get_handle());
|
||||
this->cl_poll_queue.erase(this->cl_poll_queue.begin());
|
||||
@ -161,11 +161,11 @@ void curl_looper::check_for_new_requests() {
|
||||
std::unique_lock<std::mutex> mg(this->cl_mutex);
|
||||
|
||||
while (!this->cl_new_requests.empty()) {
|
||||
curl_request *cr = this->cl_new_requests.back();
|
||||
auto cr = this->cl_new_requests.back();
|
||||
|
||||
log_info("%s:new curl request %p",
|
||||
cr->get_name().c_str(),
|
||||
cr);
|
||||
cr.get());
|
||||
this->cl_handle_to_request[cr->get_handle()] = cr;
|
||||
curl_multi_add_handle(this->cl_curl_multi, cr->get_handle());
|
||||
this->cl_new_requests.pop_back();
|
||||
@ -179,23 +179,20 @@ void curl_looper::check_for_new_requests() {
|
||||
|
||||
log_info("attempting to close request -- %s", name.c_str());
|
||||
if (all_iter != this->cl_all_requests.end()) {
|
||||
map<CURL *, curl_request *>::iterator act_iter;
|
||||
vector<pair<mstime_t, curl_request *> >::iterator poll_iter;
|
||||
curl_request *cr = *all_iter;
|
||||
auto cr = *all_iter;
|
||||
|
||||
log_info("%s:closing request -- %p",
|
||||
cr->get_name().c_str(), cr);
|
||||
cr->get_name().c_str(), cr.get());
|
||||
(*all_iter)->close();
|
||||
act_iter = this->cl_handle_to_request.find(cr);
|
||||
auto act_iter = this->cl_handle_to_request.find(cr->get_handle());
|
||||
if (act_iter != this->cl_handle_to_request.end()) {
|
||||
this->cl_handle_to_request.erase(act_iter);
|
||||
curl_multi_remove_handle(this->cl_curl_multi,
|
||||
cr->get_handle());
|
||||
delete cr;
|
||||
this->cl_handle_to_request.erase(act_iter);
|
||||
}
|
||||
poll_iter = find_if(this->cl_poll_queue.begin(),
|
||||
this->cl_poll_queue.end(),
|
||||
curl_request_eq(name));
|
||||
auto poll_iter = find_if(this->cl_poll_queue.begin(),
|
||||
this->cl_poll_queue.end(),
|
||||
curl_request_eq(name));
|
||||
if (poll_iter != this->cl_poll_queue.end()) {
|
||||
this->cl_poll_queue.erase(poll_iter);
|
||||
}
|
||||
@ -228,33 +225,30 @@ void curl_looper::check_for_finished_requests()
|
||||
|
||||
curl_multi_remove_handle(this->cl_curl_multi, easy);
|
||||
if (iter != this->cl_handle_to_request.end()) {
|
||||
curl_request *cr = iter->second;
|
||||
auto cr = iter->second;
|
||||
long delay_ms;
|
||||
|
||||
this->cl_handle_to_request.erase(iter);
|
||||
delay_ms = cr->complete(msg->data.result);
|
||||
if (delay_ms < 0) {
|
||||
vector<curl_request *>::iterator all_iter;
|
||||
|
||||
log_info("%s:curl_request %p finished, deleting...",
|
||||
cr->get_name().c_str(), cr);
|
||||
cr->get_name().c_str(), cr.get());
|
||||
{
|
||||
std::unique_lock<std::mutex> mg(this->cl_mutex);
|
||||
|
||||
all_iter = find(this->cl_all_requests.begin(),
|
||||
this->cl_all_requests.end(),
|
||||
cr);
|
||||
auto all_iter = find(this->cl_all_requests.begin(),
|
||||
this->cl_all_requests.end(),
|
||||
cr);
|
||||
if (all_iter != this->cl_all_requests.end()) {
|
||||
this->cl_all_requests.erase(all_iter);
|
||||
}
|
||||
this->cl_cond.notify_all();
|
||||
}
|
||||
delete cr;
|
||||
}
|
||||
else {
|
||||
log_debug("%s:curl_request %p is polling, requeueing in %d",
|
||||
cr->get_name().c_str(),
|
||||
cr,
|
||||
cr.get(),
|
||||
delay_ms);
|
||||
this->cl_poll_queue.emplace_back(getmstime() + delay_ms, cr);
|
||||
sort(this->cl_poll_queue.begin(), this->cl_poll_queue.end());
|
||||
|
@ -52,7 +52,7 @@ class curl_looper {
|
||||
public:
|
||||
void start() { };
|
||||
void stop() { };
|
||||
void add_request(curl_request *cr) { };
|
||||
void add_request(std::shared_ptr<curl_request> cr) { };
|
||||
void close_request(const std::string &name) { };
|
||||
void process_all() { };
|
||||
};
|
||||
@ -186,7 +186,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void add_request(curl_request *cr) {
|
||||
void add_request(std::shared_ptr<curl_request> cr) {
|
||||
std::unique_lock<std::mutex> mg(this->cl_mutex);
|
||||
|
||||
require(cr != nullptr);
|
||||
@ -232,11 +232,11 @@ private:
|
||||
auto_mem<CURLM> cl_curl_multi;
|
||||
std::mutex cl_mutex;
|
||||
std::condition_variable cl_cond;
|
||||
std::vector<curl_request *> cl_all_requests;
|
||||
std::vector<curl_request *> cl_new_requests;
|
||||
std::vector<std::shared_ptr<curl_request>> cl_all_requests;
|
||||
std::vector<std::shared_ptr<curl_request>> cl_new_requests;
|
||||
std::vector<std::string> cl_close_requests;
|
||||
std::map<CURL *, curl_request *> cl_handle_to_request;
|
||||
std::vector<std::pair<mstime_t, curl_request *> > cl_poll_queue;
|
||||
std::map<CURL *, std::shared_ptr<curl_request>> cl_handle_to_request;
|
||||
std::vector<std::pair<mstime_t, std::shared_ptr<curl_request>>> cl_poll_queue;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@ -2339,11 +2339,11 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
|
||||
}
|
||||
#ifdef HAVE_LIBCURL
|
||||
else if (is_url(argv[lpc])) {
|
||||
unique_ptr<url_loader> ul(new url_loader(argv[lpc]));
|
||||
auto ul = std::make_shared<url_loader>(argv[lpc]);
|
||||
|
||||
lnav_data.ld_active_files.fc_file_names[argv[lpc]]
|
||||
.with_fd(ul->copy_fd());
|
||||
lnav_data.ld_curl_looper.add_request(ul.release());
|
||||
lnav_data.ld_curl_looper.add_request(ul);
|
||||
}
|
||||
#endif
|
||||
else if (is_glob(argv[lpc])) {
|
||||
|
@ -112,13 +112,13 @@ static string refresh_pt_search()
|
||||
if (lnav_data.ld_pt_search.empty()) {
|
||||
return "info: no papertrail query is active";
|
||||
}
|
||||
unique_ptr<papertrail_proc> pt(new papertrail_proc(
|
||||
lnav_data.ld_pt_search.substr(3),
|
||||
lnav_data.ld_pt_min_time,
|
||||
lnav_data.ld_pt_max_time));
|
||||
auto pt = std::make_shared<papertrail_proc>(
|
||||
lnav_data.ld_pt_search.substr(3),
|
||||
lnav_data.ld_pt_min_time,
|
||||
lnav_data.ld_pt_max_time);
|
||||
lnav_data.ld_active_files.fc_file_names[lnav_data.ld_pt_search]
|
||||
.with_fd(pt->copy_fd());
|
||||
lnav_data.ld_curl_looper.add_request(pt.release());
|
||||
lnav_data.ld_curl_looper.add_request(pt);
|
||||
|
||||
ensure_view(&lnav_data.ld_views[LNV_LOG]);
|
||||
|
||||
@ -1933,11 +1933,11 @@ static Result<string, string> com_open(exec_context &ec, string cmdline, vector<
|
||||
retval = "error: lnav was not compiled with libcurl";
|
||||
#else
|
||||
if (!ec.ec_dry_run) {
|
||||
auto ul = make_unique<url_loader>(fn);
|
||||
auto ul = make_shared<url_loader>(fn);
|
||||
|
||||
lnav_data.ld_active_files.fc_file_names[fn]
|
||||
.with_fd(ul->copy_fd());
|
||||
lnav_data.ld_curl_looper.add_request(ul.release());
|
||||
lnav_data.ld_curl_looper.add_request(ul);
|
||||
lnav_data.ld_files_to_front.emplace_back(fn, top);
|
||||
retval = "info: opened URL";
|
||||
} else {
|
||||
|
@ -346,7 +346,6 @@ static unordered_map<string, attr_line_t> EXAMPLE_RESULTS;
|
||||
|
||||
void execute_examples()
|
||||
{
|
||||
exec_context &ec = lnav_data.ld_exec_context;
|
||||
db_label_source &dls = lnav_data.ld_db_row_source;
|
||||
db_overlay_source &dos = lnav_data.ld_db_overlay;
|
||||
textview_curses &db_tc = lnav_data.ld_views[LNV_DB];
|
||||
|
Loading…
Reference in New Issue
Block a user