Revision: 289 Author: totti19851101 Date: Mon Aug 24 19:33:39 2009 Log: [No log message] http://code.google.com/p/boost-doc-zh/source/detail?r=289 Modified: /trunk/doc/html/boost_asio/tutorial/tuttimer1.html =======================================--- /trunk/doc/html/boost_asio/tutorial/tuttimer1.html Wed May 27 03:09:50 2009 +++ /trunk/doc/html/boost_asio/tutorial/tuttimer1.html Mon Aug 24 19:33:39 2009
@@ -1,6 +1,6 @@ <html> <head> -<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Timer.1 - Using a timer synchronously</title> <link rel="stylesheet" href="../../boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.74.3"> @@ -24,62 +24,51 @@ </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h3 class="title">-<a name="boost_asio.tutorial.tuttimer1"></a><a class="link" href="tuttimer1.html" title="Timer.1 - Using a timer synchronously"> Timer.1 - Using a timer
- synchronously</a>+<a name="boost_asio.tutorial.tuttimer1"></a><a class="link" href="tuttimer1.html" title="Timer.1 - Using a timer synchronously"> Timer.1 - 使用同步定时器</a>
</h3></div></div></div> <p>- This tutorial program introduces asio by showing how to perform a blocking
- wait on a timer. + 这个示例程序通过展示在定时器中执行一个阻塞等待来介绍Asio。 </p> <p> - We start by including the necessary header files. + 让我们从必须包含的头文件开始。 </p> <p>- All of the asio classes can be used by simply including the <code class="computeroutput"><span class="string">"asio.hpp"</span></code> header file. + 所有的Asio类只要简单的包含<code class="computeroutput"><span class="string">"asio.hpp"</span></code>头文件便可使用。
</p><pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">asio</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
</pre> <p>- Since this example users timers, we need to include the appropriate Boost.Date_Time
- header file for manipulating times.+ 因为本程序中使用了定时器,我们需要包含相应的的Boost.Date_Time 头文 件来处理时间操作。
</p><pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">date_time</span><span class="special">/</span><span class="identifier">posix_time</span><span class="special">/</span><span class="identifier">posix_time</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
</pre> <p>- All programs that use asio need to have at least one <a class="link" href="../reference/io_service.html" title="io_service">io_service</a> - object. This class provides access to I/O functionality. We declare an object
- of this type first thing in the main function.+ 使用Asio的所有程序都至少需要一个提供访问I/O功能的<a class="link" href="../reference/io_service.html" title="io_service">io_service</a>
+ 对象。因此在主函数中我们做的第一件事就是声明一个这个类型的对象。 </p><pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">io_service</span> <span class="identifier">io</span><span class="special">;</span>
</pre> <p>- Next we declare an object of type boost::asio::deadline_timer. The core asio - classes that provide I/O functionality (or as in this case timer functionality) - always take a reference to an io_service as their first constructor argument. - The second argument to the constructor sets the timer to expire 5 seconds
- from now.+ 接下来我们声明一个boost::asio::deadline_timer类型的对象。作为 Asio的 核心类,它提供的I/O功能(在此为定时器功能)通常用一个io_service 的引用作为其构 造函数的第一个参数。第二个参数设置一个从现在开始5秒后终止的定时器。
</p><pre class="programlisting"> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">deadline_timer</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">io</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">5</span><span class="special">));</span>
</pre> <p>- In this simple example we perform a blocking wait on the timer. That is, - the call to <a class="link" href="../reference/basic_deadline_timer/wait.html" title="basic_deadline_timer::wait">deadline_timer::wait()</a> - will not return until the timer has expired, 5 seconds after it was created
- (i.e. not from when the wait starts).+ 在这个简单的程序中,我们用定时器演示一个阻塞等待。<a class="link" href="../reference/basic_deadline_timer/wait.html" title="basic_deadline_timer::wait">deadline_timer::wait()</a>
+ 函数调用直到定时器终止(从定时器被创建算起,五秒后终止)才会返回。 </p> <p> - A deadline timer is always in one of two states: "expired" or "not- expired". If the <a class="link" href="../reference/basic_deadline_timer/wait.html" title="basic_deadline_timer::wait">deadline_timer::wait()</a>
- function is called on an expired timer, it will return immediately.+ 一个deadline timer 通常是下面两种状态中的一种:"expired(终止)" 或"not expired(不终止)"。如果<a class="link" href="../reference/basic_deadline_timer/wait.html" title="basic_deadline_timer::wait">deadline_timer::wait()</a>
+ 函数被一个已经终止的定时器调用, 它将立即返回。 </p><pre class="programlisting"> <span class="identifier">t</span><span class="special">.</span><span class="identifier">wait</span><span class="special">();</span>
</pre> <p>- Finally we print the obligatory <code class="computeroutput"><span class="string">"Hello,
- world!"</span></code> message to show when the timer has expired.+ 最后我们打印出 <code class="computeroutput"><span class="string">"Hello,
+ world!"</span></code> 信息以显示定时器已经终止。 </p><pre class="programlisting"> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Hello, world!\n"</span><span class="special">;</span>
@@ -87,14 +76,13 @@ <span class="special">}</span> </pre> <p>- See the <a class="link" href="tuttimer1/src.html" title="Source listing for Timer.1">full source listing</a> + 查看<a class="link" href="tuttimer1/src.html" title="Source listing for Timer.1">本例全部源码</a>
</p> <p>- Return to the <a class="link" href="../tutorial.html" title="Tutorial">tutorial index</a> + 返回<a class="link" href="../tutorial.html" title="Tutorial">指南 </a>
</p> <p>- Next: <a class="link" href="tuttimer2.html" title="Timer.2 - Using a timer asynchronously">Timer.2 - Using a timer
- asynchronously</a>+ 下例:<a class="link" href="tuttimer2.html" title="Timer.2 - Using a timer asynchronously">Timer.2 - 使用异步定时器</a>
</p> </div><table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"; width="100%"><tr>