Newer
Older
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
55
56
57
58
59
60
61
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020-2021 Florian Fischer
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include "CountingPrivateSemaphore.hpp"
#include "Fiber.hpp"
#include "Runtime.hpp"
#include "emper.hpp"
#include "fixtures/network.hpp"
#include "io.hpp"
#define PORT 4241
#define BUF_SIZE 1024
auto main(int argc, char* argv[]) -> int {
unsigned int client_count = 10;
unsigned int echos = 1000;
int port = PORT;
std::string host = "127.0.0.1";
if (argc > 3) {
std::cerr << "Usage: " << argv[0] << " [clients] [echos]" << std::endl;
exit(EXIT_FAILURE);
}
const int DECIMAL = 10;
if (argc > 1) {
client_count = strtol(argv[1], nullptr, DECIMAL);
}
if (argc > 2) {
echos = strtol(argv[2], nullptr, DECIMAL);
}
Runtime runtime;
runtime.scheduleFromAnywhere(*emper::io::tcp_listener(host, port, echo_serve));
Fiber* client_producer = Fiber::from([&] {
CPS cps;
for (unsigned int i = 0; i < client_count; ++i) {
spawn(
[&] {
const std::vector<std::string> msgs = {"foo"};
echo_client("127.0.0.1", PORT, msgs, echos);
},
cps);
}
cps.wait();
exit(EXIT_SUCCESS);
});
runtime.scheduleFromAnywhere(*client_producer);
runtime.waitUntilFinished();
return EXIT_FAILURE;
}