Exemplo n.º 1
0
  // construct STOMP frame (command & header) from a streambuf
  // --------------------------------------------------
  Frame::Frame(boost::asio::streambuf& stomp_response, const stomp_server_command_map_t& cmd_map)
  // --------------------------------------------------
  {
		string _str;

		try {
			// STEP 1: find the next STOMP command line in stomp_response.
			// Chomp unknown lines till the buffer is empty, in which case an exception is raised
			//debug_print(boost::format("Frame parser phase 1, stomp_response.size()==%1%") % stomp_response.size());
			//hexdump(boost::asio::buffer_cast<const char*>(stomp_response.data()), stomp_response.size());
			while (stomp_response.size() > 0) {
				mygetline(stomp_response, _str);
				//hexdump(_str.c_str(), _str.length());
				stomp_response.consume(_str.size() + 1); // plus one for the newline
				if (cmd_map.find(_str) != cmd_map.end()) {
					//debug_print(boost::format("phase 1: COMMAND==%1%, sb.size==%2%") % _str % stomp_response.size());
					m_command = _str;
					break;
				}
			}
			// if after all this trouble m_command is not set, and there's no more data in stomp_response
			// (which shouldn't happen since we do async_read_until the double newline), then throw an exception
			if (m_command == "") throw(NoMoreFrames());

			// STEP 2: parse all headers
			//debug_print("Frame parser phase 2");
			vector< string > header_parts;
			while (stomp_response.size() > 0) {
				mygetline(stomp_response, _str);
				stomp_response.consume(_str.size()+1);
				boost::algorithm::split(header_parts, _str, is_any_of(":"));
				if (header_parts.size() > 1) {
					string& key = decode_header_token(header_parts[0]);
					string& val = decode_header_token(header_parts[1]);
					//debug_print(boost::format("phase 2: HEADER[%1%]==%2%") % key % val);
					m_headers[key] = val;
					//
				} else {
					// no valid header line detected, on to the body scanner
					break;
				}
			}
			//
		} catch(NoMoreFrames& e) {
			//debug_print("-- Frame parser ended (no more frames)");
			throw(e);
		}
  };
Exemplo n.º 2
0
//===========================================================================
void CHttpClient::DoReadHeaders (const boost::system::error_code & err) {
    if (err) {
        printf("%s\n", __FUNCTION__);
        cout<<"Error: "<<err.message()<<endl;
        return;
    }

    istream responseStream(&m_response);
    string header;
    while (getline(responseStream, header) && header != "\r")
        cout<<header<<endl;
    cout<<endl;

    if (m_response.size() > 0)
        cout<<&m_response;

    auto handler = boost::bind(
        &CHttpClient::DoReadContent,
        this,
        boost::asio::placeholders::error
    );
    boost::asio::async_read(
        m_socket,
        m_response,
        boost::asio::transfer_at_least(1),
        handler
    );
}
Exemplo n.º 3
0
static std::string to_string(boost::asio::streambuf& buffer)
{
    boost::asio::streambuf::const_buffers_type bufs = buffer.data();
    std::string data(
        boost::asio::buffers_begin(bufs),
        boost::asio::buffers_begin(bufs) + buffer.size());
    return std::move(data);
}
Exemplo n.º 4
0
void MkvTransfer::stream_header(
    StreamInfo const & info,
    boost::asio::streambuf & buf)
{
    //每添加一个流需要添加一个track_entry
    MkvTrackEntry track_entry;
    track_entry.TrackNumber = info.index + 1;
    std::vector<boost::uint8_t> tem(4, (boost::uint8_t)(info.index + 1));
    track_entry.TrackUID = tem;
    track_entry.Language = "eng";
    if (info.type == MEDIA_TYPE_VIDE) {
        track_entry.TrackType = MkvTrackType::VIDEO;
        track_entry.CodecID = "V_MPEG4/ISO/AVC";
        track_entry.CodecPrivate = info.format_data;
        track_entry.Video.PixelWidth = info.video_format.width;
        track_entry.Video.PixelHeight = info.video_format.height;
        track_entry.Video.Size = track_entry.Video.data_size();
    } else if (info.type == MEDIA_TYPE_AUDI) {
        track_entry.TrackType = MkvTrackType::AUDIO;
        track_entry.CodecID = "A_AAC";
        track_entry.CodecPrivate = info.format_data;
        track_entry.Audio.SamplingFrequency =
            (float)info.audio_format.sample_rate;
        track_entry.Audio.Channels =
            info.audio_format.channel_count;
        //track_entry.Audio.BitDepth =
        //    mediainfoex.audio_format.sample_size * 8;
        track_entry.Audio.Size = track_entry.Audio.data_size();
    } else {
        track_entry.TrackType = MkvTrackType::SUBTITLE;
        track_entry.CodecID = "S_TEXT/UTF-8";
    }

    EBML_DataSizeArchive dsa;
    dsa >> track_entry;

    size_t old_size = buf.size();

    util::archive::BigEndianBinaryOArchive<> oa(buf);
    oa << track_entry;

    assert(old_size + track_entry.byte_size() == buf.size());
}
Exemplo n.º 5
0
void StreamDemuxer::Push(boost::asio::streambuf& stream)
{
	while (stream.size()) {
		if (_packet->Fill(stream)) {
			if (_packet->IsFull()) {
				_downStream->Push(_packet);
				_packet = std::make_shared<LiveViewPacket>();
			}
		}
	}
}
Exemplo n.º 6
0
bool EmptyData::Fill(boost::asio::streambuf& buf)
{
	assert(Size() != UNDEFINED_SIZE);

	uint32_t pos = Pos();
	const uint32_t copyBytes = std::min(buf.size(), Size() - pos);
	buf.consume(copyBytes);
	SetPos(pos + copyBytes);

	return true;
}
Exemplo n.º 7
0
void Dump(boost::asio::streambuf& buf)
{
	std::ofstream ofs("out.dat", std::ios::binary | std::ios::trunc);
	if (!ofs) {
		cout << "dump failed" << endl;
		return;
	}

	cout << "content size:" << buf.size() << endl;
	ofs << &buf;
}
Exemplo n.º 8
0
		void on_recv_(const boost::system::error_code& error, size_t bytes_transferred)
		{
			if(error && error != boost::asio::error::eof) {
				std::cout << "receive failed: " << error.message() << std::endl;
			} else {
				const char* data = asio::buffer_cast<const char*>(recv_.data());
				std::cout << "response(" << bytes_transferred << "): ";
				std::cout << data << std::endl;
				recv_.consume(recv_.size());
				read_trg_ = true;
			}
		}
Exemplo n.º 9
0
  // my own version of getline for an asio streambuf
inline void mygetline (boost::asio::streambuf& sb, string& _str, char delim = '\n') {
	const char* line = boost::asio::buffer_cast<const char*>(sb.data());
	char _c;
	size_t i;
	_str.clear();
	for( i = 0;
		((i < sb.size()) && ((_c = line[i]) != delim));
		i++
	) _str += _c;
	//debug_print( boost::format("mygetline: i=%1%, sb.size()==%2%") % i % sb.size() );
	//hexdump(_str.c_str(), _str.size());
}
Exemplo n.º 10
0
	void run_event_loop_until_frame_received()
	{
		using boost::bind;
		have_frame = false;
		buffer.consume(buffer.size());
		last_error = boost::system::error_code();
		boost::asio::async_read_until(socket,
									  buffer,
									  "END\r\n",
									  bind(&TimedSessionBase::handle_frame_reception,
										   this,
										   boost::asio::placeholders::error,
										   boost::asio::placeholders::bytes_transferred));
		service.reset();
		while (!last_error && !have_frame) {
			service.poll();
			service.reset();
			check_if_timed_out();
		}
	}
Exemplo n.º 11
0
 size_t size() {
     return streambuf.size();
 }