コード例 #1
0
void CMaquetteImpl::send(CPacketToSend& packet, bool wait /*= false*/)
{
	const data_t data = packet.encode();
	LOG4CPLUS_DEBUG(logger, "Sending " << CPacket::Type::toString(data[0]) << ": " << data.size() << " byte\n" << CUtils::dump(data).c_str());

	// Send message to the server
	// See https://casablanca.codeplex.com/wikipage?title=Web%20Socket&referringTitle=Documentation
	auto buf = std::make_shared<producer_consumer_buffer<byte>>();
	auto task = buf->putn_nocopy(data.data(), data.size())
		.then([=](size_t size) {
			websocket_outgoing_message msg;
			msg.set_binary_message(buf->create_istream(), size);
			pplx::task<void>task = m_client->send(msg);
			task.then([](pplx::task<void> t) {
				try {
					t.get();
				} catch(const websocket_exception& ex) {
					LOG4CPLUS_ERROR(logger, "websocket_callback_client::send() failed: " << ex.what());
				}
			});
			return task;
		});
		
	if(wait) task.wait();
	if(packet.type() != CPacket::Type::PINGREQ) {
		m_keepAliveTimer.restart();
	}
}
コード例 #2
0
        std::string encode(const data_t& data) const {
            auto end = reinterpret_cast<const uint8_t*>(&*data.end());
            uint8_t tmp[base_t::digits_per_unit];
            char out[base_t::digits_per_unit];

            std::string text;
            text.reserve(this->estimate(data.size()));
            auto in = reinterpret_cast<const uint8_t*>(data.data());
            size_t n = 0;
            while (in < end) {
                n = this->stretch(in, tmp, end);
                for (size_t i = 0; i < n; ++i) {
                    out[i] = this->digit(tmp[i]);
                }
                text.append(out, n);
            }
            if (this->padding and n != 0 and n != sizeof(out)) {
                text.append(sizeof(out) - n, '=');
            }
            return text;
        }
コード例 #3
0
ファイル: gzip.cpp プロジェクト: 0x0all/nanocv
 bool io::uncompress_gzip(const data_t& istream, data_t& data)
 {
         stream_t stream(istream.data(), istream.size());
         return io_uncompress_gzip(stream, stream.size(), data);
 }