ReCodEx - Task Broker
ReCodEx is complex programmer testing solution, primary targeted to technical universities. It's highly customizable and based on modern technologies.
router_socket_wrapper.cpp
1 #include "router_socket_wrapper.h"
2 
4  std::shared_ptr<zmq::context_t> context, const std::string &addr, const bool bound)
5  : socket_wrapper_base(context, zmq::socket_type::router, addr, bound)
6 {
7 }
8 
10 {
11  bool retval;
12  retval = socket_.send(source.identity.c_str(), source.identity.size(), ZMQ_SNDMORE) >= 0;
13 
14  if (!retval) {
15  return false;
16  }
17 
18  for (auto it = std::begin(source.data); it != std::end(source.data); ++it) {
19  retval = socket_.send(it->c_str(), it->size(), std::next(it) != std::end(source.data) ? ZMQ_SNDMORE : 0) >= 0;
20 
21  if (!retval) {
22  return false;
23  }
24  }
25 
26  return true;
27 }
28 
30 {
31  zmq::message_t msg;
32  target.data.clear();
33  bool retval;
34 
35  retval = socket_.recv(&msg, 0);
36 
37  if (!retval) {
38  return false;
39  }
40 
41  target.identity = std::string(static_cast<char *>(msg.data()), msg.size());
42 
43  while (msg.more()) {
44  try {
45  retval = socket_.recv(&msg, 0);
46  } catch (zmq::error_t) {
47  retval = false;
48  }
49 
50  if (!retval) {
51  return false;
52  }
53 
54  target.data.emplace_back(static_cast<char *>(msg.data()), msg.size());
55  }
56 
57  return true;
58 }
bool send_message(const message_container &message)
bool receive_message(message_container &target)
router_socket_wrapper(std::shared_ptr< zmq::context_t > context, const std::string &addr, const bool bound)
std::vector< std::string > data