锘??xml version="1.0" encoding="utf-8" standalone="yes"?>免费无码国产欧美久久18,精品久久久无码人妻中文字幕,久久精品国产亚洲av麻豆蜜芽http://www.shnenglu.com/ngaut/category/8573.htmlasm/c/c++/......zh-cnWed, 13 Jun 2012 03:56:28 GMTWed, 13 Jun 2012 03:56:28 GMT60[杞琞 C++鎵洸緋誨垪--絎竴涓湇鍔″櫒紼嬪簭http://www.shnenglu.com/ngaut/archive/2009/09/06/95406.htmlngautngautSun, 06 Sep 2009 03:26:00 GMThttp://www.shnenglu.com/ngaut/archive/2009/09/06/95406.htmlhttp://www.shnenglu.com/ngaut/comments/95406.htmlhttp://www.shnenglu.com/ngaut/archive/2009/09/06/95406.html#Feedback0http://www.shnenglu.com/ngaut/comments/commentRss/95406.htmlhttp://www.shnenglu.com/ngaut/services/trackbacks/95406.html闃呰鍏ㄦ枃

ngaut 2009-09-06 11:26 鍙戣〃璇勮
]]>
asio宸ョ▼鍚慴oost.asio杞崲娉ㄦ剰浜嬮」http://www.shnenglu.com/ngaut/archive/2008/10/21/64602.htmlngautngautTue, 21 Oct 2008 03:50:00 GMThttp://www.shnenglu.com/ngaut/archive/2008/10/21/64602.htmlhttp://www.shnenglu.com/ngaut/comments/64602.htmlhttp://www.shnenglu.com/ngaut/archive/2008/10/21/64602.html#Feedback0http://www.shnenglu.com/ngaut/comments/commentRss/64602.htmlhttp://www.shnenglu.com/ngaut/services/trackbacks/64602.htmlWhat are the differences in the source code?

鈥?Asio is in a namespace called asio::, whereas Boost.Asio puts everything under boost::asio::.

鈥?The main Asio header file is called asio.hpp. The corresponding header in Boost.Asio is boost/asio.hpp. All other headers are similarly changed.

鈥?Any macros used by or defined in Asio are prefixed with ASIO_. In Boost.Asio they are prefixed with BOOST_ASIO_.

鈥?Asio includes a class for launching threads, asio::thread. Boost.Asio does not include this class, to avoid overlap with the Boost.Thread library

鈥?Boost.Asio uses the Boost.System library to provide support for error codes (boost::system::error_code and boost::system::system_error). Asio includes these under its own namespace (asio::error_code and asio::system_error). The Boost.System version of these classes currently supports better extensibility for user-defined error codes. 闇瑕佸寘鍚?lt;boost/system/system_error.hpp> 澶存枃浠?/p>

鈥?Asio is header-file-only and for most uses does not require linking against any Boost library. Boost.Asio always requires that you link against the Boost.System library, and also against Boost.Thread if you want to launch threads using boost::thread.闇瑕佸寘鍚?lt;boost/thread.hpp>



ngaut 2008-10-21 11:50 鍙戣〃璇勮
]]>
asio緇堜簬闅廱oost涓璧峰彂甯冧簡http://www.shnenglu.com/ngaut/archive/2008/04/01/45940.htmlngautngautTue, 01 Apr 2008 10:46:00 GMThttp://www.shnenglu.com/ngaut/archive/2008/04/01/45940.htmlhttp://www.shnenglu.com/ngaut/comments/45940.htmlhttp://www.shnenglu.com/ngaut/archive/2008/04/01/45940.html#Feedback4http://www.shnenglu.com/ngaut/comments/commentRss/45940.htmlhttp://www.shnenglu.com/ngaut/services/trackbacks/45940.html闃呰鍏ㄦ枃

ngaut 2008-04-01 18:46 鍙戣〃璇勮
]]>
asio:濡備綍姝g‘鍏抽棴sockethttp://www.shnenglu.com/ngaut/archive/2008/02/22/43102.htmlngautngautFri, 22 Feb 2008 11:31:00 GMThttp://www.shnenglu.com/ngaut/archive/2008/02/22/43102.htmlhttp://www.shnenglu.com/ngaut/comments/43102.htmlhttp://www.shnenglu.com/ngaut/archive/2008/02/22/43102.html#Feedback0http://www.shnenglu.com/ngaut/comments/commentRss/43102.htmlhttp://www.shnenglu.com/ngaut/services/trackbacks/43102.html> 1. In what situation we need to use both
> "basic_stream_socket::shutdown()" & "basic_stream_socket::close()"
> functions?

If you want graceful closure of the socket, and you want it to work
consistently on Windows, use shutdown() before close(). There are
circumstances where just calling close() can result in the Windows TCP
stack sending a RST to the peer, which means possible data loss (i.e.
anything but a graceful closure).

> 2. In what situation we need to use just "basic_stream_socket::close()"
> function?

When you just want to close the connection as soon as possible and don't
care about possible loss of data under Windows.



ngaut 2008-02-22 19:31 鍙戣〃璇勮
]]>
浣跨敤asio闇瑕佹敞鎰忕殑涓や釜闂http://www.shnenglu.com/ngaut/archive/2008/02/14/42745.htmlngautngautThu, 14 Feb 2008 13:52:00 GMThttp://www.shnenglu.com/ngaut/archive/2008/02/14/42745.htmlhttp://www.shnenglu.com/ngaut/comments/42745.htmlhttp://www.shnenglu.com/ngaut/archive/2008/02/14/42745.html#Feedback0http://www.shnenglu.com/ngaut/comments/commentRss/42745.htmlhttp://www.shnenglu.com/ngaut/services/trackbacks/42745.htmlDate: Wed, 6 Feb 2008 23:43:09 -0000
From: "Roger Austin" <Roger@wallingfordsoftware.com>
Subject: Re: [asio-users] asio::async_write & WriteHander
To: <asio-users@lists.sourceforge.net>
Message-ID:
<0CEE50132F7DB142AA8632D6FB1BE982E7E462@bob.internal.wallingfordsoftware.co.uk>

Content-Type: text/plain; charset="us-ascii"

If there is ever an asio FAQ, the correct use of async_write will be at
the top of the list



Cliff is correct in what he says but the key clause is "when the first
async_write completes". If you start your second async_write before the
first has completed, you risk interleaving the data. Thus if you want to
write code like:



DoAsyncWrite("Message 1");

DoAsyncWrite("Message 2");



Then your implementation of DoAsyncWrite (which will call async_write
internally) must check if there is already an async_write pending and,
if so, put the message somewhere (i.e. in a queue), ready to be sent
when the pending async_write has completed. The asio chat example does
this.



This is not a limitation of asio as such. The underlying socket
functions (send or equivalent) make no guarantee that the entire message
can be transferred to the TCP stream in a single asynchronous operation
- the write handler will be told how many bytes were actually
transferred and the application is responsible for issuing a new call to
send the remaining bytes. The asio async_write function does this for
you via one or more calls to async_write_some, but in doing so it tends
to hide the fact that the second and later calls to async_write_some
(needed to complete sending the first message) may happen later in the
thread than the first call to async_write_some for the second message.





From: asio-users-bounces@lists.sourceforge.net
[mailto:asio-users-bounces@lists.sourceforge.net] On Behalf Of X Wang
Sent: Thursday, 7 February 2008 9:37 AM
To: asio-users@lists.sourceforge.net
Subject: Re: [asio-users] asio::async_write & WriteHander





"Green, Cliff" <cliff.green@boeing.com> wrote:

> Sender sends out 2 messages back to back (on the same end-to-end
socket
> connection), message 1 is 10 MB, message 2 is 10 bytes, with no
receiver
> ACK in between.

Assuming the two messages are generated in order (e.g. in a single
thread), there is not an issue - one async_write of 10 MB, followed by
an async_write of 10 bytes (when the first async_write completes). Since
the actual "buffer" passed to Asio async_write does not copy the 10 MB /
10 b, you will need to manage the lifetime of the two original message
buffers. If the "message generation" is completely independent of the
thread invoking the async_writes, you need to manage the coordination
(this could be a queue, as previously mentioned, or some other form of
coordination).

You will be guaranteed that the data gets to the receiver in the same
order - 10 MB followed by 10 b (however, the receiver will need to take
responsibility for the message delimiter handling).

Am I missing something?

(Asio experts, please correct any of my mistakes on the Asio aspects.)

Much of this explanation is not dependent on async concepts and designs
- it would need to be similar whether your app is blocking, non-blocking
(polling), non-blocking (reactive), multi-threaded, etc.

Cliff

------------------------------------------------------------------------
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
asio-users mailing list
asio-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users


Yeah, you are right. What I said about TCP did not make much sense...
need some coffee :)


ngaut 2008-02-14 21:52 鍙戣〃璇勮
]]>
asio浣滆呭啓鐨勫ソ涓滀笢,涓嶅閿欒繃鍝?/title><link>http://www.shnenglu.com/ngaut/archive/2007/12/28/39863.html</link><dc:creator>ngaut</dc:creator><author>ngaut</author><pubDate>Fri, 28 Dec 2007 12:43:00 GMT</pubDate><guid>http://www.shnenglu.com/ngaut/archive/2007/12/28/39863.html</guid><wfw:comment>http://www.shnenglu.com/ngaut/comments/39863.html</wfw:comment><comments>http://www.shnenglu.com/ngaut/archive/2007/12/28/39863.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/ngaut/comments/commentRss/39863.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/ngaut/services/trackbacks/39863.html</trackback:ping><description><![CDATA[<h2 class=date-header>Wednesday, August 08, 2007</h2> <div id="rt1n9rp" class="post hentry uncustomized-post-template"><a name=9091214669274461484></a> <h3 class="post-title entry-title"><a ><u><font color=#0000ff>Time Travel</font></u></a> </h3> <div id="pplzdlv" class=post-header-line-1></div> <div id="hr9vlhd" class="post-body entry-content"> <p>Many event-driven programs involve state changes that are triggered according to the system clock. You might be coding for: <ul><br> <li>A share market that opens at 10:00am and closes at 4:00pm.<br> <li>An off-peak phone billing rate that starts after 7:00pm.<br> <li>An interest calculation that is run on the last day of every month.<br></li> </ul> The <code>asio::deadline_timer</code> class lets you handle this easily. For example:<br> <pre>using namespace boost::posix_time;<br>typedef boost::date_time::c_local_adjustor<ptime> local_adj;<br><br>...<br><br>asio::deadline_timer timer(io_service);<br><br>ptime open_time(second_clock::local_time().date(), hours(10));<br>timer.expires_at(local_adj::local_to_utc(open_time));<br>timer.async_wait(open_market);<br></pre> There's a catch: to test that your timer events work correctly, you have to run your program at the right time of day. It usually isn't practical to sit around all day (or, worse, all year) waiting for the timers to expire.<br><br> <h3>Time Traits</h3> <br>You may have noticed that the <code>asio::deadline_timer</code> class is actually a typedef:<br> <pre>typedef basic_deadline_timer<boost::posix_time::ptime><br> deadline_timer;</pre> where the basic_deadline_timer class template is declared as follows:<br> <pre>template <<br> typename Time,<br> typename TimeTraits<br> = asio::time_traits<Time>,<br> typename TimerService<br> = deadline_timer_service<Time, TimeTraits> ><br>class basic_deadline_timer;<br></pre> In the context of our problem, the most interesting template parameter is the second one: <code>TimeTraits</code>. An implementation of <code>TimeTraits</code> lets us customise the treatment of the template's <code>Time</code> parameter, and consequently the behaviour of the timer itself.<br><br>A <code>TimeTraits</code> class must implement an interface that matches the following:<br> <pre>class TimeTraits<br>{<br>public:<br> // The type used to represent an absolute time, i.e. the same<br> // as the Time template parameter to basic_deadline_timer.<br> typedef ... time_type;<br><br> // The type used to represent the difference between two<br> // absolute times.<br> typedef ... duration_type;<br><br> // Returns the current time.<br> static time_type now();<br><br> // Returns a new absolute time resulting from adding the<br> // duration d to the absolute time t.<br> static time_type add(time_type t, duration_type d);<br><br> // Returns the duration resulting from subtracting t2 from t1.<br> static duration_type subtract(time_type t1, time_type t2);<br><br> // Returns whether t1 is to be treated as less than t2.<br> static bool less_than(time_type t1, time_type t2);<br><br> // Returns a "posix" duration corresponding to the duration d.<br> static boost::posix_time::time_duration to_posix_duration(<br> duration_type d);<br>};</pre> As you can see from the declaration of the <code>basic_deadline_timer</code> class template, Asio provides a default <code>TimeTraits</code> implementation called <code>asio::time_traits<></code>.<br><br> <h3>Offsetting Now</h3> <br>To test our timer events at any time of our choosing, we simply need to change the definition of "now" using a custom <code>TimeTraits</code> class.<br><br>Since we want to use the same time types as the regular <code>deadline_timer</code> class, we'll start by reusing the default traits implementation:<br> <pre>class offset_time_traits<br> : public asio::deadline_timer::traits_type<br>{<br>};</pre> The value returned by the <code>now()</code> function will be offset from the system clock by a specified duration:<br> <pre>class offset_time_traits<br> : public asio::deadline_timer::traits_type<br>{<br><br>private:<br> <font color=red>static duration_type offset_;</font><br>};</pre> which is simply added to the system clock:<br> <pre>class offset_time_traits<br> : public asio::deadline_timer::traits_type<br>{<br>public:<br> <font color=red>static time_type now()<br> {<br> return add(asio::deadline_timer::traits_type::now(), offset_);<br> }</font><br><br>private:<br> static duration_type offset_;<br>};</pre> Of course, we will also need to provide a way to set the offset, which can be done by setting an initial value for "now":<br> <pre>class offset_time_traits<br> : public asio::deadline_timer::traits_type<br>{<br>public:<br> static time_type now()<br> {<br> return add(asio::deadline_timer::traits_type::now(), offset_);<br> }<br><br> <font color=red>static void set_now(time_type t)<br> {<br> offset_ =<br> subtract(t, asio::deadline_timer::traits_type::now());<br> }</font><br><br>private:<br> static duration_type offset_;<br>};</pre> <br> <h3>Creating a Timer</h3> <br>To use our custom traits type with the <code>basic_deadline_timer</code> template, we simply need to add the following typedef:<br> <pre>typedef asio::basic_deadline_timer<<br> boost::posix_time::ptime, offset_time_traits> offset_timer;</pre> To see the offset timer in action, let's create a timer to fire precisely at the start of the coming new year. So we don't have to wait until then, we'll set "now" to be just ten seconds prior to midnight:<br> <pre>offset_time_traits::set_now(<br> boost::posix_time::from_iso_string("20071231T235950"));<br><br>offset_timer timer(io_service);<br>timer.expires_at(<br> boost::posix_time::from_iso_string("20080101T000000"));<br>timer.async_wait(handle_timeout);<br><br>io_service.run();</pre> When the program is run, it will take just ten seconds to complete.<br><br> <h3>Jumping Through Time</h3> <br>One feature not supported by the above solution is the ability to change the definition of "now" after the timers have been started. However, if your timer events are spread across a long period of time, then this is likely to be something you would want.<br><br>Let's say that the next timer does not expire for several hours, but in an attempt to speed things up we call <code>set_now()</code> to move to just seconds before. The problem with the above traits class is that the existing asynchronous wait operation does not know about the change to "now", and so will continue to run for the remaining hours.<br><br>Fortunately, Asio provides a way around this: by customising the <code>to_posix_duration()</code> function in our traits class.<br><br>The <code>to_posix_duration()</code> function is normally used to convert from a user-defined duration type to a type that Asio knows about (namely <code>boost::posix_time::time_duration</code>). The key point here is that this converted duration value is used by Asio to determine how long to wait until the timer expires. Furthermore, it doesn't matter if this function returns a duration that is smaller (even substantially so) than the actual duration. The timer won't fire early, because Asio guarantees that it won't expire until the following condition holds true:<br> <pre>!TimeTraits::less_than(Time_Traits::now(), timer.expires_at())</pre> So, by adding the <code>to_posix_duration()</code> function to our traits class:<br> <pre>class offset_time_traits<br> : public asio::deadline_timer::traits_type<br>{<br>public:<br> static time_type now()<br> {<br> return add(asio::deadline_timer::traits_type::now(), offset_);<br> }<br><br> static void set_now(time_type t)<br> {<br> offset_ =<br> subtract(t, asio::deadline_timer::traits_type::now());<br> }<br><br> <font color=red>static boost::posix_time::time_duration to_posix_duration(<br> duration_type d)<br> {<br> return d < boost::posix_time::seconds(5)<br> ? d : boost::posix_time::seconds(5);<br> }</font><br><br>private:<br> static duration_type offset_;<br>};</pre> we can ensure that Asio detects changes to the offset within seconds. <p> </p> <div style="CLEAR: both"></div> </div> <div id="hxr7xrx" class=post-footer> <p class="post-footer-line post-footer-line-1"><span id="lvvbllj" class="post-author vcard">Posted by <span id="nnxxtpr" class=fn>chris</span> </span><span id="jjhhxpf" class=post-timestamp>at <a class=timestamp-link title="permanent link" rel=bookmark><abbr class=published title=2007-08-08T23:00:00+10:00><u><font color=#0000ff>11:00 PM</abbr></font></u></a> </span><span id="d9dbzxx" class=post-comment-link><a class=comment-link onclick="" ><u><font color=#0000ff>1 comments</font></u></a> </span><span id="zddbjhr" class="post-backlinks post-comment-link"></span><span id="tttblbt" class=post-icons><span id="9vzrbjr" class="item-control blog-admin pid-660467121"><a title="Edit Post" ><u><font color=#0000ff><span id="bjhffnx" class=quick-edit-icon> </span> </font></u></a></span></span></p> <p class="post-footer-line post-footer-line-2"><span id="prrjjr9" class=post-labels>Labels: <a rel=tag><u><font color=#0000ff>asio</font></u></a>, <a rel=tag><u><font color=#0000ff>boost</font></u></a>, <a rel=tag><u><font color=#0000ff>timer</font></u></a> </span></p> <p class="post-footer-line post-footer-line-3"></p> </div> </div> <h2 class=date-header>Thursday, April 26, 2007</h2> <div id="lvv7fv1" class="post hentry uncustomized-post-template"><a name=7236229129837214596></a> <h3 class="post-title entry-title"><a ><u><font color=#0000ff>New home heating solution</font></u></a> </h3> <div id="lxp7vvl" class=post-header-line-1></div> <div id="vtl7fn7" class="post-body entry-content"> <p>For quite some time I have wanted to take a really good look at improving Boost.Asio's scalability across multiple processors. Unfortunately, getting unlimited access to this sort of hardware has been somewhat problematic. What I really needed was a decent multiprocessor box at home :)<br><br>The arrival of Intel's Clovertown quad core CPUs gave me the opportunity. The primary goal was to maximise parallelism while minimising the cost, and the lowest spec quad cores were cheap enough for me to justify spending the money. So, after months of <strong style="COLOR: black; BACKGROUND-COLOR: #ffff66">thinking</strong> (and weeks of waiting for parts), last week I finally completed my home-built server.<br><br>Here are the headline specs: <ul><br> <li>Two Intel Xeon E5310 quad core processors (1.6 GHz)<br><br> <li>Tyan Tempest i5000XL motherboard<br><br> <li>2GB DDR2-667 fully buffered ECC DIMMs<br><br> <li>OCZ GameXStream 700W power supply (OK, OK, it's a little overpowered, but it was in stock!)<br><br> <li>Other stuff like case, hard disk, DVD drive, video card and wireless LAN card<br><br> <li>Lots of fans to provide soothing ambient noise<br><br></li> </ul> So far I have installed CentOS Linux 5 on it, but also plan to try Solaris 10 and FreeBSD. It seems pretty snappy. <p> </p> <div style="CLEAR: both"></div> </div> <div id="zrr1dr3" class=post-footer> <p class="post-footer-line post-footer-line-1"><span id="hr9b9ft" class="post-author vcard">Posted by <span id="h9bldlv" class=fn>chris</span> </span><span id="9dvfxhh" class=post-timestamp>at <a class=timestamp-link title="permanent link" rel=bookmark><abbr class=published title=2007-04-26T23:57:00+10:00><u><font color=#0000ff>11:57 PM</abbr></font></u></a> </span><span id="lnn19rb" class=post-comment-link><a class=comment-link onclick="" ><u><font color=#0000ff>2 comments</font></u></a> </span><span id="fxppxhf" class="post-backlinks post-comment-link"></span><span id="hphrlt9" class=post-icons><span id="tjhzph7" class="item-control blog-admin pid-660467121"><a title="Edit Post" ><u><font color=#0000ff><span id="vld9llj" class=quick-edit-icon> </span> </font></u></a></span></span></p> <p class="post-footer-line post-footer-line-2"><span id="l9lvj7l" class=post-labels>Labels: <a rel=tag><u><font color=#0000ff>asio</font></u></a>, <a rel=tag><u><font color=#0000ff>boost</font></u></a>, <a rel=tag><u><font color=#0000ff>hardware</font></u></a> </span></p> <p class="post-footer-line post-footer-line-3"></p> </div> </div> <h2 class=date-header>Monday, January 15, 2007</h2> <div id="9xfzj7h" class="post hentry uncustomized-post-template"><a name=993190014642551346></a> <h3 class="post-title entry-title"><a ><u><font color=#0000ff>Unbuffered socket iostreams</font></u></a> </h3> <div id="jttltfp" class=post-header-line-1></div> <div id="ld7jlfv" class="post-body entry-content"> <p>Boost.Asio includes an iostreams-based interface to TCP sockets, <code>ip::tcp::iostream</code>, for simple use cases. However, like the file iostreams provided by the standard library, <code>ip::tcp::iostream</code> buffers input and output data. This can lead to problems if you forget to explicitly flush the stream. For example, consider the following code to perform an HTTP request:<br> <pre>ip::tcp::iostream stream("www.boost.org", "http");<br>stream << "GET / HTTP/1.0\r\n"<br> << "Host: www.boost.org\r\n"<br> << "\r\n";<br><br>std::string response_line;<br>std::getline(stream, response_line);<br>...</pre> The code will be stuck on the <code>getline()</code> call waiting for the response, because the request will still be sitting <code>stream</code>'s output buffer. The correct code looks like this:<br> <pre>ip::tcp::iostream stream("www.boost.org", "http");<br>stream << "GET / HTTP/1.0\r\n"<br> << "Host: www.boost.org\r\n"<br> << "\r\n"<br> <font color=red><< std::flush</font>;</pre> The <code>std::flush</code> will cause the stream to send the entire contents of its output buffer at that point.<br><br>Boost.Asio now supports an alternative solution: turn off the stream's output buffering. This is accomplished as follows:<br> <pre>ip::tcp::iostream stream("www.boost.org", "http");<br><font color=red>stream.rdbuf()->pubsetbuf(0, 0);</font><br>stream << "GET / HTTP/1.0\r\n"<br> << "Host: www.boost.org\r\n"<br> << "\r\n";</pre> Now you can send and receive to your heart's content, without having to worry about whether your message is stuck in the output buffer, but be warned: an unbuffered stream is a lot less efficient in terms of system calls. Don't use this feature if you care about performance.</div> </div> <img src ="http://www.shnenglu.com/ngaut/aggbug/39863.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/ngaut/" target="_blank">ngaut</a> 2007-12-28 20:43 <a href="http://www.shnenglu.com/ngaut/archive/2007/12/28/39863.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[杞琞asio Buffer debugging http://www.shnenglu.com/ngaut/archive/2007/12/28/39862.htmlngautngautFri, 28 Dec 2007 12:40:00 GMThttp://www.shnenglu.com/ngaut/archive/2007/12/28/39862.htmlhttp://www.shnenglu.com/ngaut/comments/39862.htmlhttp://www.shnenglu.com/ngaut/archive/2007/12/28/39862.html#Feedback0http://www.shnenglu.com/ngaut/comments/commentRss/39862.htmlhttp://www.shnenglu.com/ngaut/services/trackbacks/39862.htmlFriday, November 10, 2006

Buffer debugging

Some standard library implementations, such as the one that ships with MSVC 8.0, provide a nifty feature called iterator debugging. What this means is that the validity of your iterators is checked at runtime. If you try to use an iterator that has been invalidated, you'll get an assertion. For example:

std::vector<int> v(1)
std::vector<int>::iterator i = v.begin();
v.clear(); // invalidates iterators
*i = 0; // assertion!
Boost.Asio now takes advantage of this feature to add buffer debugging. Consider the following code:
void dont_do_this()
{
std::string msg = "Hello, world!";
asio::async_write(sock, asio::buffer(msg), my_handler);
}
When you call an asynchronous read or write you need to ensure that the buffers for the operation are valid until the completion handler is called. In the above example, the buffer is the std::string variable msg. This variable is on the stack, and so it goes out of scope before the asynchronous operation completes. If you're lucky, your application will crash. Often you will get random failures.

With the new buffer debug checking, however, Boost.Asio stores an iterator into the string until the asynchronous operation completes, and then dereferences it to check its validity. In the above example you get an assertion failure just before Boost.Asio tries to call the completion handler.

This feature has only been tested with MSVC 8.0 so far, but it should work with any other implementation that supports iterator debugging. Obviously there's a performance cost to this checking, so it's only enabled in debug builds. You can also explicitly disable it by defining BOOST_ASIO_DISABLE_BUFFER_DEBUGGING (or ASIO_DISABLE_BUFFER_DEBUGGING if you're using standalone asio).

 

4 comments:

andi said...

Hi Chris!

First of all, thanks for the great library!

I just wondered about the behaviour of this buffer debugging thing if the buffer length is zero, e.g.:

[...]
string content = ...
array<asio::const_buffer, 2> buffers = {
asio::buffer(header_ptr, sizeof(header_t)),
asio::buffer(content)
};
asio::async_write(socket_, buffers, boost::bind(...));

This is what I tried to do in my prototype I'm currently building.
Well, the problem I ran into is that the content string would sometimes have length 0, and that triggered an assertion failure because (obviously) the iterator could not be dereferenced then.
So, I wondered whether this is the intended behaviour (in other words: a feature, not a bug)?

chris said...

Hi Andi,

Actually I fixed this bug not so long ago:

http://asio.cvs.sourceforge.net/asio/asio/include/asio/buffer.hpp?r1=1.22&r2=1.23

chris said...

Let's try that link again:

diff for bug fix

andi said...

Oh! Thanks for telling and good luck with your async' arts!



ngaut 2007-12-28 20:40 鍙戣〃璇勮
]]>
色综合久久久久网| 亚洲中文久久精品无码ww16| 精品午夜久久福利大片| 久久最近最新中文字幕大全| 久久久久亚洲AV综合波多野结衣| 久久久久久综合网天天| 欧美激情精品久久久久| 亚洲性久久久影院| AV色综合久久天堂AV色综合在| 九九久久精品国产| 久久久无码人妻精品无码| 国产高清美女一级a毛片久久w| 久久婷婷国产剧情内射白浆| 久久91亚洲人成电影网站| 久久天天婷婷五月俺也去| 久久综合久久久| 日产精品99久久久久久| 久久天天躁狠狠躁夜夜2020| 久久久久久无码Av成人影院| 久久婷婷五月综合97色直播 | 一级做a爰片久久毛片免费陪| 久久久亚洲欧洲日产国码二区 | 久久综合九色综合精品| 99久久99久久精品国产片果冻| 99久久精品国内| 日韩精品久久无码中文字幕| 亚洲欧洲久久av| 久久久人妻精品无码一区 | 欧美亚洲国产精品久久高清| 国产L精品国产亚洲区久久| 99久久婷婷国产综合亚洲| 精品综合久久久久久98| 伊人久久大香线蕉AV一区二区| 久久激情亚洲精品无码?V| 99精品久久久久久久婷婷| 国产精品岛国久久久久| 国产精品一久久香蕉国产线看观看 | 国产精品成人久久久久三级午夜电影| 亚洲香蕉网久久综合影视| 日韩人妻无码一区二区三区久久99 | 久久久久久国产a免费观看黄色大片 |