Exemplo n.º 1
0
 static inline
 void
 pack(zmq::message_t& message,
      const std::string& value)
 {
     message.rebuild(value.size());
     
     std::memcpy(
         message.data(),
         value.data(),
         value.size()
     );
 }
 void
 init_msg(const void* t, size_t sz, zmq::message_t& msg)
 {
   try
   {
     void *data = ::malloc(sz);
     if (!data)
     {
       throw zmq::error_t();
     }
     ::memcpy(data, t, sz);
     msg.rebuild(data, sz, &zmqmessage_free, 0);
   }
   catch (const zmq::error_t& e)
   {
     throw_zmq_exception(e);
   }
 }
Exemplo n.º 3
0
void server_worker(zmq::message_t& msg, std::string str) {
  // std::cout << "Received: " << str << std::endl;
  std::string uuid_src("");
  std::string uuid_dst("");
  std::string data("");

  if (!str.empty()) {
    Utils::ParseTranserJson(str, uuid_src, uuid_dst, data);
    if (!uuid_dst.empty() && !data.empty()) {
      ServerManager::Instance().InsertMessage(uuid_src, uuid_dst, data);  
    }
  }
  From_Message fm = ServerManager::Instance().GetMessage(uuid_src);
  std::string content = Utils::BuildTranserJson(fm.uuid_dst, "", fm.data);
  std::cout << "received: " << str << "  will send: " << content << std::endl;
  //memcpy(msg.data(), content.c_str(), content.length()+1); // segment error
  msg.rebuild(content.c_str(), content.length());
  
}
Exemplo n.º 4
0
inline void str_to_msg( zmq::message_t & msg, std::string const & str )
{
	msg.rebuild( str.size()+1 );
	memcpy( msg.data(), (void*)str.c_str(), str.size()+1 );
}