-
Notifications
You must be signed in to change notification settings - Fork 62
/
client02.cc
54 lines (42 loc) · 1.66 KB
/
client02.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 模拟 https://github.com/sogou/workflow/issues/135
#include <workflow/Workflow.h>
#include <workflow/WFTaskFactory.h>
#include <workflow/WFFacilities.h>
#include <spdlog/spdlog.h>
#include <vector>
#include <atomic>
using namespace protocol;
const int k_redirect_max = 4;
const int k_retry_max = 2;
std::atomic<int> seq;
void http_callback(WFHttpTask *task)
{
spdlog::info("state : {}, err : {}, seq : {}",
task->get_state(), task->get_error(), seq++);
}
int main()
{
std::string url = "http://127.0.0.1:8888/";
struct WFGlobalSettings settings = GLOBAL_SETTINGS_DEFAULT;
settings.endpoint_params.max_connections = 1024;
WORKFLOW_library_init(&settings);
WFFacilities::WaitGroup wait_group(1);
ParallelWork *pwork = Workflow::create_parallel_work([&wait_group](const ParallelWork *pwork)
{
spdlog::info("All series in this parallel have done");
wait_group.done();
});
for (int i = 0; i < 400; i++)
{
WFHttpTask *task = WFTaskFactory::create_http_task(url,
k_redirect_max,
k_retry_max,
http_callback);
SeriesWork *series = Workflow::create_series_work(task, nullptr);
pwork->add_series(series);
}
spdlog::info("client start");
pwork->start();
wait_group.wait();
return 0;
}