-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzmq_util.cpp
67 lines (53 loc) · 1.25 KB
/
zmq_util.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Created by meox on 15/10/16.
//
#include "ZmqServer.h"
#include "ZmqClient.h"
#include <boost/filesystem.hpp>
#include <iostream>
size_t produce_file(const std::string& fname, ZmqClient& pub)
{
std::ifstream f{fname};
std::string line;
size_t c{};
while(f)
{
std::getline(f, line, '\n');
pub.send(line);
c++;
}
return c;
}
void zmq_server()
{
ZmqServer zmqServer;
zmqServer.run();
}
void zmq_client()
{
using namespace boost::filesystem;
size_t c{};
ZmqClient zmq_client;
path p("/mnt/disk-master/DATA2");
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Start producing Data\n";
//zmq_client.wait_client();
//std::thread th_sync{&ZmqClient::sync_loop, &zmq_client};
for (directory_entry& x : directory_iterator(p))
{
time_t t_s, t_e;
const auto fname = x.path().string();
time(&t_s);
const auto n = produce_file(fname, zmq_client);
time(&t_e);
c += n;
std::cout << "done: " << fname << ", #nmsg = " << c << " - " << (double)n / (double)(t_e - t_s) << " msg/s\n";
}
zmq_client.send("###EXIT###");
//zmq_client.wait_client();
std::this_thread::sleep_for(std::chrono::seconds(10));
//zmq_client.stop();
//th_sync.join();
zmq_client.close();
std::cout << "Messages produces: " << c << "\n";
}