• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ asio::streambuf类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中boost::asio::streambuf的典型用法代码示例。如果您正苦于以下问题:C++ streambuf类的具体用法?C++ streambuf怎么用?C++ streambuf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了streambuf类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: parse_body

  // STEP 3: parse the body
  size_t Frame::parse_body(boost::asio::streambuf& _response)
  {
	  std::size_t _content_length = 0, bytecount = 0;
	  string _str;
	//debug_print("Frame parser phase 3");
	// special case: content-length
	if (m_headers.find("content-length") != m_headers.end()) {
		string& val = m_headers["content-length"];
		//debug_print(boost::format("phase 3: body content-length==%1%") % val);
		_content_length = lexical_cast<size_t>(val);
	}
	if (_content_length > 0) {
		bytecount += _content_length;
		// read back the body byte by byte
		const char* rawdata = boost::asio::buffer_cast<const char*>(_response.data());
		for (size_t i = 0; i < _content_length; i++ ) {
			m_body << rawdata[i];
		}
	} else {
		// read all bytes until the first NULL
		mygetline(_response, _str, '\0');
		bytecount += _str.size();
		m_body << _str;
	}
	bytecount += 1; // for the final frame-terminating NULL
	//debug_print(boost::format("phase 3: consumed %1% bytes, BODY(%2% bytes)==%3%") % bytecount % _str.size() % _str);
	_response.consume(bytecount);
	return(bytecount);
  }
开发者ID:RemcoTukker,项目名称:BoostStomp,代码行数:30,代码来源:StompFrame.cpp


示例2: to_string

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);
}
开发者ID:Wang-OuYang,项目名称:xxsocket,代码行数:8,代码来源:connection.cpp


示例3: Fill

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;
}
开发者ID:hamling-ling,项目名称:KirinCam,代码行数:11,代码来源:EmptyData.cpp


示例4: mygetline

  // 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());
}
开发者ID:RemcoTukker,项目名称:BoostStomp,代码行数:13,代码来源:StompFrame.cpp


示例5: handle_line

    void handle_line(const boost::system::error_code& error, size_t bytes_received) {
        if(!error) {
            boost::asio::streambuf::const_buffers_type bufs = m_buffer.data();
            std::string line(boost::asio::buffers_begin(bufs),
                             boost::asio::buffers_begin(bufs) + bytes_received);

            std::cerr << "Sentence: " << line << std::endl;

            m_buffer.consume(bytes_received);

            read_next();
        } else {
            std::cerr << "Error: " << error << std::endl;
        }
    }
开发者ID:promovicz,项目名称:garmin-radar,代码行数:15,代码来源:garmin.cpp


示例6: catch

  // 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);
		}
  };
开发者ID:RemcoTukker,项目名称:BoostStomp,代码行数:50,代码来源:StompFrame.cpp


示例7: make_string

/// @brief Helper function that extracts a string from a streambuf.
std::string make_string(
  boost::asio::streambuf& streambuf,
  std::size_t n)
{
  return std::string(buffers_begin(streambuf.data()),
                     buffers_begin(streambuf.data()) + n);
}
开发者ID:CCJY,项目名称:coliru,代码行数:8,代码来源:main.cpp


示例8: parse

		/// Parse some data. The enum return value is good when a complete request has
		/// been parsed, bad if the data is invalid, indeterminate when more data is
		/// required. The InputIterator return value indicates how much of the input
		/// has been consumed.
		result_type parse(boost::asio::streambuf& buf)
		{
			int c = EOF;
			while ((c = buf.sbumpc()) != EOF)
			{
				result_type result = consume(c);
				if (result == good || result == bad)
				{
					std::string url = urldecode(url_);
					std::string::size_type qmak_pos = url.find("?");
					if (qmak_pos == std::string::npos)
					{
						path_ = url;
					}
					else
					{
						path_ = url.substr(0, qmak_pos);
						std::string quert_str = url.substr(qmak_pos + 1, url.size());
						query_ = query_parser(quert_str);
					}
					return result;
				}
			}
			return indeterminate;
		}
开发者ID:archerbroler,项目名称:cinatra,代码行数:29,代码来源:request_parser.hpp


示例9: read_some

 size_t read_some( AsyncReadStream& s, boost::asio::streambuf& buf )
 {
     char buffer[1024];
     size_t bytes_read = read_some( s, boost::asio::buffer( buffer, sizeof(buffer) ) );
     buf.sputn( buffer, bytes_read );
     return bytes_read;
 }
开发者ID:FollowMyVote,项目名称:fc,代码行数:7,代码来源:asio.hpp


示例10: log_request_helper

std::string log_request_helper(const boost::asio::streambuf& buf)
{
    boost::asio::const_buffers_1 b = static_cast<boost::asio::const_buffers_1>(buf.data());
    boost::iterator_range<const char*> ib(buffer_cast<const char*>(b),
            buffer_cast<const char*>(b) + buffer_size(b));
    return string(ib.begin(), ib.end());
}
开发者ID:alexeimoisseev,项目名称:NwSMTP,代码行数:7,代码来源:smtp_client.cpp


示例11: Fill

bool ConstByte::Fill(boost::asio::streambuf& buf)
{
	const char* cp = boost::asio::buffer_cast<const char*>(buf.data());
	if (static_cast<const char>(_expectedValue) != *cp) {
		return false;
	}
	return FixedSizeData<1>::Fill(buf);
}
开发者ID:hamling-ling,项目名称:KirinCam,代码行数:8,代码来源:ConstByte.cpp


示例12: stream_header

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());
}
开发者ID:uvbs,项目名称:MyProjects,代码行数:43,代码来源:MkvTransfer.cpp


示例13: Push

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>();
			}
		}
	}
}
开发者ID:hamling-ling,项目名称:KirinCam,代码行数:11,代码来源:StreamDemuxer.cpp


示例14: Dump

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;
}
开发者ID:hamling-ling,项目名称:KirinCam,代码行数:11,代码来源:StreamDump.cpp


示例15: async_fetch_cface_std_saver

void webqq::async_fetch_cface_std_saver( boost::system::error_code ec, boost::asio::streambuf& buf, std::string cface, boost::filesystem::path parent_path)
{
	if (!fs::exists(parent_path)){
		fs::create_directories(parent_path);
	}

	if (!ec || ec == boost::asio::error::eof){
		std::string imgfilename = (parent_path / cface).string();
		std::ofstream cfaceimg(imgfilename.c_str(), std::ofstream::binary|std::ofstream::out);
		cfaceimg.write(boost::asio::buffer_cast<const char*>(buf.data()), boost::asio::buffer_size(buf.data()));
	}
}
开发者ID:buaagg,项目名称:avbot,代码行数:12,代码来源:webqq.cpp


示例16: operator

	void operator()( boost::system::error_code ec, boost::asio::streambuf & buf, std::string cface )
	{
 		using namespace boost::asio::detail;

		if( !ec || ec == boost::asio::error::eof )
		{
			std::ofstream cfaceimg( ( std::string( "images/" ) + cface ).c_str(), std::ofstream::openmode(std::ofstream::binary | std::ofstream::out) );
			cfaceimg.write( boost::asio::buffer_cast<const char*>( buf.data() ), boost::asio::buffer_size( buf.data() ) );
			ec = boost::system::error_code();
		}

		io_service.post( bind_handler( handler, ec));
	}
开发者ID:HackLinux,项目名称:avbot,代码行数:13,代码来源:async_image_checker.hpp


示例17: proto_get_one_package

int proto_get_one_package(tcp::socket *socket, boost::asio::streambuf &buff,
                          boost::uint8_t *packet_no)
{
  unsigned long packet_length;
  if (proto_read_package_header(socket, buff, &packet_length, packet_no))
    return 0;
  std::streamsize inbuffer= buff.in_avail();
  if (inbuffer < 0)
    inbuffer= 0;
  if (packet_length > inbuffer)
    boost::asio::read(*socket, buff,
                      boost::asio::transfer_at_least(packet_length-inbuffer));

  return packet_length;
}
开发者ID:MassimilianoPinto,项目名称:MaxScale,代码行数:15,代码来源:protocol.cpp


示例18: parse_rc_response

boost::optional<rc_result> parse_rc_response(const boost::asio::streambuf& buf)
{
    typedef boost::asio::streambuf::const_buffers_type const_buffers_type;
    typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
    const_buffers_type buffers = buf.data();
    iterator begin = iterator::begin(buffers);
    iterator end = iterator::end(buffers);

    // Look for the start of the body of the response
    boost::iterator_range<const char*> delim = boost::as_literal("\r\n\r\n");
    std::pair<iterator, bool> result = boost::asio::detail::partial_search(
        begin, end, delim.begin(), delim.end());
    if (result.first != end && result.second)
    {
        iterator start = result.first + delim.size();

        // Skip a line
        delim = boost::as_literal("\r\n");
        result = boost::asio::detail::partial_search(start, end,
                delim.begin(), delim.end());
        if (result.first != end && result.second)
        {
            // todo: we can optimise parsing here
            std::string d;
            start = result.first + delim.size();
            std::copy(start, end, std::back_inserter(d));

            rc_result res;
            try
            {
                std::istringstream iss(d);
                iss >> res.ok;
                iss >> res.sum1;
                iss >> res.sum2;
                iss >> res.sum3;
                iss >> res.sum4;
            }
            catch (...)
            {
                return boost::optional<rc_result>();
            }

            return boost::optional<rc_result>(res);
        }
开发者ID:alexeimoisseev,项目名称:NwSMTP,代码行数:44,代码来源:atormoz.cpp


示例19: size

 size_t size() {
     return streambuf.size();
 }
开发者ID:0x1abin,项目名称:Simple-WebSocket-Server,代码行数:3,代码来源:server_ws.hpp


示例20: make_string

/// @brief Convert a streambuf to a string.
std::string make_string(boost::asio::streambuf& streambuf)
{
  return std::string(buffers_begin(streambuf.data()),
                     buffers_end(streambuf.data()));
}
开发者ID:CCJY,项目名称:coliru,代码行数:6,代码来源:main.cpp



注:本文中的boost::asio::streambuf类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ io_service::strand类代码示例发布时间:2022-05-31
下一篇:
C++ asio::io_service类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap