void
PeerDiscovery::DomainPeerDiscovery::startPublish(const std::string &type, const msgpack::sbuffer &pack_buf)
{
    //Set up New Sending pack
    msgpack::sbuffer pack_buf_c;
    pack_buf_c.write(pack_buf.data(),pack_buf.size());

    std::unique_lock<std::mutex> lck(mtx_);
    messages_[type] = std::move(pack_buf_c);
    messages_reload();
    if (not lrunning_) {
        if (running_send_.joinable())
            running_send_.join();
        lrunning_ = true;
        sender_setup();
        running_send_ = std::thread([this](){
            std::unique_lock<std::mutex> lck(mtx_);
            while (lrunning_) {
                ssize_t nbytes = sendto(
                    sockfd_,
                    sbuf_.data(),
                    sbuf_.size(),
                    0,
                    sockAddrSend_.get(),
                    sockAddrSend_.getLength()
                );
                if (nbytes < 0) {
                    std::cerr << "Error sending packet: " << strerror(errno) << std::endl;
                }
                if (cv_.wait_for(lck,std::chrono::seconds(3),[&]{ return !lrunning_; }))
                    break;
            }
        });
    }
}
Example #2
0
 T unpack(const msgpack::sbuffer & sbuf) {
   T r;
   msgpack::unpacked msg;
   msgpack::unpack(&msg, sbuf.data(), sbuf.size());
   auto obj = msg.get();
   obj.convert(&r);
   return r;
 }
Example #3
0
    static constexpr auto unpack(const msgpack::sbuffer& buffer){
        std::tuple<Args...> tmp;
            msgpack::object_handle oh =
                msgpack::unpack(buffer.data(), buffer.size());

            msgpack::object obj = oh.get();
            obj.convert(tmp);
            return tmp;
    }
Example #4
0
void sbuff_dump(const msgpack::sbuffer& sb){
    int len = sb.size();
    const char* ptr = sb.data();
    fprintf(stderr,"sb[");
    while(len > 0){
        fprintf(stderr,"%02X", (*ptr) & 0x000000ff);
        ++ptr;
        --len;
    }
    fprintf(stderr,"]\n");
}
Example #5
0
void fluent::Sender::send_internal(const ::msgpack::sbuffer& bytes)
{
    const ::msgpack::sbuffer * to_send = nullptr;
    if( !buf )
    {
        to_send = &bytes;
    }
    else {
        buf->write(bytes.data(), bytes.size());
        to_send = buf;
    }
    try {
        reconnect();
        sock.send(to_send->data(), to_send->size());
        /* TODO should I use release or clear here?
         * release frees the memory in the sbuffer,
         * clear just empties out the buffer. */
        if( buf ) {
            delete buf;
        }
    }
    catch(::std::runtime_error& e) {
        ::std::cerr << "while sending, got exception " << e.what() << "\n";
        close();
        if( buf ) {
            if(  buf->size() > bufmax ) {
                /* buffer is already full, so drop everything */
                /* python says put a callback here */
                delete buf;
            }
        }
        else {
            buf = new ::msgpack::sbuffer();
            buf->write(bytes.data(), bytes.size());
        }
        throw;
    }
}
Example #6
0
	};
}

TEST_CASE( "MessagePackTest/testDefault", "[unit]" )
{
	std::vector<std::string> target;
	target.push_back("Hello,");
	target.push_back("World!");

	// Serialize
	msgpack::sbuffer sbuf;
	msgpack::pack(&sbuf, target);

	// Deserialize
	msgpack::unpacked msg;
	msgpack::unpack(&msg, sbuf.data(), sbuf.size());
	std::vector<std::string> result;
	msg.get().convert(&result);

	assertEquals( "Hello, World!", turbo::str::join(result) );
}

TEST_CASE( "MessagePackTest/testClass", "[unit]" )
{
	CoolClass cool("foo", 1.5, {1,2,3});

	// Serialize
	msgpack::sbuffer sbuf;
	msgpack::pack(&sbuf, cool);

	// Deserialize
Example #7
0
void Connection::Send(u16 peer_id, u8 channelnum, const msgpack::sbuffer &buffer, bool reliable) {
	SharedBuffer<u8> data((unsigned char*)buffer.data(), buffer.size());
	Send(peer_id, channelnum, data, reliable);
}
Example #8
0
void ClientInterface::sendToAll(u16 channelnum,
		const msgpack::sbuffer &buffer, bool reliable)
{
	SharedBuffer<u8> data((unsigned char*)buffer.data(), buffer.size());
	sendToAll(channelnum, data, reliable);
}
Example #9
0
bool ResourceManager::TriggerEvent(fwString& eventName, msgpack::sbuffer& argsSerialized, int source)
{
	return TriggerEvent(eventName, fwString(argsSerialized.data(), argsSerialized.size()), source);
}