-
Notifications
You must be signed in to change notification settings - Fork 1
/
aeron_test.cpp
37 lines (33 loc) · 1.16 KB
/
aeron_test.cpp
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
#include <thread>
#include <chrono>
#include <iostream>
#include <Aeron.h>
#include "aeron.h"
using namespace aeron;
int poll_callback(char* buf, int len) {
std::cout << "AeronPollCallback: " << std::string{buf, size_t(len)} << std::endl;
return 0;
}
int main(int argc, char **argv) {
int ret = aeron_initialize((char*)"/opt/yi/data/aeron");
if (ret < 0)
return -1;
std::cout << "inited" << std::endl;
if (argv[1] == std::string("pub")) {
auto pub_idx = aeron_add_publication(argv[2], atoi(argv[3]));
std::cout << "isConnected: " << aeron_publication_is_connected(pub_idx) << std::endl;
for (int i = 0; i < 100000; ++i) {
char buf[32];
sprintf(buf, "pub: %d", i);
aeron_publish(pub_idx, buf, 8);
std::cout << buf << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
} else {
auto sub_idx = aeron_add_subscription(argv[2], atoi(argv[3]));
aeron_poll(sub_idx, poll_callback);
std::cout << "polling......." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(100));
}
aeron_destroy();
}