<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>奋斗 &#187; boost</title>
	<atom:link href="http://fangfangtu.com/blog/tag/boost/feed/" rel="self" type="application/rss+xml" />
	<link>http://fangfangtu.com/blog</link>
	<description>生命在于折腾</description>
	<lastBuildDate>Wed, 01 Feb 2012 06:01:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>boost::asio::async_read 的一些记录</title>
		<link>http://fangfangtu.com/blog/2009/12/async_read-memo/</link>
		<comments>http://fangfangtu.com/blog/2009/12/async_read-memo/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 13:12:12 +0000</pubDate>
		<dc:creator>bborn</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[网络]]></category>

		<guid isPermaLink="false">http://fangfangtu.com/blog/?p=795</guid>
		<description><![CDATA[boost中的asio是一个非常好用的网络库 不过可以参考的资料比较少 大部分都是靠阅读自带的几个example来理解 这里记录一下这两天的几个心得 boost::asio::async_read_until(socket_, response_, “\r\n\r\n”, boost::bind(&#038;shoutcast::handle_read_headers, this, boost::asio::placeholders::error)); async_read_until, 一直读,直到读到指定的内容.但是了,并不是刚刚读到就停止,一般缓冲区里会有更多的内容, 所以我们需要读出我们需要的,剩下的留下就好 官方是这么说的”After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.” boost::asio::async_read(socket_, response_, boost::asio::transfer_at_least(512), boost::bind(&#038;shoutcast::handle_read_content, this, boost::asio::placeholders::error)); async_read 可以选择使用transfer_at_least 这个CompletionCondition async_read 读入的缓冲区可以这样 [...]]]></description>
			<content:encoded><![CDATA[<p>boost中的asio是一个非常好用的网络库<br />
不过可以参考的资料比较少<br />
大部分都是靠阅读自带的几个example来理解<br />
这里记录一下这两天的几个心得</p>
<blockquote><p>boost::asio::async_read_until(socket_, response_,  “\r\n\r\n”, boost::bind(&#038;shoutcast::handle_read_headers, this, boost::asio::placeholders::error));</p></blockquote>
<p>async_read_until, 一直读,直到读到指定的内容.但是了,并不是刚刚读到就停止,一般缓冲区里会有更多的内容,<br />
所以我们需要读出我们需要的,剩下的留下就好<br />
官方是这么说的”After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.”</p>
<blockquote><p>boost::asio::async_read(socket_, response_, boost::asio::transfer_at_least(512), boost::bind(&#038;shoutcast::handle_read_content, this, boost::asio::placeholders::error));</p></blockquote>
<p>async_read 可以选择使用transfer_at_least 这个CompletionCondition<br />
async_read 读入的缓冲区可以这样<br />
boost::array<char, 8192> buffer_;<br />
boost::asio::buffer(buffer_);来构造<br />
也可以直接用字符数组来构造<br />
char _buf[512] = {0};<br />
boost::asio::buffer(_buf, 512);<br />
也可以用流,更像tcp的方式<br />
使用boost::asio::streambuf response_;<br />
它继承自 std::streambuf<br />
一般这样使用<br />
std::istream _stream(&#038;response_);<br />
这里要注意的是 basic_istream::get<br />
如果我们指定get的个数count,那么取出的个数是count-1<br />
msdn是这样说的”The fourth function extracts up to _Count &#8211; 1 elements and stores them in the array beginning at _Str.”</p>
<h3  class="related_post_title">可能相关</h3><ul class="related_post"><li>2005-09-08 -- <a href="http://fangfangtu.com/blog/2005/09/net-hust/" title="终于可以上网了">终于可以上网了</a></li><li>2005-08-31 -- <a href="http://fangfangtu.com/blog/2005/08/opera-ten-years/" title="opera 十年">opera 十年</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://fangfangtu.com/blog/2009/12/async_read-memo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

