锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲视频在线观看网站,欧美国产日韩一区,欧美日韩福利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="hvzpftn" 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="hvzpftn" class=post-header-line-1></div> <div id="hvzpftn" 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="hvzpftn" class=post-footer> <p class="post-footer-line post-footer-line-1"><span id="hvzpftn" class="post-author vcard">Posted by <span id="hvzpftn" class=fn>chris</span> </span><span id="hvzpftn" 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="hvzpftn" class=post-comment-link><a class=comment-link onclick="" ><u><font color=#0000ff>1 comments</font></u></a> </span><span id="hvzpftn" class="post-backlinks post-comment-link"></span><span id="hvzpftn" class=post-icons><span id="hvzpftn" class="item-control blog-admin pid-660467121"><a title="Edit Post" ><u><font color=#0000ff><span id="hvzpftn" class=quick-edit-icon> </span> </font></u></a></span></span></p> <p class="post-footer-line post-footer-line-2"><span id="hvzpftn" 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="hvzpftn" 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="hvzpftn" class=post-header-line-1></div> <div id="hvzpftn" 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="hvzpftn" class=post-footer> <p class="post-footer-line post-footer-line-1"><span id="hvzpftn" class="post-author vcard">Posted by <span id="hvzpftn" class=fn>chris</span> </span><span id="hvzpftn" 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="hvzpftn" class=post-comment-link><a class=comment-link onclick="" ><u><font color=#0000ff>2 comments</font></u></a> </span><span id="hvzpftn" class="post-backlinks post-comment-link"></span><span id="hvzpftn" class=post-icons><span id="hvzpftn" class="item-control blog-admin pid-660467121"><a title="Edit Post" ><u><font color=#0000ff><span id="hvzpftn" class=quick-edit-icon> </span> </font></u></a></span></span></p> <p class="post-footer-line post-footer-line-2"><span id="hvzpftn" 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="hvzpftn" 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="hvzpftn" class=post-header-line-1></div> <div id="hvzpftn" 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 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美成人免费全部观看天天性色| 国产欧美精品一区二区三区介绍 | 免费在线观看成人av| 午夜久久久久| 国产综合久久久久影院| 亚洲一区图片| 欧美在线观看一区| 亚洲国产成人精品久久| 亚洲电影自拍| 欧美xart系列高清| 中日韩在线视频| 午夜视频久久久| 香蕉尹人综合在线观看| 亚洲天堂偷拍| 欧美一激情一区二区三区| 亚洲国产乱码最新视频| 99精品国产福利在线观看免费 | 亚洲精品免费一区二区三区| 国产精品久久久对白| 久久久久久久久岛国免费| 欧美成人国产| 欧美一区二区三区喷汁尤物| 麻豆freexxxx性91精品| 国产精品99久久久久久久女警| 亚洲素人一区二区| 亚洲国产成人av在线| 一区二区久久| 亚洲国产精品一区二区www在线| 日韩性生活视频| 在线不卡a资源高清| 一区二区欧美激情| 亚洲高清在线精品| 亚洲欧美日本日韩| 一区二区精品| 久久综合成人精品亚洲另类欧美| 亚洲影院污污.| 欧美成人一品| 欧美午夜性色大片在线观看| 亚洲欧美日韩一区| 另类综合日韩欧美亚洲| 欧美一区二区三区久久精品茉莉花 | 久久成人久久爱| 欧美精品久久久久久| 久久视频精品在线| 欧美日韩精品一区视频| 欧美成人一区二区在线 | 美女91精品| 久久精品在这里| 国产精品免费视频xxxx| 亚洲区中文字幕| 亚洲国产激情| 久久久久99| 久久久久久高潮国产精品视| 欧美性片在线观看| 亚洲精品免费一区二区三区| 亚洲国产一区二区在线| 久久蜜桃av一区精品变态类天堂| 亚洲欧美日韩区| 国产精品久久久久婷婷| 在线亚洲精品| 亚洲欧美日本伦理| 欧美日韩亚洲一区二区三区| 亚洲精品自在久久| 99精品久久| 欧美日韩一区在线观看| 亚洲精品日韩一| 亚洲视频在线观看视频| 欧美日韩黄色一区二区| 亚洲黄色小视频| 亚洲精品国产品国语在线app| 免费观看成人www动漫视频| 欧美电影打屁股sp| 亚洲精品美女免费| 久久久噜噜噜久久久| 毛片av中文字幕一区二区| 狠狠入ady亚洲精品| 久久影音先锋| 欧美韩国日本综合| 亚洲理伦在线| 欧美亚洲不卡| 亚洲欧美日韩成人高清在线一区| 欧美一区二区国产| 国产综合欧美在线看| 久久人人97超碰精品888| 欧美激情精品久久久久久黑人| 在线观看一区二区视频| 欧美精品18+| 亚洲影院免费| 久久久噜噜噜| 亚洲欧洲日本专区| 国产精品第十页| 久久9热精品视频| 亚洲黄网站黄| 欧美一区二区精品| 亚洲国产精品成人精品| 欧美视频在线观看一区二区| 欧美一级黄色录像| 欧美二区在线观看| 亚洲免费视频观看| 在线观看视频一区二区| 国产精品―色哟哟| 欧美激情在线有限公司| 亚洲成色最大综合在线| 亚洲影视在线播放| 亚洲第一毛片| 欧美日韩免费看| 日韩视频一区二区三区在线播放| 亚洲电影在线观看| 欧美一级片在线播放| 亚洲国产免费| 国产精品一区久久久| 欧美sm重口味系列视频在线观看| 亚洲一区精彩视频| 免费观看30秒视频久久| 午夜欧美不卡精品aaaaa| 亚洲国产一区二区三区青草影视| 国产女主播在线一区二区| 欧美电影电视剧在线观看| 午夜精品99久久免费| 日韩亚洲欧美一区| 欧美.www| 久久精品人人| 午夜欧美大尺度福利影院在线看 | 国产精品美女在线| 欧美激情第4页| 久久久久久婷| 久久成人人人人精品欧| 亚洲综合视频一区| 一本久久青青| 亚洲人成久久| 亚洲第一天堂av| 免费视频最近日韩| 久久激情一区| 欧美一区二区三区免费视| 中日韩美女免费视频网站在线观看| 亚洲激情电影在线| 黄色日韩在线| 国语自产精品视频在线看抢先版结局 | 国内精品视频在线观看| 欧美精品在欧美一区二区少妇| 久久国产日韩| 欧美一区二区日韩| 香蕉免费一区二区三区在线观看| 亚洲一二三区在线| 在线一区免费观看| 一区二区三区导航| 在线亚洲一区观看| 亚洲视频在线观看三级| 一本色道久久综合亚洲精品小说| 日韩亚洲欧美在线观看| 亚洲伊人观看| 亚洲天堂免费观看| 91久久精品视频| 欧美国产精品久久| 欧美黄色aaaa| 亚洲欧洲日韩女同| 亚洲日本久久| 在线视频中文亚洲| 免费高清在线视频一区·| 欧美日韩亚洲一区二区| 国产精品超碰97尤物18| 国产精品一区二区欧美| 国产亚洲精品久久飘花| 精品成人免费| 亚洲精品欧美一区二区三区| 在线视频亚洲一区| 欧美诱惑福利视频| 欧美69视频| 亚洲精品久久久久久下一站| 在线亚洲欧美专区二区| 久久久99免费视频| 欧美日韩免费观看中文| 国产精品区一区二区三区| 激情欧美国产欧美| 亚洲伦理在线观看| 韩国自拍一区| 亚洲全黄一级网站| 亚洲欧美国产毛片在线| 久久久久青草大香线综合精品| 欧美插天视频在线播放| 亚洲国产三级| 久久精品国产99国产精品澳门| 欧美大片专区| 国产欧美一区二区三区国产幕精品| 影音先锋日韩精品| 亚洲男女毛片无遮挡| 久色成人在线| 亚洲午夜精品久久久久久app| 久久国产成人| 国产精品av免费在线观看| 娇妻被交换粗又大又硬视频欧美| 艳妇臀荡乳欲伦亚洲一区| 久久riav二区三区| 日韩亚洲欧美成人一区| 久久综合五月| 国产精品久久久久永久免费观看| 亚洲高清一区二| 久久久99国产精品免费| 一区二区激情| 欧美成人资源网|