mirror of
https://github.com/BlackMATov/curly.hpp.git
synced 2025-12-16 14:11:17 +07:00
add is_ready and is_running function for request
This commit is contained in:
@@ -137,6 +137,9 @@ namespace curly_hpp
|
||||
statuses wait() const noexcept;
|
||||
statuses status() const noexcept;
|
||||
|
||||
bool is_ready() const noexcept;
|
||||
bool is_running() const noexcept;
|
||||
|
||||
response get();
|
||||
const std::string& error() const noexcept;
|
||||
private:
|
||||
|
||||
@@ -483,6 +483,16 @@ namespace curly_hpp
|
||||
return status_;
|
||||
}
|
||||
|
||||
bool is_ready() const noexcept {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
return status_ != statuses::pending;
|
||||
}
|
||||
|
||||
bool is_running() const noexcept {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
return status_ == statuses::pending;
|
||||
}
|
||||
|
||||
statuses status() const noexcept {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
return status_;
|
||||
@@ -630,6 +640,14 @@ namespace curly_hpp
|
||||
return state_->status();
|
||||
}
|
||||
|
||||
bool request::is_ready() const noexcept {
|
||||
return state_->is_ready();
|
||||
}
|
||||
|
||||
bool request::is_running() const noexcept {
|
||||
return state_->is_running();
|
||||
}
|
||||
|
||||
response request::get() {
|
||||
return state_->get();
|
||||
}
|
||||
@@ -888,7 +906,7 @@ namespace curly_hpp
|
||||
}
|
||||
|
||||
for ( auto iter = active_handles.begin(); iter != active_handles.end(); ) {
|
||||
if ( (*iter)->status() != request::statuses::pending ) {
|
||||
if ( (*iter)->is_ready() ) {
|
||||
curl_multi_remove_handle(curlm, (*iter)->curlh().get());
|
||||
iter = active_handles.erase(iter);
|
||||
} else {
|
||||
|
||||
@@ -93,6 +93,23 @@ TEST_CASE("curly") {
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("is_ready/is_running") {
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/delay/1").send();
|
||||
REQUIRE(req.is_running());
|
||||
REQUIRE_FALSE(req.is_ready());
|
||||
REQUIRE(req.cancel());
|
||||
REQUIRE_FALSE(req.is_running());
|
||||
REQUIRE(req.is_ready());
|
||||
}
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/status/200").send();
|
||||
REQUIRE(req.wait() == net::request::statuses::done);
|
||||
REQUIRE(req.is_ready());
|
||||
REQUIRE_FALSE(req.is_running());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("get") {
|
||||
{
|
||||
auto req = net::request_builder("https://httpbin.org/status/204").send();
|
||||
|
||||
Reference in New Issue
Block a user