Add requestsBufferSize function (#2124)
This commit is contained in:
parent
206ef0d881
commit
5b5d1906bf
|
@ -72,6 +72,8 @@ int main()
|
|||
std::cout << "count=" << nth_resp << std::endl;
|
||||
});
|
||||
}
|
||||
std::cout << "requestsBufferSize:" << client->requestsBufferSize()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
app().run();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <drogon/HttpRequest.h>
|
||||
#include <trantor/utils/NonCopyable.h>
|
||||
#include <trantor/net/EventLoop.h>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <future>
|
||||
|
@ -178,6 +179,12 @@ class DROGON_EXPORT HttpClient : public trantor::NonCopyable
|
|||
*/
|
||||
virtual void setSockOptCallback(std::function<void(int)> cb) = 0;
|
||||
|
||||
/**
|
||||
* @brief Return the number of unsent http requests in the current http
|
||||
* client cache buffer
|
||||
*/
|
||||
virtual std::size_t requestsBufferSize() = 0;
|
||||
|
||||
/// Set the pipelining depth, which is the number of requests that are not
|
||||
/// responding.
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include <trantor/net/EventLoop.h>
|
||||
#include <trantor/net/Resolver.h>
|
||||
#include <trantor/net/TcpClient.h>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
@ -115,6 +118,21 @@ class HttpClientImpl final : public HttpClient,
|
|||
sockOptCallback_ = std::move(cb);
|
||||
}
|
||||
|
||||
std::size_t requestsBufferSize() override
|
||||
{
|
||||
if (loop_->isInLoopThread())
|
||||
{
|
||||
return requestsBuffer_.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::promise<std::size_t> bufferSize;
|
||||
loop_->queueInLoop(
|
||||
[&] { bufferSize.set_value(requestsBuffer_.size()); });
|
||||
return bufferSize.get_future().get();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<trantor::TcpClient> tcpClientPtr_;
|
||||
trantor::EventLoop *loop_;
|
||||
|
|
Loading…
Reference in New Issue