﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Focus on ACE-随笔分类-ACE</title><link>http://www.cppblog.com/ace/category/1167.html</link><description>&lt;table style="border:1px solid #aa0033; font-size:small" align=center&gt;
  &lt;tr&gt;
    &lt;td rowspan=3&gt;
    
    &lt;/td&gt;
    &lt;td colspan=2 align=center&gt;&lt;b&gt;订阅 ace-china&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;form action="http://groups.google.com/group/ace-china/boxsubscribe"&gt;
  &lt;input type=hidden name="hl" value="zh-CN"&gt;
  &lt;tr&gt; 
    &lt;td&gt;电子邮件： &lt;input type=text name=email&gt;&lt;/td&gt;
    &lt;td&gt;
      &lt;table 
       style="background-color:#ffcc33;padding:2px;border:2px outset #ffcc33;"&gt;
      &lt;tr&gt;
        &lt;td&gt;
         &lt;input type=submit name="sub" value="订阅"&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
   &lt;/form&gt;
  &lt;tr&gt;&lt;td colspan=2 align=center&gt; 浏览存于  
	&lt;a href="http://groups.google.com/group/ace-china"&gt;groups.google.com&lt;/a&gt; 上的&lt;a href="http://groups.google.com/group/ace-china"&gt;所有帖子&lt;/a&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 12:35:16 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 12:35:16 GMT</pubDate><ttl>60</ttl><item><title>ACE小技巧：在ACE_Acceptor框架中，自定义服务处理器的创建</title><link>http://www.cppblog.com/ace/archive/2006/08/30/11849.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 30 Aug 2006 06:11:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/08/30/11849.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/11849.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/08/30/11849.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/11849.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/11849.html</trackback:ping><description><![CDATA[<p>
				<span class="Title">ACE小技巧：在ACE_Acceptor框架中，自定义服务处理器的创建</span>
		</p>
		<p>
				<em><a title="Focus on ACE" href="http://www.cppblog.com/ace" >Stone Jiang</a></em>
		</p>
		<p>ACE_Acceptor框架使对新连接的侦听变得容易，也使创建和激活新连接的ACE_Svc_Handler的派生类变得容易。之前我们已经了解了ACE_Svc_Handle::open()挂勾函数和服务处理器</p>
		<p>初始化时它所扮演的角色。本文我们回退几步，来了解服务处理器是如何实例化的以及我们如何自定义它的行为。</p>
		<p>再看看ACE_Acceptor类，它是一个模板类，第一个模板参数ACE_Accetpor是代表与服务建立连接的处理器。当新的连接建立时，ACE_Acceptor调用make_svc_handler()挂勾函数来</p>
		<p>实际创建的新建服务处理器对象。ACE_Acceptor::make_svc_handler()的实现如下:<br /></p>
		<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
				<div>
						<span style="COLOR: #000000">template </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">class</span>
						<span style="COLOR: #000000"> SVC_HANDLE,ACE_PEER_ACCEPTOR_1</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">
								<br />ACE_Acceptor</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">SVC_HANDLE, ACE_PEER_ACCEPTOR_2</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">::make_svc_handler(SVC_HANDLE</span>
						<span style="COLOR: #000000">*&amp;</span>
						<span style="COLOR: #000000"> sh)<br />{<br />  ACE_TRACE (</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">ACE_Acceptor&lt;SVC_HANDLER, ACE_PEER_ACCEPTOR_2&gt;::make_svc_handler</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);  </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (sh </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br />    ACE_NEW_RETURN (sh,<br />                    SVC_HANDLER,<br />                    </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);  </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Set the reactor of the newly created &lt;SVC_HANDLER&gt; to the same<br />  </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> reactor that this &lt;ACE_Acceptor&gt; is using.</span>
						<span style="COLOR: #008000">
								<br />
						</span>
						<span style="COLOR: #000000">  sh</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">reactor (</span>
						<span style="COLOR: #0000ff">this</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">reactor ());<br />  </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><br />}<br /></span>
				</div>
		</div>
		<p> </p>
		<p>默认的实现包括了两步基本操作：<br />1.  获得一个新的SVC_HANLDER对象， 这里是使用的new运算符分配的。<br />2.  设置新的服务处理器的reactor指针为ACE_Accetpor使用的reactor的。</p>
		<p>然而，如果应用程序需要通过其它方式获得SVC_HANDLER对象，而不是通过默认的构造函数那种动态分配，这又该怎么办呢？举例来说，我们可能需要：<br /> . 从一个预分配的池中获得SVC_HANDLER对象；<br /> . 为新创建的SVC_HANDLER传入一些额外的信息<br /> . 使用单体的SVC_HANDLER</p>
		<p>上面这些情形，我们都可以自定义make_svc_handler()挂勾函数来实现必要的行为。例如,假定我们新的处理器需要拥有一个处理所有对所有接收到的消息进行集中处理的中心处理</p>
		<p>器。这个中心处理器我们用类Processor表示。我们需要每个服务处理器都拥有一个指向中心处理器的指针，而不是使Processor成为一个全局访问的指针(使用全局变量的种种弊端</p>
		<p>本文不作详述)。我们的解决办法是: 从ACE_Accetor派生一个新类，这个新类拥有Processor的指针作成员，并且，在创建新和服务处理器(Service)的时候，把这个 Processor的</p>
		<p>指针作参数传进去。</p>
		<p>新的acceptor类可以这样定义：<br /></p>
		<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
				<div>
						<img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />
						<span style="COLOR: #0000ff">class</span>
						<span style="COLOR: #000000"> My_Acceptor : </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> ACE_Acceptor</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">Service, ACE_SOCK_ACCEPTOR</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img id="_68_539_Open_Image" onclick="this.style.display='none'; document.getElementById('_68_539_Open_Text').style.display='none'; document.getElementById('_68_539_Closed_Image').style.display='inline'; document.getElementById('_68_539_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
								<img id="_68_539_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_68_539_Closed_Text').style.display='none'; document.getElementById('_68_539_Open_Image').style.display='inline'; document.getElementById('_68_539_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" />
						</span>
						<span id="_68_539_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span>
						<span id="_68_539_Open_Text">
								<span style="COLOR: #000000">{<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span>
								<span style="COLOR: #0000ff">public</span>
								<span style="COLOR: #000000">:<br /><img id="_140_142_Open_Image" onclick="this.style.display='none'; document.getElementById('_140_142_Open_Text').style.display='none'; document.getElementById('_140_142_Closed_Image').style.display='inline'; document.getElementById('_140_142_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_140_142_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_140_142_Closed_Text').style.display='none'; document.getElementById('_140_142_Open_Image').style.display='inline'; document.getElementById('_140_142_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  My_Acceptor (Processor </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">processor) : processor_ (processor) </span>
								<span id="_140_142_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span>
								<span id="_140_142_Open_Text">
										<span style="COLOR: #000000">{ }</span>
								</span>
								<span style="COLOR: #000000">;<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> make_svc_handler (Service </span>
								<span style="COLOR: #000000">*&amp;</span>
								<span style="COLOR: #000000">sh)<br /><img id="_190_502_Open_Image" onclick="this.style.display='none'; document.getElementById('_190_502_Open_Text').style.display='none'; document.getElementById('_190_502_Closed_Image').style.display='inline'; document.getElementById('_190_502_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_190_502_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_190_502_Closed_Text').style.display='none'; document.getElementById('_190_502_Open_Image').style.display='inline'; document.getElementById('_190_502_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
								<span id="_190_502_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">...</span>
								<span id="_190_502_Open_Text">
										<span style="COLOR: #000000">{<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />      </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (sh </span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">)<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />        ACE_NEW_RETURN (sh,<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />                        Service (</span>
										<span style="COLOR: #0000ff">this</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">processor_),<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />                        </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">);      </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000"> Set the reactor of the newly created &lt;SVC_HANDLER&gt; to the same<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />      </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">  reactor that this &lt;ACE_Acceptor&gt; is using.</span>
										<span style="COLOR: #008000">
												<br />
												<img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">      sh</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">reactor (</span>
										<span style="COLOR: #0000ff">this</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">reactor ());<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />      </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">;<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />
										<br />
										<img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #0000ff">private</span>
								<span style="COLOR: #000000">:<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  Processor </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">processor_;<br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />
						</span>
				</div>
		</div>
		<p> </p>
		<p>就这样，现在，当My_Acceptor接受新连接的时候，make_svc_handler()挂勾函数分配一个新的处理器(Service)，并把Processor*作为参数传进去。需要注意的事，尽管这里使用</p>
		<p>的是这一个构造函数Service(Processor*)。我们仍需求为Service类定义默认的构造函数，以满足模板类ACE_Acceptor的需要。</p>
		<p> </p><img src ="http://www.cppblog.com/ace/aggbug/11849.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-08-30 14:11 <a href="http://www.cppblog.com/ace/archive/2006/08/30/11849.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>小技巧: 当ACE_Svc_Handler关闭时使用的默认行为</title><link>http://www.cppblog.com/ace/archive/2006/08/28/11762.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Mon, 28 Aug 2006 01:36:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/08/28/11762.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/11762.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/08/28/11762.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/11762.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/11762.html</trackback:ping><description><![CDATA[<p>小技巧: 当ACE_Svc_Handler关闭时使用的默认行为</p>
		<p>
				<a title="Focus on ACE" href="/ace">Stone Jiang</a>
				<br />
				<br />上一篇我们看了ACE_Svc_Handler::open()挂勾函数提供默认行为的一些技巧。因为在大多数情况下，它完成了服务创建时所需的所有事情：为输入事件注册新处理器和返回。</p>
		<p>
				<br />在ACE_Svc_Handler中关闭操作的默认行为要比在open()中初始化的代码更为复杂。这是因为关闭时的挂勾函数包含了反应式(reactive)关闭和主动式(active-object)关闭两种情</p>
		<p>况，它们有相同的效果:删除所有在反应器注册的事件和确保删除ACE_Svc_handler的派生类的对象。</p>
		<p> </p>
		<p>反应式关闭(handle_close()): 当以下形况发生时被调用：<br /> 1) 事件回调函数(译注：handle_xxxx())返回-1时，或<br /> 2) 调用ACE_Reactor::remove_handler()，传入的标记不含 DONT_CALL时<br /> 反应器框架将调用handle_close()挂勾函数。 ACE_Svc_handler::handle_close()的默认行为是调用ACE_Svc_Handler::destroy()销毁事件处理器。</p>
		<p>
				<br />主动对象式关闭(close()): 当ACE_Svc_Handler 派生的对象通过activate()函数转变为主动对象，处理器的的svc()方法在它产生的线程中运行后进行回调。当svc()返回时，线程</p>
		<p>退出，但在它要退出时，仍在将要退出线程的上下文中，ACE_Task框架调用它的close()方法。ACE_Svc_Handler::close()方法调用handle_close()完成服务处理器的清理工作。</p>
		<p>因此，不管ACE_Svc_Handler对象是反应式还是主动式，结束时的清理工作都在相同的地方：ACE_Svc_Handler::destroy()。如果对象是动态分配且不是ACE_Stream框架中的组成部</p>
		<p>分，destroy()将删除此对象，如果对象不是动态分配的，析构它的责任是创建时对象所在的封闭范围。如果对象是ACE_Stream的模块的组成部分，流和/或控制流的代码负责管理</p>
		<p>对象的生命期。destroy()函数应遵守这样的规则来避免出现资源泄漏。</p>
		<p>
				<br />无论ACE_Svc_Handler对象是反应式销毁还是主动式销毁，都会引起相同的事情发生：~ACE_Svc_Handler() (处理器的析构函数)调用ACE_Svc_Handler::shutdown()函数完成服务处</p>
		<p>理器的清理工作。shutdown()执行的这些清理操作是：</p>
		<p> </p>
		<p>如果处理器与反应器是关联的：<br />   取消处理器关联的所有定时器。<br />   为处理器的流对象（如socket)删除所有已注册的事件。<br />如果处理器与再生器(recycler)是关系的，从再生器中清除处理器。<br />关闭流对象。<br />因此，我们看到的绝大多数情况服务处理器通过shutdown需要通过框架来清理工作，都是简单的允许缺省的挂勾函数得以被调用。如果你的应用程序需求更多的关闭/清理规则，推</p>
		<p>荐的地方是你的处理器的handle_close()挂勾方法。仅仅是确保把ACE_Svc_Handler::destroy()函数人作为你的handle_close()的最后一个动作，与框架清理行为的余下的行为合</p>
		<p>并。</p>
		<p>
				<br /> </p><img src ="http://www.cppblog.com/ace/aggbug/11762.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-08-28 09:36 <a href="http://www.cppblog.com/ace/archive/2006/08/28/11762.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>小技巧: ACE_Svc_Handler的初始化</title><link>http://www.cppblog.com/ace/archive/2006/08/27/11758.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Sun, 27 Aug 2006 15:48:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/08/27/11758.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/11758.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/08/27/11758.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/11758.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/11758.html</trackback:ping><description><![CDATA[<h1>小技巧: ACE_Svc_Handler的初始化</h1>
		<pre>
				<pre>
						<br />
						<br /><a title="Focus on ACE" href="http://www.cppblog.com/ace" >Stone Jiang</a><br /><pre>ACE_Svc_Handler经常用于网络服务类的基类，这是因为它很容易在主动对象(Active Ojbect)<br />模式和反应器(Reactor)框架中使用。APG第7.6节中讨论了怎么在接受器-连接器(Acceptor-conector)<br />框架中如何把ACE_Svc_Handler作为目标来使用，并且，在C++NPv2第7章中，深度探讨了<br />Acceotor-Connector的相关设计。</pre><pre>挂勾函数(Hook method)ACE_Svc_Handler::open()常是服务中新建连接时执行的初始化设置的地方。<br />举例来说，如果服务要在日志中记录新连接建立的相关信息，open()函数是则是记录这个信息的地方。<br />对于使用Reacotor 框架的服务检查网络数据到达，open()是执行reactor注册的地方。<br />事实上，这正是reactor注册的地方，这种动作在服务建立新连接时非常常见的，ACE_Svc_Handler::<br />open()的缺省操作也正是</pre><pre><pre>if (this-&gt;reactor () &amp;&amp; this-&gt;reactor ()-&gt;register_handler
          (this,
           ACE_Event_Handler::READ_MASK) == -1)
  ACE_ERROR_RETURN ((LM_ERROR,
                     ACE_LIB_TEXT ("%p\n"),
                     ACE_LIB_TEXT ("unable to register client handler")),
                    -1);
return 0;
</pre></pre><pre>所以，如果在与服务建立新连接并为“读事件”注册时，你甚至不需要在你的类中<br />实现open(void*)函数，ACE已经为你做了这一步!另外，请记住，如果reactor注册失败，<br />默认的open()函数会返回-1，它会引起Acceptor-Connector框架关闭新建的连接和删除这个<br />事件处理器(handler)。<br /><a title="Focus on ACE" href="/ace">Stone Jiang</a><br /><a href="/ace/">http://www.cppblog.com/ace/</a><br /><br /></pre></pre>
		</pre><img src ="http://www.cppblog.com/ace/aggbug/11758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-08-27 23:48 <a href="http://www.cppblog.com/ace/archive/2006/08/27/11758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE_Hash_Map的使用示例</title><link>http://www.cppblog.com/ace/archive/2006/07/13/9796.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Thu, 13 Jul 2006 05:39:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/07/13/9796.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/9796.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/07/13/9796.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/9796.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/9796.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> TestHaspMap.cpp : Defines the entry point for the console application.<br /></span>
				<span style="COLOR: #008000">//<br /></span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stdafx.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Basic_Types.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Map_Manager.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/SString.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Log_Msg.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Null_Mutex.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> PhoneNumber<br />{<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br />    PhoneNumber(</span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> number):number_(number)<br />    {<br /><br />    }<br />    </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> getNumber(</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000">)<br />    {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> number_.c_str();<br />    }<br /></span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000">:<br />    ACE_SString  number_; <br />};<br /><br /><br /><br />typedef ACE_UINT16 CONNECTION_ID;<br /><br />typedef ACE_Null_Mutex MAP_MUTEX;<br /><br />typedef ACE_Map_Manager</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">CONNECTION_ID,PhoneNumber</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">, MAP_MUTEX</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />   CONNECTION_MAP;<br /><br />typedef ACE_Map_Iterator</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">CONNECTION_ID, PhoneNumber</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">, MAP_MUTEX</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />     CONNECTION_MAP_ITERATOR;<br /><br />typedef ACE_Map_Entry</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">CONNECTION_ID, PhoneNumber</span>
				<span style="COLOR: #000000">*&gt;</span>
				<span style="COLOR: #000000">
						<br />    CONNECTION_MAP_ENTRY;<br /><br />typedef ACE_Map_Manager</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">CONNECTION_ID,CONNECTION_MAP</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">,MAP_MUTEX</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />     MAP_MAP;<br /><br />typedef ACE_Map_Iterator</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">CONNECTION_ID, CONNECTION_MAP</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">, MAP_MUTEX</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />MAP_MAP_ITERATOR;<br /><br />typedef ACE_Map_Entry</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">CONNECTION_ID, CONNECTION_MAP</span>
				<span style="COLOR: #000000">*&gt;</span>
				<span style="COLOR: #000000">
						<br />MAP_MAP_ENTRY;<br /><br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ACE_TMAIN(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, _TCHAR</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> argv[])<br />{<br /><br /><br />    CONNECTION_MAP connection_map;<br />    PhoneNumber  me(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">13717928***</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />    PhoneNumber  office(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">010-82378***</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /><br />    PhoneNumber  home(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">13366686**</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> result </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />    result </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> connection_map.bind(</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">me);<br />     ACE_ASSERT(result </span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">);<br />    result </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  connection_map.bind(</span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">office);<br />    ACE_ASSERT(result </span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">);<br />    result </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  connection_map.bind(</span>
				<span style="COLOR: #000000">3</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">home);<br />    ACE_ASSERT(result </span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">);<br />    result </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> connection_map.bind(</span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">home);<br />    ACE_ASSERT(result </span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">);<br /><br />    connection_map.unbind(</span>
				<span style="COLOR: #000000">3</span>
				<span style="COLOR: #000000">);<br />    CONNECTION_MAP_ITERATOR it(connection_map);<br />  <br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (CONNECTION_MAP_ENTRY </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">i </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />        it.next (i) </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />        it.advance ())<br />    {<br />        PhoneNumber</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> phone </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">int_id_;<br />        ACE_DEBUG((LM_INFO,ACE_TEXT(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">连接号码　%d, 电话号码 %s\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),<br />            i</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">ext_id_,<br />            phone</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">getNumber()));<br />    }<br /><br />   PhoneNumber</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> any_phone </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />   CONNECTION_ID any_id </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">;<br /><br />    result </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> connection_map.find(any_id,any_phone);<br />   </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">( result </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">)<br />   {<br />       ACE_DEBUG((LM_INFO,ACE_TEXT(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">连接号码　%d, 电话号码 %s\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),<br />           any_id,<br />           any_phone</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">getNumber()));<br />   } <br />   </span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />   {<br />       ACE_DEBUG((LM_INFO,ACE_TEXT(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">连接号码　%d, 电话号码 %s\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),<br />           any_id,<br />           </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">not found.</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">));<br />   }<br /><br />   MAP_MAP map_map;<br />   map_map.bind(</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">connection_map);<br />   size_t n </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> map_map.current_size();<br />   MAP_MAP_ITERATOR map_it(map_map);<br /><br />   </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (MAP_MAP_ENTRY </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">j </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />       map_it.next (j) </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />       map_it.advance ())<br />   {<br />       CONNECTION_MAP</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> cur_map </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> j</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">int_id_;<br />        size_t count </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> cur_map</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">current_size();<br />         PhoneNumber</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> any_phone2 </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />         </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (cur_map</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">find(</span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">,any_phone2)</span>
				<span style="COLOR: #000000">!=-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">)<br />         {<br />             ACE_DEBUG((LM_INFO,ACE_TEXT(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">内部map中电话号码 %s\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),<br />                 any_phone2</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">getNumber()));<br />         }<br />   }<br /><br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
		</div><img src ="http://www.cppblog.com/ace/aggbug/9796.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-07-13 13:39 <a href="http://www.cppblog.com/ace/archive/2006/07/13/9796.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于ACE_Thread_Mutex的回复</title><link>http://www.cppblog.com/ace/archive/2006/07/12/9746.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 12 Jul 2006 07:25:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/07/12/9746.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/9746.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/07/12/9746.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/9746.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/9746.html</trackback:ping><description><![CDATA[<p>感谢您的回复 <br />的确太低级别了,这是我对操作系统不熟悉造成的. <br />有的操作系统,如win32,系统默认实现的是递归锁,有的则不是,如Solaris. </p>
		<p>下面是取自ace注释 </p>
		<p>/** <br />* @class ACE_Thread_Mutex <br />* <br />* @brief ACE_Thread_Mutex wrapper (only valid for threads in the same <br />* process). <br />* <br />* This implementation is optimized for locking threads that are <br />* in the same process. It maps to &lt;CRITICAL_SECTION&gt;s on NT <br />* and &lt;ACE_mutex_t&gt; with &lt;type&gt; set to &lt;USYNC_THREAD&gt; on UNIX. <br />* ACE_Thread_Mutex is recursive on some platforms (like <br />* Win32). However, on most platforms (like Solaris) it is not <br />* recursive. To be totally safe and portable, developers <br />* should use ACE_Recursive_Thread_Mutex when they need a <br />* recursive mutex. <br />*/ </p>
		<p> </p><img src ="http://www.cppblog.com/ace/aggbug/9746.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-07-12 15:25 <a href="http://www.cppblog.com/ace/archive/2006/07/12/9746.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>再次获得互斥体,为什么没有死锁</title><link>http://www.cppblog.com/ace/archive/2006/07/09/9617.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Sun, 09 Jul 2006 14:56:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/07/09/9617.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/9617.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/07/09/9617.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/9617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/9617.html</trackback:ping><description><![CDATA[今天与一个朋友讨论死锁的时候,我说,我简单写一个程序,验证一下.<br />一测不要紧,本应该死锁的程序,怎么不死锁了呢?<br /><br />我们来看代码吧 <br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #008000">//</span><span style="COLOR: #008000"> testMutex.cpp : Defines the entry point for the console application.<br /></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #008000"></span><span style="COLOR: #008000">//<br /></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">stdafx.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Thread_Mutex.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Log_Msg.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Guard_T.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">typedef ACE_Thread_Mutex MUTEX;<br /></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Logger<br /></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> log(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">        ACE_GUARD(MUTEX,mon,mutex_);<br /></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000">        ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">(%t) 进入互斥体1\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000">        logCritical();<br /></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> logCritical()<br /></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">        ACE_GUARD(MUTEX,mon,mutex_);<br /></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000">        ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">(%t) 为什么还能再进入进入互斥体1,为什么不在这里死锁\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000">    MUTEX mutex_;<br /></span><span style="COLOR: #008080">26</span> <span style="COLOR: #000000">};<br /></span><span style="COLOR: #008080">27</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">28</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">29</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ACE_TMAIN(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, _TCHAR</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> argv[])<br /></span><span style="COLOR: #008080">30</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">31</span> <span style="COLOR: #000000">    ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">(%t) 主线程\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080">32</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">33</span> <span style="COLOR: #000000">    Logger l;<br /></span><span style="COLOR: #008080">34</span> <span style="COLOR: #000000">    l.log();  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">影响不在这里死锁呢</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">35</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">36</span> <span style="COLOR: #000000">   ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">(%t) 主线程2\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080">37</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">38</span> <span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">39</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">40</span> <span style="COLOR: #000000"></span></div><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br />屏幕输出的结果是<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">  (4492) 主线程<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  (4492) 进入互斥体1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  (4492) 为什么还能再进入进入互斥体1,为什么不在这里死锁<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  (4492) 主线程2</span></div><br /><br /><img src ="http://www.cppblog.com/ace/aggbug/9617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-07-09 22:56 <a href="http://www.cppblog.com/ace/archive/2006/07/09/9617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE应用程序链接错误  error LNK2019 的解决办法 </title><link>http://www.cppblog.com/ace/archive/2006/07/09/9604.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Sun, 09 Jul 2006 04:53:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/07/09/9604.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/9604.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/07/09/9604.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/9604.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/9604.html</trackback:ping><description><![CDATA[<h3>ACE应用程序链接错误  error LNK2019 的解决办法 <br /> </h3>
		<p>读者水平:初级 <br />摘要：文本简要指出如何正确编译和链接ACE应用程序。</p>
		<p>对于新手来说，ACE开发环境，会是一团谜团，如何正确配置开发者机器，快速体验ACE，<br />就是本系列文章的目的。本文仅解决如何解决LNK2019错误</p>
		<p>环境：<br />  </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">   ACE版本 5.5.1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />     操作系统 Windows xp professional sp2<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />     开发环境 Microsoft Visual C++ 2005   77626-009-0000007-41235<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
		<p>下面的代码是服务的主程序<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@file: RegisterServer.cpp :<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@description: Defines the entry point for the GameService Daemon application.<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@date: 2006-07-06<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@author: Jiangtao&lt;2005119@gmail.com&gt;</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">#ifdef _DEBUG<br /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000">   ACE_NDEBUG 0</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000">   ACE_NTRACE 0</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">#endif</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stdafx.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Filecache.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Log_Msg.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/OS_NS_signal.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>/Service_Config.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<br />#ifdef ACE_HAS_SIG_C_FUNC<br />#pragma message (</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">ACE_HAS_SIG_C_FUNC</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br /></span>
				<span style="COLOR: #0000ff">extern</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">C</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />{<br /></span>
				<span style="COLOR: #0000ff">#endif</span>
				<span style="COLOR: #000000"> /* ACE_HAS_SIG_C_FUNC */</span>
				<span style="COLOR: #000000">
						<br />
						<br /> </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> call exit() so that static destructors get called</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000">
						<br />  handler (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">)<br /> {<br />  delete (ACE_Filecache </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">) ACE_Filecache::instance ();<br />  ACE_OS::exit (</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">);<br /> }<br /><br />#ifdef ACE_HAS_SIG_C_FUNC<br />}<br /></span>
				<span style="COLOR: #0000ff">#endif</span>
				<span style="COLOR: #000000"> /* ACE_HAS_SIG_C_FUNC */</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ACE_TMAIN(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, ACE_TCHAR</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> argv[])<br />{<br /> ACE_DEBUG((LM_INFO,ACE_TEXT(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">启动服务\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)));<br /> ACE_Service_Config daemon;<br /><br /> ACE_OS::signal (SIGCHLD, SIG_IGN);<br /><br /> </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> SigAction not needed since the handler will shutdown the server.</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000"> ACE_OS::signal (SIGINT, (ACE_SignalHandler) handler);<br /> ACE_OS::signal (SIGUSR2, (ACE_SignalHandler) handler);<br /><br /> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (daemon.open (argc, argv, ACE_DEFAULT_LOGGER_KEY, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">) </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">)<br />  ACE_ERROR_RETURN ((LM_ERROR, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%p\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">open</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">), </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">);<br /><br /> </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> The configured service creates threads, and the<br /> </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> server won't exit until the threads die.<br /><br /> </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Run forever, performing the configured services until we receive<br /> </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> a SIGINT.</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<br /> </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
		</div>
		<p>服务加载的配置文件</p>
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />###############################################################################<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /># file svc.conf<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />###############################################################################<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />dynamic GameService Service_Object </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> GameService: _make_GameServer_T() active <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
		<p> </p>
		<p>
				<br />出错提示:</p>
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">----- Build started: Project: RegisterServer, Configuration: Debug Win32 ------<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Compiling<img src="http://www.cppblog.com/images/dot.gif" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RegisterServer.cpp<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Linking<img src="http://www.cppblog.com/images/dot.gif" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RegisterServer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ace_os_wmain_i(class ACE_Main_Base &amp;,int,wchar_t * * const)" (__imp_?ace_os_wmain_i@@YAHAAVACE_Main_Base@@HQAPA_W@Z) referenced in function _wmain<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RegisterServer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl ACE_Service_Config::open(int,wchar_t * * const,wchar_t const *,int,int,int)" (__imp_?open@ACE_Service_Config@@SAHHQAPA_WPB_WHHH@Z) referenced in function "int __cdecl ace_wmain_i(int,wchar_t * * const)" (?ace_wmain_i@@YAHHQAPA_W@Z)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />D:\ACE_OUTPUT\Game\\RegisterServerd.exe : fatal error LNK1120: 2 unresolved externals<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Build log was saved at "file://d:\My Sources\RegisterService\RegisterServer\Debug\BuildLog.htm"<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RegisterServer - 3 error(s), 0 warning(s)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========</span>
		</div>
		<p> </p>
		<p>问题分析<br />出错信息显示，不能解析函数ace_os_wmain_i()以及  ACE_Service_Config::open()。<br />从这里可以看出，链接器需要UNICODE版本的ace库，而我们在生成ACE的时候，并没有生成宽字符<br />的UNICODE版本。</p>
		<p>解决办法：<br />打开项目的属性页，找到配置属性，在字符集中，选择多字节字符集。再重新编译，问题解决。</p>
		<p> </p>
		<p> </p><img src ="http://www.cppblog.com/ace/aggbug/9604.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-07-09 12:53 <a href="http://www.cppblog.com/ace/archive/2006/07/09/9604.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual C++下ACE动态服务配置入门</title><link>http://www.cppblog.com/ace/archive/2006/07/04/9367.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Tue, 04 Jul 2006 05:26:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/07/04/9367.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/9367.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/07/04/9367.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/9367.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/9367.html</trackback:ping><description><![CDATA[<p>Visual C++下ACE动态服务配置入门<br />摘要：<br />   服务动态配置在编写服务端应用在有很明显的优点，本文简要介绍用visual C++ (7.1)<br />编写ACE动态服务的步骤。<br />   本文适用于ACE初学者。<br />   <br />1. 主进程</p>
		<p>1.1 创建主程序<br />    用Viusal Studio创建一空Win32 Console项目，这里命名为GLIVR86ServiceD.注，这里<br />D表示Daemon，不是Debug。表示我们以后会把这个项目改造为了NT_Service(以后介绍步骤.<br />1.2 修改项目属性 (Configuation Properties)<br />1.2.1 为项目新增主文件 GLIVR86ServiceD.cpp，目的是为项目属性中，增加C/C++选项<br />1.2.1 General 修改程序输出路径$(OutDir)<br />1.2.2.Debugging  Command Arguments: -d, 以调试模式启动<br />1.2.3 C/C++设置<br />1.2.3.1 Additional Include Directories /I[path]: $(ACE_ROOT); <br />1.2.3.2 Code Generation: /MTd ;/MT 调试版选MTd,发行版选 MT<br />1.2.3.3 Preprocessor:Preprocesor Definitions/D: WIN32;_DEBUG;_CONSOLE; <br />               这是调试版，发行版将_DEBUG改为NDEBUG<br />1.2.4 链接设置<br />1.2.4.1 Input: Additinal Dependencise: <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>(d).lib,调试版选aced.lib,<br />                                                   发行版选ace.lib<br />1.2.4.2 System: SubSystem /subsystem: Console ;   (/SUBSYSTEM:CONSOLE)</p>
		<p>主程序代码</p>
		<p>
				<br /> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@file:  GLIVR86ServiceD.cpp <br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@description:  IVR 86业务服务主程序入口<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@author: jiangtao<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@version:2.0.0</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stdafx.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">memory</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> 使用 auto_ptr</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/OS_NS_unistd.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/TP_Reactor.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/Reactor.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/Service_Config.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/Thread_Manager.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">线程池</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> ACE_THR_FUNC_RETURN event_loop (</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arg) <br />{<br />    ACE_DEBUG((LM_INFO,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">(%P|%t),event_loop()\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">));<br />    ACE_Reactor </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">reactor </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> static_cast</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">ACE_Reactor </span>
				<span style="COLOR: #000000">*&gt;</span>
				<span style="COLOR: #000000"> (arg);<br /><br />    reactor</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">owner (ACE_OS::thr_self ());<br />    reactor</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">run_reactor_event_loop ();<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">
						<br />ACE_TMAIN (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, ACE_TCHAR </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">argv[])<br />{<br />  <br />    </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> size_t N_THREADS </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">;<br />    ACE_TP_Reactor tp_reactor;<br />    ACE_Reactor reactor (</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">tp_reactor);<br />    auto_ptr</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">ACE_Reactor</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000"> delete_instance(ACE_Reactor::instance (</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">reactor));<br />   <br />     </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (ACE_Service_Config::open (argc, argv) </span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">)<br />            ACE_ERROR_RETURN ((LM_ERROR,<br />            ACE_TEXT (</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">%p\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),<br />            ACE_TEXT (</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">open</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)),<br />            </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">);<br />       <br />    ACE_Thread_Manager::instance ()</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">spawn_n<br />                 (N_THREADS, event_loop, ACE_Reactor::instance ());<br /><br />    ACE_Thread_Manager::instance ()</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">wait ();<br /><br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
		</div>
		<p>
				<br />2. 创建被加载的服务的动态链接库<br />2.1 用Visual Studio创建一个新的项目GLIVR86Service,我们依然从空白的Win32 Console开<br />始<br />1.2.1 为项目新增主文件 GLIVR86Service.cpp，目的是为项目属性中，增加C/C++选项<br />1.2.1 General : Configration Type:改为 动态链接库 Dynamic Library(DLL)<br />1.2.3.1 Additional Include Directories /I[path]: $(ACE_ROOT); <br />1.2.3.2 Code Generation: /MTd ;/MT 调试版选MTd,发行版选 MT<br />1.2.3.3 Preprocessor:Preprocesor Definitions/D: <br />                        WIN32;_DEBUG;_WINDOWS;ACE_BUILD_SVC_DLL<br />                        这是调试版，发行版将_DEBUG改为NDEBUG<br />        这里，特别注意，要增加 ACE_BUILD_SVC_DLL宏。如果用generate_export_file.pl<br />        生成自定义的export头文件，这个宏也可以自定义<br />        <br />2.2.2 链接器设置<br />2.2.2.1 Input: Additinal Dependencise: <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>(d).lib,调试版选aced.lib,<br />                                                   发行版选ace.lib<br />2.2.2.2 System: SubSystem /subsystem: Console ;   (/SUBSYSTEM:CONSOLE)<br />2.2.2.3 General ,Output file:<br />                 ../GLIVR86ServiceD/GLIVR86ServiceD/GLIVR86ServiceD.dll<br />    <br />                    这里填写上GLIVR86ServiceD的路径或环境变量Path中指<br />                    示的路径，这样可以方便调试</p>
		<p>2.2.2.4 Adanced, Import Libaray:  $(OutDir)\GLIVR86ServiceD.lib<br />                               上面是调试版，发行版可以去掉后缀D,即<br />                               $(OutDir)\GLIVR86Service.lib<br />                               <br />3.服务的动态链接库实现</p>
		<p>3.1 为项目增加两个文件，分别声明和实现服务类工厂<br /><a>//@file</a>: ServiceFactory.h<br /><a>//@file</a>: ServiceFactory.cpp<br />代码分别如下</p>
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@file: ServiceFactory.h<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@description:  IVR 86业务服务<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@author: jiangtao<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@data: 2006-7-3<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@version:1.0.0</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<br />
						<br />#ifndef SERVICEFACTORY_H<br /></span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> SERVICEFACTORY_H</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/svc_export.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/Service_Config.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/Service_Object.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<br />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">声明服务工厂</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">ACE_SVC_FACTORY_DECLARE (ServiceFactory_T)<br /><br /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> ACE_Svc_Export ServiceFactory_T : </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ACE_Service_Object<br />{<br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br />  </span>
				<span style="COLOR: #808080">///</span>
				<span style="COLOR: #008000"> Initializes object when dynamic linking occurs.</span>
				<span style="COLOR: #808080">
						<br />
				</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #0000ff">virtual</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> init (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, ACE_TCHAR </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">argv[]);<br /><br />  </span>
				<span style="COLOR: #808080">///</span>
				<span style="COLOR: #008000"> Terminates object when dynamic unlinking occurs.</span>
				<span style="COLOR: #808080">
						<br />
				</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #0000ff">virtual</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> fini (</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000">);<br /><br />  </span>
				<span style="COLOR: #808080">///</span>
				<span style="COLOR: #008000"> Returns information on a service object.</span>
				<span style="COLOR: #808080">
						<br />
				</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #0000ff">virtual</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> info (ACE_TCHAR </span>
				<span style="COLOR: #000000">**</span>
				<span style="COLOR: #000000">info_string, size_t length </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">) </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000">;<br /><br />};<br /><br /><br /></span>
				<span style="COLOR: #0000ff">#endif</span>
				<span style="COLOR: #000000"> /* SERVICEFACTORY_H */</span>
				<span style="COLOR: #000000">
						<br />
						<br />
						<br />
						<br />
				</span>
		</div>
		<p>
				<br />/*******************************************************************/<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">@file: ServiceFactory.cpp</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">ServiceFactory.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a>/Log_Msg.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">实现服务工厂</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">ACE_SVC_FACTORY_DEFINE (ServiceFactory_T)<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ServiceFactory_T::init(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, ACE_TCHAR </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">argv[])<br />{<br />    ACE_DEBUG((LM_INFO,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">(%P|%t) 服务初始化完成\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">));<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ServiceFactory_T::info(ACE_TCHAR </span>
				<span style="COLOR: #000000">**</span>
				<span style="COLOR: #000000">strp, size_t length) </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000">
						<br />{<br />    ACE_DEBUG((LM_INFO,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">ServiceFactory_T::info() \n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">));<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ServiceFactory_T::fini(</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000">)<br />{<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /><br /></span>
		</div>
		<p>
				<br />5.服务配置文件svc.conf<br />dynamic IVR86Service Service_Object * GLIVR86Service: _make_ServiceFactory_T() active <br />    <br />6. 运行结果</p>
		<p> </p><img src ="http://www.cppblog.com/ace/aggbug/9367.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-07-04 13:26 <a href="http://www.cppblog.com/ace/archive/2006/07/04/9367.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于ACE_Task::last_thread()</title><link>http://www.cppblog.com/ace/archive/2006/06/30/9225.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Fri, 30 Jun 2006 04:30:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/06/30/9225.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/9225.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/06/30/9225.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/9225.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/9225.html</trackback:ping><description><![CDATA[<div class="dateTitle">2006年06月30日</div>
		<div class="post">
				<div class="postTitle">
						<a href="http://blog.csdn.net/FocusOnACE/archive/2006/06/30/855549.aspx">
								<img height="13" src="http://blog.csdn.net/images/trans.gif" width="15" border="0" /> 关于ACE_Task::last_thread()</a>
				</div>
				<br />
				<div class="postText">
						<p>关于ACE_Task::last_thread()</p>
						<p>在ACE应用中，我们经常用ACE_Task类实现多线程处理。由于ACE_Svc_Handler从ACE_Task派生，当你写的应用程序使用了Acceptor-Connector框架同时又直接使用ACE_Task,如线程池，这时你会使用到ACE_Task。<br />因为许多ACE_Task对应是动态分配的，所以，必须在不再需要时把它们正确地释放掉,知道何时可以释放对象，这一点非常重要。C++NPv2第189页描述了当多线程涉及到的task对象在它们退出时，使用ACE_Task::thr_count()方法确定正确释放它们的方法。</p>
						<p>在C++NPv2文档中描述的过程并不不安全，这里有一个用例可以说明这一点。原因如下：</p>
						<p>ACE在调用ACE_Task::close()挂钩(hook)函数前检查线程计数。</p>
						<p>线程锁(task thread)使控制线程计数顺序化，所以不能通过调用ACE_Task::close()达到控制线程数这一目的，这是因为关闭挂勾（close hook)方法会删除task 对象。因此，多个线程检查ACE_Task:: thr_count()的值都为0是可能存在的。</p>
						<p>举例来说吧，我们假设这里有两个线程，A和B,这给都要退出。线程A从svc()方法中退出控制，同时，ACE开始线程记录保护(record-keeping)。ACE获得线程锁并把活动线程数从2减为1,接着，ACE释放线程锁并调用task的close()挂钩方法。其间，线程B也从svc()方法中退出。在线程A检查ACE_Task::thr_count()之前，ACE已执行线程B的清楚操作可能导致task的线程计数器从1变为0.如果那样，线程A和B都会看到线程计数器为0，并都试图清理task对象。这一点肯定不是好事.......</p>
						<p>发现并指出这一问题是一位长时间使用ACE的用户,Howard Finer，经过一些迭代和试验Howard找到一个解决这一问题的办法，即额外的维护线程计数器，记住到底是哪一个线程真实的把线程计数器从1变为0，（上述例子中的线程B）。这就要求ACE_Task增加一个新的方法 ：<br />ACE_thread_t ACE_Task::last_thread (void) const <br />所以，在你的代码实现ACE_Task::close()时需要包含如下的检查</p>
						<p>if (ACE_OS::thr_equal (ACE_Thread::self (),<br />                       this-&gt;last_thread ()))<br />  {<br />    // Do the cleanup here...<br />  }</p>
						<p>
								<br />这个方法可能会出现在ACE 5.5.2中。</p>
				</div>
		</div><img src ="http://www.cppblog.com/ace/aggbug/9225.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-06-30 12:30 <a href="http://www.cppblog.com/ace/archive/2006/06/30/9225.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在Linux下安装ACE菜鸟指南</title><link>http://www.cppblog.com/ace/archive/2006/06/23/8864.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Thu, 22 Jun 2006 16:19:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/06/23/8864.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/8864.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/06/23/8864.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/8864.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/8864.html</trackback:ping><description><![CDATA[<a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a> for linux的安装由于安装说明文件“ACE-INSTALL.html”中提及的linux安装过程极少，其主要针对Unix、Windows，手动配置较多，加上本人安装后感觉“ACE-INSTALL.html”文件有些影响视听，因为主要的动作都可以由ACE包中的安装脚本ACE-install.sh自动完成，我们主要的工作就可以直接对这个安装脚本来处理即可。<br /><br />1、安装环境：lRedHat 9.0 ACE安装包ACE+TAO+CIAO.tar.gz，<a href="http://deuce.doc.wustl.edu/Download.html" target="_blank"><font color="#000080">http://deuce.doc.wustl.edu/Download.html</font></a> ， "Latest Beta Kit"，beta版既是ACE的最新版。<br /><br />2、安装过程：第一步先设置ACE_ROOT环境，命令：“vi /etc/profile”<br /><br />在其中加入4行ACE_ROOT=/opt/ACE export ACE_ROOT LD_LIBRARY_PATH=$ACE_ROOT/ace：$LD_LIBRARY_PATH export LD_LIBRARY_PATH我是加在“export PATH USER…。”后的。完成后将/etc/profile执行一次，命令：“chmod 555 /etc/profile”<br /><br />“/etc/profile”<br /><br />这样我们的ACE_ROOT就设置好了，可以用如下命令查看ACE_ROOT是否设置好了：“echo $ACE_ROOT”<br /><br />这个时候最好reboot启动一次linux.第二步不要自己手工将ACE+TAO+CIAO.tar.gz包完全解开，特别强调不要完全解开，后面可以看到安装脚本会给我们解开它的；如果你手工解开全部，安装脚本将会将你的解压缩目录删除的！我们要做的事就只是将ACE+TAO+CIAO.tar.gz包中的ACE-install.sh安装脚本单独解出来，并对其修改。我们只要这一个文件就可以。<br /><br />用mkdir建目录，如/home/my/ACE，然后将你的ACE+TAO+CIAO.tar.gz放在此目录下（用cp命令拷贝或mv命令移动到此目录）。注意这个目录将是你的一个存放ACE+TAO+CIAO.tar.gz的目录，安装脚本会来这个目录找这个文件的，这个目录和ACE_ROOT是不一样的，且ACE-install.sh也提示不要将这两个目录设置成同一个目录。ACE_ROOT将是我们的安装目标目录。<br /><br />从ACE+TAO+CIAO.tar.gz解压出单个文件ACE-install.sh：“tar –zxvf <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>+TAO+CIAO.tar.gz ACE_wrappers/ACE-install.sh”<br /><br />解好后，会出来一个新的子目录“ACE_wrappers”。此时可以先将ACE-install.sh移到外面的目录来：“mv /ACE_wrappers/ACE-install.sh .”<br /><br />“。”代表当前目录。当然ACE-install.sh在什么路径下是没什么影响的，因为我们要对ACE-install.sh的内容进行修改的，里面有很多路径要修改。好，现在在/home/my/ACE就有了ACE-install.sh，我们现在用vi对其进行修改，修改前自己可以先备份一个。命令：“cp <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>-install.sh <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>-install.sh.bak”<br /><br />“vi <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a>-install.sh”<br /><br />我们可以看到缺省的，这个文件是用来在UNIX下做安装的。所以我们要将其中的有关UNIX的部分换成linux即可。<br /><br />先找到“MY_ACEDIR=${HOME}/aceconfig”，将其改成“MY_ACEDIR=/home/my/ACE”，就是改成我们自己建的、放有ACE+TAO+CIAO.tar.gz文件的目录，之后去掉前面的注释“#”号。<br /><br />接着在下面一点，找到“MY_ACE_CONFIG=config-sunos5.4-sunc++-4.x.h”，将其修改成 “MY_ACE_CONFIG=config-linux.h”，即改成linux下的配置文件。继续改，找到“MY_ACE_GNU_MACROS=platform_sunos5_sunc++.GNU”，将其改成 “MY_ACE_GNU_MACROS=platform_linux.GNU”。这个是各种操作系统平台下的GNU宏文件设置。<br /><br />好了，文件修改完毕，保存退出“：wq”。<br /><br />第三步我们的重点到了，现在就可以安装ACE了。<br /><br />此时应该是在/home/my/ACE目录下，我们执行：。/ACE-install.sh<br /><img src ="http://www.cppblog.com/ace/aggbug/8864.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-06-23 00:19 <a href="http://www.cppblog.com/ace/archive/2006/06/23/8864.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一篇很不错的ACE讲义</title><link>http://www.cppblog.com/ace/archive/2006/06/01/8046.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Thu, 01 Jun 2006 13:29:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/06/01/8046.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/8046.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/06/01/8046.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/8046.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/8046.html</trackback:ping><description><![CDATA[Overview<br />  Object Oriented Terminology<br />  <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html ">ACE</a> Wrappers<br />  Streams<br />  Message Demultiplexing<br />  Service Configuration<br />  Task and Active Objects<br /><br /><a class="" title="下载" href="http://cseminar.home.cern.ch/cseminar/1999/Gutleber/CERNtut.pdf" target="">下载</a><br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">ABSTRACT <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />1 Topic<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />The ADAPTIVE Communication Environment (ACE) is a C++ toolkit for object oriented network programming that has been developed at the Washington University of St.Louis, MI, USA by Douglas C. Schmidt. Since the early days, it addresses high performance environments, such as medical imaging, avionics and telecommunication applications. <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a> incorporates an operating system abstraction layer that facilitates porting of applications to different platforms (several UNIX flavours, WindowsNT, LynxOS and VxWorks to name but a few). On top of this layer design patterns that are common to network aware applications have been implemented. <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a> contains also a real-time CORBA implementation named TAO.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />More information on <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a> is available through the web http://www.cs.wustl.edu/~schmidt/ACE.html <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />2 Scope<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />The goal of this tutorial is to present the building blocks of the <a title="" href="http://www.cs.wustl.edu/~schmidt/ACE.html " >ACE</a> toolkit. Some patterns are highlighted, namely the streams facility, the reactor, the service configurator, and the active object. Simple examples are presented in order to illustrate the application of object oriented programming in distributed systems. The upper level frameworks, such as TAO will only be mentioned shortly by outlining their capabilities and application areas. <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />3 Duration<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Two Hours (break included) 4 Background Knowledge Attendees should have a basic knowledge of object oriented programming. As the toolkit aims at hiding complicated low level information from the application programmer, it is not required to have detailed knowledge about network protocols or operating system details. <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><img src ="http://www.cppblog.com/ace/aggbug/8046.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-06-01 21:29 <a href="http://www.cppblog.com/ace/archive/2006/06/01/8046.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE运行时的初始化和结束时的回收操作</title><link>http://www.cppblog.com/ace/archive/2006/05/16/7236.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Tue, 16 May 2006 02:20:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/05/16/7236.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/7236.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/05/16/7236.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/7236.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/7236.html</trackback:ping><description><![CDATA[<p>ACE运行时的初始化和结束时的回收操作</p>
		<p>url: <a class="" title="http://www.cppblog.com/ace" href="/ace" target="">http://www.cppblog.com/ace<br /></a></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">   <a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a> VERSION: </span>
				<span style="COLOR: #000000">5.4</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">9</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   HOST MACHINE and OPERATING SYSTEM:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       Windows XP SP1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   COMPILER NAME AND VERSION (AND PATCHLEVEL):<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       Microsoft Visual C</span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000"> .NET<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   THE $ACE_ROOT</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>
				</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">config.h FILE:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       #include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/config-win32.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   DOES THE PROBLEM AFFECT:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       EXECUTION<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   SYNOPSIS:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       In my dll <a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a> work incorrect, but </span>
				<span style="COLOR: #0000ff">in</span>
				<span style="COLOR: #000000"> exe good.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   REPEAT BY:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">正确：测试连接的简单程序</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/INET_Addr.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/SOCK_Connector.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/SOCK_Stream.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> _tmain(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, _TCHAR</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> argv[])<br /><img id="Codehighlighter1_530_963_Open_Image" onclick="this.style.display='none'; Codehighlighter1_530_963_Open_Text.style.display='none'; Codehighlighter1_530_963_Closed_Image.style.display='inline'; Codehighlighter1_530_963_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_530_963_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_530_963_Closed_Text.style.display='none'; Codehighlighter1_530_963_Open_Image.style.display='inline'; Codehighlighter1_530_963_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_530_963_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_530_963_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   std::cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Hi\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Create remote address</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">   ACE_INET_Addr server_addr;<br /><img id="Codehighlighter1_673_733_Open_Image" onclick="this.style.display='none'; Codehighlighter1_673_733_Open_Text.style.display='none'; Codehighlighter1_673_733_Closed_Image.style.display='inline'; Codehighlighter1_673_733_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_673_733_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_673_733_Closed_Text.style.display='none'; Codehighlighter1_673_733_Open_Image.style.display='inline'; Codehighlighter1_673_733_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( server_addr.</span>
						<span style="COLOR: #0000ff">set</span>
						<span style="COLOR: #000000">( </span>
						<span style="COLOR: #000000">1234</span>
						<span style="COLOR: #000000">, INADDR_LOOPBACK ) </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> ) </span>
						<span id="Codehighlighter1_673_733_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_673_733_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       std::cout </span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Bad address\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Create connection</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">   ACE_SOCK_Connector connector;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   ACE_SOCK_Stream connection;<br /><img id="Codehighlighter1_881_947_Open_Image" onclick="this.style.display='none'; Codehighlighter1_881_947_Open_Text.style.display='none'; Codehighlighter1_881_947_Closed_Image.style.display='inline'; Codehighlighter1_881_947_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_881_947_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_881_947_Closed_Text.style.display='none'; Codehighlighter1_881_947_Open_Image.style.display='inline'; Codehighlighter1_881_947_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (connector.connect (connection, server_addr) </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)  </span>
						<span id="Codehighlighter1_881_947_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_881_947_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       std::cout </span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Connection failed\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">不正确：放在Dll项目中的代码片断</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/INET_Addr.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/SOCK_Connector.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/SOCK_Stream.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />BOOL APIENTRY DllMain( HANDLE hModule,<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                      DWORD  ul_reason_for_call,<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                      LPVOID lpReserved<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />                                        )<br /><img id="Codehighlighter1_1246_1465_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1246_1465_Open_Text.style.display='none'; Codehighlighter1_1246_1465_Closed_Image.style.display='inline'; Codehighlighter1_1246_1465_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1246_1465_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1246_1465_Closed_Text.style.display='none'; Codehighlighter1_1246_1465_Open_Image.style.display='inline'; Codehighlighter1_1246_1465_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1246_1465_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1246_1465_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
						<span style="COLOR: #0000ff">switch</span>
						<span style="COLOR: #000000"> (ul_reason_for_call)<br /><img id="Codehighlighter1_1290_1447_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1290_1447_Open_Text.style.display='none'; Codehighlighter1_1290_1447_Closed_Image.style.display='inline'; Codehighlighter1_1290_1447_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1290_1447_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1290_1447_Closed_Text.style.display='none'; Codehighlighter1_1290_1447_Open_Image.style.display='inline'; Codehighlighter1_1290_1447_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />       </span>
						<span id="Codehighlighter1_1290_1447_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1290_1447_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">case</span>
								<span style="COLOR: #000000"> DLL_PROCESS_ATTACH:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">case</span>
								<span style="COLOR: #000000"> DLL_THREAD_ATTACH:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">case</span>
								<span style="COLOR: #000000"> DLL_THREAD_DETACH:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">case</span>
								<span style="COLOR: #000000"> DLL_PROCESS_DETACH:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />               </span>
								<span style="COLOR: #0000ff">break</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />       }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> TRUE;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> test()<br /><img id="Codehighlighter1_1479_1804_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1479_1804_Open_Text.style.display='none'; Codehighlighter1_1479_1804_Closed_Image.style.display='inline'; Codehighlighter1_1479_1804_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1479_1804_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1479_1804_Closed_Text.style.display='none'; Codehighlighter1_1479_1804_Open_Image.style.display='inline'; Codehighlighter1_1479_1804_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1479_1804_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1479_1804_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Create remote address</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">   ACE_INET_Addr server_addr;<br /><img id="Codehighlighter1_1596_1618_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1596_1618_Open_Text.style.display='none'; Codehighlighter1_1596_1618_Closed_Image.style.display='inline'; Codehighlighter1_1596_1618_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1596_1618_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1596_1618_Closed_Text.style.display='none'; Codehighlighter1_1596_1618_Open_Image.style.display='inline'; Codehighlighter1_1596_1618_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> ( server_addr.</span>
						<span style="COLOR: #0000ff">set</span>
						<span style="COLOR: #000000">( </span>
						<span style="COLOR: #000000">1234</span>
						<span style="COLOR: #000000">, INADDR_LOOPBACK ) </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> ) </span>
						<span id="Codehighlighter1_1596_1618_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1596_1618_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Create connection</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">   ACE_SOCK_Connector connector;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   ACE_SOCK_Stream connection;<br /><img id="Codehighlighter1_1766_1788_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1766_1788_Open_Text.style.display='none'; Codehighlighter1_1766_1788_Closed_Image.style.display='inline'; Codehighlighter1_1766_1788_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1766_1788_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1766_1788_Closed_Text.style.display='none'; Codehighlighter1_1766_1788_Open_Image.style.display='inline'; Codehighlighter1_1766_1788_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (connector.connect (connection, server_addr) </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)  </span>
						<span id="Codehighlighter1_1766_1788_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1766_1788_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p>
				<br />
				<strong>
						<font style="BACKGROUND-COLOR: #7fffd4">如果我从dll中调用 test()函数，函数返回2...</font>
				</strong>
		</p>
		<p>========================<br />解答:<br /><br />平台不同及兼容性问题的一个特殊地方是运行时对象的初始化和程序退出时与那相类象相关的析构操作。这种不同尤其表现在包含有多线程的时候，这是因为编译器没有附加的能力来顺序访问那些有先后之分的运行时对象（静态数据）的自动初始化和析构的方法。因此ACE说的一句话"静态是邪恶的"，幸运的是，ACE提供了一种可移植的解决方案来解决对象初始化和析构的问题。</p>
		<p>如果你的程序不是从标准的main()开始的，你需要在初始化和结束时用到对象管理器。你需要调用下面两个函数：</p>
		<p>
				<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>::init() 在其它ACE操作之行前初始化对象管理器。</p>
		<p>
				<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>::fini() 在你的ACE操作完成后，结束对象管理器。这个调用将触发注册在对象管理器中所有对象的clearup操作。</p>
		<p>这对于Windows程序来说可能很要紧，因为Windows程序使有WinMain()好过于标准的main()函数，在库中使用ACE但用户找不到主程序入口。对于库来说，为库分别提供初始化结束化函数来分别调用ACE::init(）和ACE::fini()是非常有用的。</p><img src ="http://www.cppblog.com/ace/aggbug/7236.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-05-16 10:20 <a href="http://www.cppblog.com/ace/archive/2006/05/16/7236.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE Proactor vs Reactor (试译)</title><link>http://www.cppblog.com/ace/archive/2006/05/12/6996.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Fri, 12 May 2006 04:22:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/05/12/6996.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/6996.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/05/12/6996.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/6996.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/6996.html</trackback:ping><description><![CDATA[<p>
				<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a> Proactor vs Reactor (试译)</p>
		<p>编译：Stone Jiang <br />url: <a href="/ace">http://www.cppblog.com/ace</a></p>
		<p>
				<br />Ephy Levy 问到：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">大家好，我正在Windows平台上使用ACE 5.5。在我所服务的公司里，我已<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />编写了一个ACE的包装体，这个包装体是服务程序的基础。我阅读了《ACE程序员指南》。在这本书中，ACE Reactor 和 Proactor 都作了解释。我们的服务器要求能同时接受1000左右的连接。我的问题是：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />-那种模式更适合我的需要？<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />(我想使用Proactor，因为Reactor在连接数上有限制——是这样的吗？)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />-如果我使用Proactor模式，那我怎样通过完成端口利用CPU数量呢？<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />非常感谢您的帮助？<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Ephy Levy.</span>
		</div>
		<p> </p>
		<p>hi,Ephy Levy.</p>
		<p>
				<font color="#0066ff">
						<em>@(我想使用Proactor，因为Reactor在连接数上有限制——是这样的吗？)</em>
				</font>
				<br />这点您对了一半。如果您使用 ACE_WFMO_Reactor，它限制在64个处理器(handler)上，也就是在一个线程上可以承载大约60个并发的连接。</p>
		<p>这是因为，ACE_WFMO_Reactor是基于WIN32 API::WaitForMultipileObjects的。</p>
		<p>另一方面，您可以使用ACE_Select_Reactor，它可以配置为支持1000甚至更从的连接支持。（显示，它是基于 ::select的）</p>
		<p>我更倾向于使用ACE_Proactor，在并发连接数上它不受限制，并且还可以在一个线程中组合使用Pipe,Socket和文件访问。</p>
		<p>还有，ACE_WIN32_Proactor是基于完成端口的，这意味着是同步的架构，它相比于Reactor模式来说有更好的性能和吞吐能力。</p>
		<p>
				<br />
				<em>
						<font color="#0066ff">@-如果我使用Proactor模式，那我怎样通过完成端口利用CPU数量呢？</font>
				</em>
		</p>
		<p>为了更充分的利用您的计算机性强大的处理能力，您可以在多线程中使用ACE_WIN32_Proactor。接下来是您需求正确的使用同步机制来避免并发访问共享对象时的问题。</p>
		<p>Ishay Green<br /></p><img src ="http://www.cppblog.com/ace/aggbug/6996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-05-12 12:22 <a href="http://www.cppblog.com/ace/archive/2006/05/12/6996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>socket编程：SO_REUSEADDR例解 (转)</title><link>http://www.cppblog.com/ace/archive/2006/04/29/6446.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Sat, 29 Apr 2006 01:40:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/29/6446.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/6446.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/29/6446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/6446.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/6446.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: socket编程：SO_REUSEADDR例解                                             kevintz 2000-6-19     网友vmstat多次提出了这个问题：SO_REUSEADDR有什么用处和怎么使用。而且很多网友在编写网络程序时也会遇到这个问题。所以特意写了这么一篇文章，希望能够解答一些人的疑难。     其实这个问题在Richard ...&nbsp;&nbsp;<a href='http://www.cppblog.com/ace/archive/2006/04/29/6446.html'>阅读全文</a><img src ="http://www.cppblog.com/ace/aggbug/6446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-29 09:40 <a href="http://www.cppblog.com/ace/archive/2006/04/29/6446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC6+stlport编译ACE库Release版出现的问题解决办法 (转)</title><link>http://www.cppblog.com/ace/archive/2006/04/25/6225.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Tue, 25 Apr 2006 01:32:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/25/6225.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/6225.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/25/6225.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/6225.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/6225.html</trackback:ping><description><![CDATA[<!--StartFragment --> 
<h3 class="storytitle"><a href="http://wolf.bloghome.cn/posts/5013">VC6+stlport编译ACE库Release版出现的问题解决办法</a></h3><div class="meta"><ul class="post-categories"><li><a title="这块我可是个新手了，不过已经会使用并理解ACE的模式，其他也多少有些了解与理解。" href="http://wolf.bloghome.cn/post_categories/2310">网络中间件平台（ACE / ICE / CORBA / J2EE / COM+ &amp; .net / ZOPE &amp; PLONE）</a></li></ul>作者 alvin_lee @ 2005-06-08 08:33:57 </div><div class="storycontent">　　不知道有没有人遇到过，我在VC6.0+STLPORT-4.6.2的环境下编译ACE version 5.4.3的Release版本，编译器报内部错误C1001: INTERNAL COMPILER ERROR。后来在google上找了些国外的论坛，大概都是说是预编译头的问题，后来摸索了下搞定了。 <br /><br /><p>　　在编译的时候出现如下错误提示：</p><p><b>Message_Block.cpp<br />E:MYPERSONALSTLPORT-4.6.2STLPORTstl/type_traits.h(68) : fatal error <br /><br />C1001: INTERNAL COMPILER ERROR<br />(compiler file ''msc1.cpp'', line 1794) <br />Please choose the Technical Support command on the Visual C++ <br />Help menu, or open the Technical Support help file for more information</b></p><p>　　这显然是编译器出了问题。然而在编译Debug版本却不会出现，说明Debug与Release版的头文件组织的结构不一样，经过反复琢磨发现如下解决办法。</p><p>　　打开ACE_wrappersace目录下的Message_Block.cpp文件：</p><p> </p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/Log_Msg.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/Malloc_Base.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/Guard_T.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/OS_NS_string.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">#define ACE_ENABLE_TIMEPROBES</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/Timeprobe.h</span><span style="COLOR: #000000">"</span></div><p><br /><br />　　把包含的Log_Msg.h的头放到Guard_T.h后面，就ok了。还有问题的话，再往下调整。</p></div><img src ="http://www.cppblog.com/ace/aggbug/6225.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-25 09:32 <a href="http://www.cppblog.com/ace/archive/2006/04/25/6225.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 简单讲解ACE_SOCK Wrapper Class的使用(原创)</title><link>http://www.cppblog.com/ace/archive/2006/04/20/5987.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Thu, 20 Apr 2006 15:50:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/20/5987.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5987.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/20/5987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5987.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5987.html</trackback:ping><description><![CDATA[<h1> 简单讲解ACE_SOCK Wrapper Class的使用</h1>
Stone Jiang<br /><a target="" class="" title="" href="/ace">http://www.cppblog.com/ace</a><br /><br /><br />
我们先来看一个场景:<br />
您去一家餐馆吃饭,这家餐馆位置就在水木清华街23号；您得事先知道餐馆的位置，从门进入，如果你想破墙而入那是不允可的。当你进门后，餐馆会有一位领位员招呼你，领位员会安排一个服务员为你提供服务的，你可以向服务员点菜，或听取服务员的推荐。用餐后你离开餐馆。<br /><br />
利用ACE SOCK编程，与上馆子极其相似。我们来作一个对比。<br />
餐馆的位置，嗯，计算机上，我们是IP地址，水木清华我们对应的是 smth.org,它的门牌号呢，对应的是我们的端口地址，在ACE中，我们用ACE_INET_Addr来表示。<br />
即，<br />
ACE_INET_Addr peer_addr;<br />
peer_addr;.set(23,"smth.org");<br />
我们也可以直接通过它的带参数的构造函数来声明和初始化，<br />
ACE_INET_Addr peer_addr(23,"smth.org")<br /><br />
餐馆的领位员相当于 ACE_SOCK_Acceptor,它被动的站在站口等着客户的到来，您作为客户，是主动端，ACE_SOCK_Connector则是您将在代码中看到的。<br /><br />
ACE面向连接的网络编程，有三个主要的角色<br />
主动端,被动端和数据交流的通道，即<br />
ACE_SOCK_Acceptor, ACE_SOCK_Connector和ACE_SOCK_Stream<br /><br />
接收和发送数据，则通过 ACE_SOCK_Stream::recv(...)和send(...)完成，本例演示了接收时的调用。<br /><br />
完成数据交互之后，ACE_SOCK_Stream::close()完成断开连接操作。 这相当于买单走人。<br /><br />
注：smth.org:23是水木清华Telnet服务，您还可以通过<br />
telnet smth.org来访问。<br /><br />
下面是完整代码示例 VC 7.1下调试通过<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">@file: mybrowser.cpp<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">       Main function<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">@auth: Stone Jiang &lt;2005119@gmail.com&gt;<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">@date: 2006-4-20</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><a title="ac" href="http://www.cs.wustl.edu/%7Eschmidt/ACE.html">ace</a>/Log_Msg.h</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><a title="ac" href="http://www.cs.wustl.edu/%7Eschmidt/ACE.html">ace</a>/SOCK_Connector.h</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><a title="ac" href="http://www.cs.wustl.edu/%7Eschmidt/ACE.html">ace</a>/SOCK_Stream.h</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><a title="ac" href="http://www.cs.wustl.edu/%7Eschmidt/ACE.html">ace</a>/INET_Addr.h</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /><br /><br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> ACE_TMAIN(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> argc, ACE_TCHAR</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> argv[])<br />{<br />  ACE_DEBUG((LM_DEBUG,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">start here\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /><br />  </span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> server_hostname </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">smth.org</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><br />  ACE_SOCK_Connector connector;<br />  ACE_SOCK_Stream peer;<br />  ACE_INET_Addr peer_addr;<br />  </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> buf[</span><span style="color: rgb(0, 0, 0);">64</span><span style="color: rgb(0, 0, 0);">]</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">};<br /><br />  </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(peer_addr.</span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">23</span><span style="color: rgb(0, 0, 0);">,server_hostname) </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />  {<br />     ACE_ERROR_RETURN((LM_DEBUG,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">(%P|%t) %p\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />                 </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Set server host</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br /><br />  }<br />  </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(connector.connect(peer,peer_addr) </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />  {<br />    ACE_ERROR_RETURN((LM_DEBUG,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">(%P|%t) %p\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />      </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Connection</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">),</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br /><br />  }<br />  ACE_DEBUG((LM_DEBUG,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">建立连接成功 \n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />  </span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> s </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">64</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">10</span><span style="color: rgb(0, 0, 0);">;<br />  </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> m </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />  </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(ssize_t n; (n </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> peer.recv(buf,</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);"> buf))</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;)<br />  {<br />    <br />    <a title="ac" href="http://www.cs.wustl.edu/%7Eschmidt/ACE.html">ace</a>::write_n(ACE_STDOUT,buf,n);<br />    m </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> n;<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( m </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> s)<br />    {<br />      </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />    }<br />  }<br />  peer.close();<br /><br />  </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}</span></div><br /><br /><br /><br /><img src ="http://www.cppblog.com/ace/aggbug/5987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-20 23:50 <a href="http://www.cppblog.com/ace/archive/2006/04/20/5987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>巧用虚友元函数(原创)</title><link>http://www.cppblog.com/ace/archive/2006/04/17/5796.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Mon, 17 Apr 2006 14:12:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/17/5796.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5796.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/17/5796.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5796.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5796.html</trackback:ping><description><![CDATA[<p>父类的友元不会自动成为子类的友元；而且友元会破坏封装；C++的语方不允许（非成员）友元函数为虚函数。<br />但是，某些时候，必须通过友元才能实现一些操作符重载，如operator&lt;&lt;()；如果为每个子类都实现operator&lt;&lt;()倒是一个可行的方法，但是显得很啰嗦。<br /><br />如果能把友元定义为虚函数，则子类可以继承该友元的接口而无需重复声明友好那该多好啊？<br />本文则通过一种变通的方法巧妙达到虚函数的效果。<br /><br />//基类 Base.</p>
		<br />
		<br />
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#pragma once<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> Base<br /><img id="Codehighlighter1_65_249_Open_Image" onclick="this.style.display='none'; Codehighlighter1_65_249_Open_Text.style.display='none'; Codehighlighter1_65_249_Closed_Image.style.display='inline'; Codehighlighter1_65_249_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_65_249_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_65_249_Closed_Text.style.display='none'; Codehighlighter1_65_249_Open_Image.style.display='inline'; Codehighlighter1_65_249_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_65_249_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_65_249_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  Base(</span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
						<span style="COLOR: #000000">~</span>
						<span style="COLOR: #000000">Base(</span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> print(ostream</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> output) </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  friend ostream</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">operator</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">(ostream</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> output,Base</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> obj);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> name_;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> age_;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;</span>
		</div>
		<br />基类的实现 base.cpp<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">StdAfx.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.\base.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Base::Base(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_59_101_Open_Image" onclick="this.style.display='none'; Codehighlighter1_59_101_Open_Text.style.display='none'; Codehighlighter1_59_101_Closed_Image.style.display='inline'; Codehighlighter1_59_101_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_59_101_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_59_101_Closed_Text.style.display='none'; Codehighlighter1_59_101_Open_Image.style.display='inline'; Codehighlighter1_59_101_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_59_101_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_59_101_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  name_ </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">This is data1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  age_ </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">18</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Base::</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Base(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_122_124_Open_Image" onclick="this.style.display='none'; Codehighlighter1_122_124_Open_Text.style.display='none'; Codehighlighter1_122_124_Closed_Image.style.display='inline'; Codehighlighter1_122_124_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_122_124_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_122_124_Closed_Text.style.display='none'; Codehighlighter1_122_124_Open_Image.style.display='inline'; Codehighlighter1_122_124_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_122_124_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_122_124_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Base::print(ostream</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> output)<br /><img id="Codehighlighter1_161_230_Open_Image" onclick="this.style.display='none'; Codehighlighter1_161_230_Open_Text.style.display='none'; Codehighlighter1_161_230_Closed_Image.style.display='inline'; Codehighlighter1_161_230_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_161_230_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_161_230_Closed_Text.style.display='none'; Codehighlighter1_161_230_Open_Image.style.display='inline'; Codehighlighter1_161_230_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_161_230_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_161_230_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  output</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">name = </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">name_</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  output</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">age = </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">age_</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ostream</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">(ostream</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> output,Base</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> obj)<br /><img id="Codehighlighter1_280_320_Open_Image" onclick="this.style.display='none'; Codehighlighter1_280_320_Open_Text.style.display='none'; Codehighlighter1_280_320_Closed_Image.style.display='inline'; Codehighlighter1_280_320_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_280_320_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_280_320_Closed_Text.style.display='none'; Codehighlighter1_280_320_Open_Image.style.display='inline'; Codehighlighter1_280_320_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_280_320_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_280_320_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  obj.print(output);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> output;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br /><br />派生类的 Derived.h<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#pragma once<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Base.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Derived :</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Base<br /><img id="Codehighlighter1_58_175_Open_Image" onclick="this.style.display='none'; Codehighlighter1_58_175_Open_Text.style.display='none'; Codehighlighter1_58_175_Closed_Image.style.display='inline'; Codehighlighter1_58_175_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_58_175_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_58_175_Closed_Text.style.display='none'; Codehighlighter1_58_175_Open_Image.style.display='inline'; Codehighlighter1_58_175_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_58_175_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_58_175_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  Derived(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> score </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">80</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Derived(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> print(ostream</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> output);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> score_;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br />派生类的实现 Derived.cpp<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">StdAfx.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.\derived.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Derived::Derived(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> score):score_(score)<br /><img id="Codehighlighter1_87_92_Open_Image" onclick="this.style.display='none'; Codehighlighter1_87_92_Open_Text.style.display='none'; Codehighlighter1_87_92_Closed_Image.style.display='inline'; Codehighlighter1_87_92_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_87_92_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_87_92_Closed_Text.style.display='none'; Codehighlighter1_87_92_Open_Image.style.display='inline'; Codehighlighter1_87_92_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_87_92_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_87_92_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Derived::</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Derived(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_119_121_Open_Image" onclick="this.style.display='none'; Codehighlighter1_119_121_Open_Text.style.display='none'; Codehighlighter1_119_121_Closed_Image.style.display='inline'; Codehighlighter1_119_121_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_119_121_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_119_121_Closed_Text.style.display='none'; Codehighlighter1_119_121_Open_Image.style.display='inline'; Codehighlighter1_119_121_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_119_121_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_119_121_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Derived::print(ostream</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> output)<br /><img id="Codehighlighter1_161_222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_161_222_Open_Text.style.display='none'; Codehighlighter1_161_222_Closed_Image.style.display='inline'; Codehighlighter1_161_222_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_161_222_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_161_222_Closed_Text.style.display='none'; Codehighlighter1_161_222_Open_Image.style.display='inline'; Codehighlighter1_161_222_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_161_222_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_161_222_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  Base::print(output);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  output</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">score = </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">score_</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br /><br />主程序main.cpp<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Test_VirtualFirendFunction.cpp : Defines the entry point for the console application.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">//<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">stdafx.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Derived.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> _tmain(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, _TCHAR</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> argv[])<br /><img id="Codehighlighter1_212_286_Open_Image" onclick="this.style.display='none'; Codehighlighter1_212_286_Open_Text.style.display='none'; Codehighlighter1_212_286_Closed_Image.style.display='inline'; Codehighlighter1_212_286_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_212_286_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_212_286_Closed_Text.style.display='none'; Codehighlighter1_212_286_Open_Image.style.display='inline'; Codehighlighter1_212_286_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_212_286_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_212_286_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  Derived  d;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  Derived  d2(</span><span style="COLOR: #000000">90</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">d2</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br />屏幕输入结果<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">name = This is data1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />age = 18<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />score = 80<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />name = This is data1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />age = 18<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />score = 90<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><p>结果：<br />任何从Base派生类的，都可以利用cout&lt;&lt;obj的机制通过流进行输出。<br /><br />同样道理，也可以利用此方法实现ACE_InputCDR  / ACE_OutputCDR对网络操作序列化操作。<br />(本文也是回答某网友关于派生类不能重载的问题的回复)</p><img src ="http://www.cppblog.com/ace/aggbug/5796.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-17 22:12 <a href="http://www.cppblog.com/ace/archive/2006/04/17/5796.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用ACE静态服务配置实现简单的Echo服务</title><link>http://www.cppblog.com/ace/archive/2006/04/17/5747.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Mon, 17 Apr 2006 05:55:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/17/5747.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5747.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/17/5747.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5747.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5747.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 用ACE静态服务配置实现简单的Echo服务Stone Jiang (HuiHoo ace)本例完善了AGP中的示例用ACE写静态服务配置与写动态服务配置一样简单.本例实际了一个简单的Echo服务.还包含了如何从ini文件中读取服务配置ACE静态服务配置演示  示例说明    完善了AGP中19章的例子    演示了如何用ACE实现静态服务配置  项目文件    HA_Status.h/cpp 服务...&nbsp;&nbsp;<a href='http://www.cppblog.com/ace/archive/2006/04/17/5747.html'>阅读全文</a><img src ="http://www.cppblog.com/ace/aggbug/5747.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-17 13:55 <a href="http://www.cppblog.com/ace/archive/2006/04/17/5747.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Q&amp;A: 请问ACE_Reactor::instance()的具体含义是什么?</title><link>http://www.cppblog.com/ace/archive/2006/04/15/5607.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Sat, 15 Apr 2006 04:06:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/15/5607.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5607.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/15/5607.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5607.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5607.html</trackback:ping><description><![CDATA[有网友这样问道:请问ACE_Reactor::instance()的具体含义是什么?

下面是我的回复

请问ACE_Reactor::instance()的具体含义是什么?

这是找回单体类实例的方法。详细可参考设计模式Singleton

打个比方，

引用：
--------------------------------------------------------------------------------

SINGLETON-俺有6个漂亮的老婆，她们的老公都是我，我就是我们家里的老公Sigleton，她们只要说道"老公"，都是指的同一个人，那就是我(­刚才做了个梦啦，哪有这么好的事) 


单例模式：单例模式确保某一个类只有一个实例，而且自行实例化并向整个系统提供这个实例单例模式。单例模式只应在有真正的"单一实例"的需求时才可使用。 



--------------------------------------------------------------------------------<img src ="http://www.cppblog.com/ace/aggbug/5607.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-15 12:06 <a href="http://www.cppblog.com/ace/archive/2006/04/15/5607.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转: UDP实现可靠文件传输 (转)</title><link>http://www.cppblog.com/ace/archive/2006/04/13/5465.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Thu, 13 Apr 2006 05:56:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/13/5465.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5465.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/13/5465.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5465.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5465.html</trackback:ping><description><![CDATA[<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">                                     <br /><br />用UDP实现可靠文件传输<br /><br /><br />大家都清楚，如果用TCP传输文件的话，是很简单的，根本都不用操心会丢包，除非是网络坏了，就得重来。用UDP的话，因为UDP是不可靠的，所以用它传输文件，要保证不丢包，就得我们自己写额外的代码来保障了。本文就说说如果保证可靠传输。<br /><br /><br />   要实现无差错的传输数据，我们可以采用重发请求（ARQ）协议，它又可分为连续ARQ协议、选择重发ARQ协议、滑动窗口协议。本文重点介绍滑动窗口协议，其它的两种有兴趣的可参考相关的网络通信之类的书。<br /><br /><br />    采用滑动窗口协议，限制已发送出去但未被确认的数据帧的数目。循环重复使用已收到的那些数据帧的序号。具体实现是在发送端和接收端分别设定发送窗口和接收窗口。<br /><br /><br /> （1）发送窗口<br /><br /><br />  发送窗口用来对发送端进行流量控制。发送窗口的大小Wt代表在还没有收到对方确认的条件下，发送端最多可以发送的数据帧的个数。具体意思请参考下图：<br /><br /><br /> （2）接收窗口<br /><br /><br />  接收窗口用来控制接收数据帧。只有当接收到的数据帧的发送序号落在接收窗口内，才允许将该数据帧收下，否则一律丢弃。接收窗口的大小用Wr来表示，在连续ARQ协议中，Wr = 1。接收窗口的意义可参考下图：<br /><br /><br />  在接收窗口和发送窗口间存在着这样的关系：接收窗口发生旋转后，发送窗口才可能向前旋转，接收窗口保持不动时，发送窗口是不会旋转的。这种收发窗口按如此规律顺时钟方向不断旋转的协议就犯法为滑动窗口协议。<br /><br /><br />   好了，在上面对滑动窗口协议有大致了解后，我们还是进入正题吧：）<br /><br /><br />   发送端的发送线程：<br /><br /><br />   int  ret;<br /><br /><br />   int  nPacketCount = 0;<br /><br /><br />   DWORD dwRet;<br /><br /><br />   SendBuf sendbuf;<br /><br /><br />   DWORD dwRead;<br /><br /><br />   DWORD dwReadSize;<br /><br /><br /><br /><br />   SendBuf* pushbuf;<br /><br /><br /><br /><br />   //计算一共要读的文件次数，若文件已读完，但客户端没有接收完，<br /><br /><br />   //则要发送的内容不再从文件里读取，而从m_bufqueue里提取<br /><br /><br />   nPacketCount = m_dwFileSize / sizeof(sendbuf.buf);<br /><br /><br /><br /><br />  //若不能整除，则应加1<br /><br /><br />  if(m_dwFileSize % sizeof(sendbuf.buf) != 0)<br /><br /><br />     ++nPacketCount;<br /><br /><br /> SetEvent(m_hEvent);<br /><br /> <br /><br /><br /><br /><br />  CHtime htime;<br /><br /><br /><br /><br />  //若已发送大小小于文件大小并且发送窗口前沿等于后沿，则继续发送<br /><br /><br />  //否则退出循环<br /><br /><br /><br /><br /> if(m_dwSend </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000"> m_dwFileSize</span>
				<span style="COLOR: #ff0000">)  // 文件没有传输完时才继续传输<br /><br /><br /> {<br /><br /><br />  while(1)<br /><br /><br />  {<br /><br /><br />   dwRet </span>
				<span style="COLOR: #0000ff">= WaitForSingleObject(m_hEvent, </span>
				<span style="COLOR: #ff0000">1000);<br /><br /><br />   if(dwRet </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">WAIT_FAILED)<br /><br /><br />   {<br /><br /><br />    return false;<br /><br /><br />   }<br /><br /><br />   else if(dwRet </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">WAIT_TIMEOUT)<br /><br /><br />   {<br /><br /><br />    //重发<br /><br /><br />    ::EnterCriticalSection(&amp;m_csQueue);  // 进入m_bufqueue的排斥区<br /><br /><br />    ret </span>
				<span style="COLOR: #0000ff">= m_hsocket.hsendto((char*)m_bufqueue.front(), </span>
				<span style="COLOR: #ff0000">sizeof(sendbuf));<br /><br /><br />    ::LeaveCriticalSection(&amp;m_csQueue);  // 退出m_bufqueue的排斥区<br /><br /><br />    if(ret </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">SOCKET_ERROR)<br /><br /><br />    {<br /><br /><br />     cout &lt;&lt; "重发失败，继续重发" &lt;&lt; endl;<br /><br /><br />     continue;<br /><br /><br />    }<br /><br /><br />   ResetEvent(m_hEvent);<br /><br /> <br /><br /><br />    continue;<br /><br /><br />   }<br /><br /><br />  //若发送窗口大小 &lt; 预定大小 &amp;&amp; 已读文件次数(nReadIndex) &lt; 需要读文件的次数(nReadCount)，则继续读取发送<br /><br /> <br /><br /><br />   //否则，要发送的内容从m_bufqueue里提取<br /><br /><br />   if(m_dwSend &lt; m_dwFileSize)<br /><br /><br />   {<br /><br /><br />    dwReadSize </span>
				<span style="COLOR: #0000ff">= m_dwFileSize </span>
				<span style="COLOR: #ff0000">- m_dwSend;<br /><br /><br />    dwReadSize </span>
				<span style="COLOR: #0000ff">= dwReadSize </span>
				<span style="COLOR: #ff0000">&lt; MAXBUF_SIZE ?   dwReadSize :MAXBUF_SIZE;<br /><br /><br /><br /><br />    memset(sendbuf.buf, 0, sizeof(sendbuf.buf));<br /><br /><br />    if(!ReadFile(m_hFile, sendbuf.buf, dwReadSize, &amp;dwRead, NULL))<br /><br /><br />    {<br /><br /><br />     //AfxMessageBox("读取文件失败,请确认文件存在或有读取权限.");<br /><br /><br />     cout &lt;&lt; "读取文件失败,请确认文件存在或有读取权限." &lt;&lt; endl;<br /><br /><br />     return false;<br /><br /><br />    }<br /><br /><br /><br /><br />    m_dwSend +</span>
				<span style="COLOR: #0000ff">= dwRead;<br /><br /><br /><br /><br />    </span>
				<span style="COLOR: #ff0000">sendbuf.index </span>
				<span style="COLOR: #0000ff">= m_nSendIndexHead;<br /><br /><br />    </span>
				<span style="COLOR: #ff0000">// 发送窗口前沿向前移一格     m_nSendIndexHead </span>
				<span style="COLOR: #0000ff">= (m_nSendIndexHead </span>
				<span style="COLOR: #ff0000">+ 1) %   Sliding_Window_Size; <br /><br /><br /><br /><br />  sendbuf.dwLen </span>
				<span style="COLOR: #0000ff">= dwRead;<br /><br /> <br /><br /><br />  </span>
				<span style="COLOR: #ff0000">//保存发送过的数据，以便重发<br /><br /> <br /><br /><br />   ::EnterCriticalSection(&amp;m_csQueue);   // 进入m_bufqueue的排斥区<br /><br /><br />   pushbuf </span>
				<span style="COLOR: #0000ff">= GetBufFromLookaside();<br /><br /><br />   </span>
				<span style="COLOR: #ff0000">memcpy(pushbuf, &amp;sendbuf, sizeof(sendbuf));<br /><br /><br /><br />   m_bufqueue.push(pushbuf);<br /><br /><br /><br />   // 文件已读完，在队列中加一File_End标志，以便判断是否需要继续发送    if(m_dwSend </span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">= m_dwFileSize)    <br /><br /><br /><br />   {<br /><br /><br />     pushbuf = GetBufFromLookaside();<br /><br /><br />    pushbuf-&gt;index = File_End;<br /><br /> <br /><br /><br />     pushbuf-&gt;dwLen = File_End;<br /><br /><br />     memset(pushbuf-&gt;buf, 0, sizeof(pushbuf-&gt;buf));<br /><br /><br />     m_bufqueue.push(pushbuf);<br /><br /><br /><br />    }<br /><br /><br />    ::LeaveCriticalSection(</span>
				<span style="COLOR: #ff0000">&amp;m_csQueue</span>
				<span style="COLOR: #000000">);   // 退出m_bufqueue的排斥区<br /><br /><br />   }<br /><br /><br />   ::EnterCriticalSection(</span>
				<span style="COLOR: #ff0000">&amp;m_csQueue</span>
				<span style="COLOR: #000000">);    // 进入m_bufqueue的排斥区<br /><br /> <br /><br /><br />   // 所有数据包已发送完毕,退出循环    if(m_bufqueue.front()-&gt;index == File_End)  <br /><br /><br /><br />   {<br /><br /><br />     ::LeaveCriticalSection(</span>
				<span style="COLOR: #ff0000">&amp;m_csQueue</span>
				<span style="COLOR: #000000">);   // 退出m_bufqueue的排斥区<br /><br /><br />     break;<br /><br /><br />   }<br /><br /><br />   // 发送窗口小于指定值，继续发送    else if(m_bufqueue.size() </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">= Send_Window_Size</span>
				<span style="COLOR: #ff0000">) <br /><br /><br /><br />   {<br /><br /><br />    ret </span>
				<span style="COLOR: #0000ff">= m_hsocket.hsendto((char*)m_bufqueue.front(), </span>
				<span style="COLOR: #ff0000">sizeof(sendbuf));<br /><br /><br />    if(ret </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">SOCKET_ERROR)<br /><br /><br />    {<br /><br /><br />     ::LeaveCriticalSection(&amp;m_csQueue);  // 退出m_bufqueue的排斥区<br /><br /><br />     cout &lt;&lt; "发送失败，重发" &lt;&lt; endl;<br /><br /><br />     continue;<br /><br /><br />    }<br /><br /><br /><br /><br />    //延时，防止丢包<br /><br /><br />    Sleep(50);  <br /><br /><br />   }<br /><br /><br />   else           // 发送窗口大于指定值，等持接收线程接收确认消息<br /><br /><br />   {<br /><br /><br />    ResetEvent(m_hEvent);<br /><br /><br />   }<br /><br /><br />   ::LeaveCriticalSection(&amp;m_csQueue);    // 退出m_bufqueue的排斥区<br /><br /><br />  }<br /><br /><br /> }<br /><br /><br />  发送端的接收线程：<br /><br /><br /><br />  int ret;<br /><br /><br />  RecvBuf recvbuf;<br /><br /><br /><br /><br />  while(m_hFile !</span>
				<span style="COLOR: #0000ff">= NULL)<br /><br /><br />  </span>
				<span style="COLOR: #ff0000">{<br /><br /><br />    ret </span>
				<span style="COLOR: #0000ff">= m_hsocket.hrecvfrom((char*)&amp;recvbuf, </span>
				<span style="COLOR: #ff0000">sizeof(recvbuf));  <br /><br /><br />    if(ret </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">SOCKET_ERROR)<br /><br /><br />    {<br /><br /><br />      //AfxMessageBox("接收确认消息出错");<br /><br /><br />      ::EnterCriticalSection(&amp;m_csQueue);<br /><br /><br />      if(m_bufqueue.front()-</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">index == File_End) // 文件传输完毕<br /><br /><br />      {<br /><br /><br />         ::LeaveCriticalSection(</span>
				<span style="COLOR: #ff0000">&amp;m_csQueue</span>
				<span style="COLOR: #000000">);<br /><br /><br />         break;<br /><br /><br />       }<br /><br /><br />       ::LeaveCriticalSection(</span>
				<span style="COLOR: #ff0000">&amp;m_csQueue</span>
				<span style="COLOR: #000000">);<br /><br /><br />       cout </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">&lt; "接收确认消息出错: </span>
				<span style="COLOR: #ff0000">" &lt;&lt; GetLastError() &lt;&lt; endl;<br /><br /><br /><br />       return false;<br /><br /><br />     }<br /><br /><br />  if(recvbuf.flag </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">Flag_Ack &amp;&amp; recvbuf.index </span>
				<span style="COLOR: #0000ff">==    </span>
				<span style="COLOR: #ff0000">m_nSendIndexTail)<br /><br />  <br /><br /><br />   {<br /><br /><br />      m_nSendIndexTail </span>
				<span style="COLOR: #0000ff">= (m_nSendIndexTail </span>
				<span style="COLOR: #ff0000">+ 1) % Sliding_Window_Size;<br /><br /><br />      //该结点已得到确认，将其加入旁视列表，以备再用<br /><br /><br />      ::EnterCriticalSection(&amp;m_csQueue);<br /><br /><br />      m_bufLookaside.push(m_bufqueue.front());<br /><br /><br />      m_bufqueue.pop();<br /><br /><br />     ::LeaveCriticalSection(&amp;m_csQueue);<br /><br /><br />     SetEvent(m_hEvent);<br /><br /><br /><br />   }<br /><br /><br /> }<br /><br /><br /><br /><br />接收端的接收线程：<br /><br /><br /> int  ret;<br /><br /><br /> DWORD dwWritten;<br /><br /><br /> SendBuf recvbuf;<br /><br /><br /> RecvBuf sendbuf;<br /><br /><br /> int nerror </span>
				<span style="COLOR: #0000ff">= 0;<br /><br /><br /> </span>
				<span style="COLOR: #ff0000">// 设置文件指针位置，指向上次已发送的大小<br /><br /><br /><br /> SetFilePointer(m_hFile, 0, NULL, FILE_END);<br /><br /><br /> //若已接收文件大小小于需要接收的大小，则继续<br /><br /><br /><br /> while(m_dwSend &lt; m_dwFileSize)<br /><br /><br /> {<br /><br /><br />  //接收<br /><br /><br />  memset(&amp;recvbuf, 0, sizeof(recvbuf));<br /><br /><br />  ret </span>
				<span style="COLOR: #0000ff">= m_hsocket.hrecvfrom((char*)&amp;recvbuf, </span>
				<span style="COLOR: #ff0000">sizeof(recvbuf));<br /><br /><br />  if(ret </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">SOCKET_ERROR)<br /><br /><br />  {<br /><br /><br />   return false;<br /><br /><br />  }<br /><br /><br />  //不是希望接收的，丢弃，继续接收<br /><br /><br /><br />  if(recvbuf.index !</span>
				<span style="COLOR: #0000ff">= (m_nRecvIndex) </span>
				<span style="COLOR: #ff0000">% Sliding_Window_Size)<br /><br /><br />  {<br /><br /><br />   nerror++;<br /><br /><br />   cout &lt;&lt; recvbuf.index &lt;&lt; "error?" &lt;&lt; m_nRecvIndex &lt;&lt; endl;<br /><br /><br />   continue;<br /><br /><br />  }<br /><br /><br />  if(!WriteFile(m_hFile, recvbuf.buf, recvbuf.dwLen, &amp;dwWritten, NULL))<br /><br /><br /><br />  {<br /><br /><br />   //AfxMessageBox("写入文件失败");<br /><br /><br />   cout &lt;&lt; "写入文件失败" &lt;&lt; endl;<br /><br /><br />   return false;<br /><br /><br />  }<br /><br /><br /><br /><br />  //已接收文件大小<br /><br /><br />  m_dwSend +</span>
				<span style="COLOR: #0000ff">= dwWritten;<br /><br /><br />  </span>
				<span style="COLOR: #ff0000">//发送确认消息<br /><br /><br /><br />  sendbuf.flag </span>
				<span style="COLOR: #0000ff">= Flag_Ack;<br /><br /><br />  </span>
				<span style="COLOR: #ff0000">sendbuf.index </span>
				<span style="COLOR: #0000ff">= m_nRecvIndex;<br /><br /><br /><br /><br />  </span>
				<span style="COLOR: #ff0000">ret </span>
				<span style="COLOR: #0000ff">= m_hsocket.hsendto((char*)&amp;sendbuf, </span>
				<span style="COLOR: #ff0000">sizeof(sendbuf));<br /><br /><br />  if(ret </span>
				<span style="COLOR: #0000ff">== </span>
				<span style="COLOR: #ff0000">SOCKET_ERROR)<br /><br /><br />  {<br /><br /><br />   return false;<br /><br /><br />  }<br /><br /><br />  //接收窗口前移一格<br /><br /><br /><br />  m_nRecvIndex </span>
				<span style="COLOR: #0000ff">= (m_nRecvIndex </span>
				<span style="COLOR: #ff0000">+ 1) % Sliding_Window_Size;<br /><br /><br /> }<br /><br /><br /><br /> <br /><br /><br /> <br /></span>
		</div><img src ="http://www.cppblog.com/ace/aggbug/5465.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-13 13:56 <a href="http://www.cppblog.com/ace/archive/2006/04/13/5465.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE_Reactor Server一例的增强版</title><link>http://www.cppblog.com/ace/archive/2006/04/12/5407.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 12 Apr 2006 10:01:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/12/5407.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5407.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/12/5407.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5407.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5407.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080">  1</span> <span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*********************************************************************** <br /></span><span style="COLOR: #008080">  2</span> <span style="COLOR: #008000"> * @file: test02.cpp                                                    <br /></span><span style="COLOR: #008080">  3</span> <span style="COLOR: #008000"> * @author: AGP<br /></span><span style="COLOR: #008080">  4</span> <span style="COLOR: #008000"> * @revise: Stone Jiang &lt;2005119@gmail.com&gt; </span><span style="COLOR: #008000; TEXT-DECORATION: underline">http://www.cppblog.com/ace</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">  5</span> <span style="COLOR: #008000"> *          增加了用户可调试性;解决了内存问题，注原作者要求忽略内存问题，关注于<br /></span><span style="COLOR: #008080">  6</span> <span style="COLOR: #008000">            Reactor本身<br /></span><span style="COLOR: #008080">  7</span> <span style="COLOR: #008000"> <br /></span><span style="COLOR: #008080">  8</span> <span style="COLOR: #008000"> ***********************************************************************</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">  9</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 10</span> <span style="COLOR: #000000">#ifdef _DEBUG<br /></span><span style="COLOR: #008080"> 11</span> <span style="COLOR: #000000">#pragma comment (lib,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">aced.lib</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080"> 12</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#else</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 13</span> <span style="COLOR: #000000">#pragma comment (lib,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>.lib</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080"> 14</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 15</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 16</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/Reactor.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 17</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/SOCK_Acceptor.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 18</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/os.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 19</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 20</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000"> PORT_NO 19998</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 21</span> <span style="COLOR: #000000">typedef ACE_SOCK_Acceptor Acceptor;<br /></span><span style="COLOR: #008080"> 22</span> <span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">forward declaration</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 23</span> <span style="COLOR: #008000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> My_Accept_Handler;<br /></span><span style="COLOR: #008080"> 24</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 25</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> My_Input_Handler:</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> ACE_Event_Handler<br /></span><span style="COLOR: #008080"> 26</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 27</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080"> 28</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">construcor</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 29</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    My_Input_Handler()<br /></span><span style="COLOR: #008080"> 30</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 31</span> <span style="COLOR: #000000">        ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Constructor\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080"> 32</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 33</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 34</span> <span style="COLOR: #000000">  </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">My_Input_Handler()<br /></span><span style="COLOR: #008080"> 35</span> <span style="COLOR: #000000">  {<br /></span><span style="COLOR: #008080"> 36</span> <span style="COLOR: #000000">    ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Deconstructor\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080"> 37</span> <span style="COLOR: #000000">  }<br /></span><span style="COLOR: #008080"> 38</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 39</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Called back to handle any input received</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 40</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> handle_input(ACE_HANDLE)<br /></span><span style="COLOR: #008080"> 41</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 42</span> <span style="COLOR: #000000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">receive the data</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 43</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">        ssize_t recvBytes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> peer().recv(data,</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> 44</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(recvBytes </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080"> 45</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 46</span> <span style="COLOR: #000000">       ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">客户端断开连接</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080"> 47</span> <span style="COLOR: #000000">       </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 48</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 49</span> <span style="COLOR: #000000">    data[recvBytes] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 50</span> <span style="COLOR: #000000">    <br /></span><span style="COLOR: #008080"> 51</span> <span style="COLOR: #000000">        ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,data));<br /></span><span style="COLOR: #008080"> 52</span> <span style="COLOR: #000000">   <br /></span><span style="COLOR: #008080"> 53</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 54</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(ACE_OS::strcmp(data,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">q</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080"> 55</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 56</span> <span style="COLOR: #000000">      ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">客户端要求服务端停止服务</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080"> 57</span> <span style="COLOR: #000000">      peer().close();<br /></span><span style="COLOR: #008080"> 58</span> <span style="COLOR: #000000">      ACE_Reactor::instance()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">end_reactor_event_loop();<br /></span><span style="COLOR: #008080"> 59</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 60</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 61</span> <span style="COLOR: #000000">    peer().send_n(data,recvBytes);<br /></span><span style="COLOR: #008080"> 62</span> <span style="COLOR: #000000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> do something with the input received.<br /></span><span style="COLOR: #008080"> 63</span> <span style="COLOR: #008000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> <img src="http://www.cppblog.com/images/dot.gif" /><br /></span><span style="COLOR: #008080"> 64</span> <span style="COLOR: #008000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> keep yourself registerd with the reator</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 65</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 66</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 67</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 68</span> <span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> handle_close(ACE_HANDLE h,ACE_Reactor_Mask m)<br /></span><span style="COLOR: #008080"> 69</span> <span style="COLOR: #000000">  {<br /></span><span style="COLOR: #008080"> 70</span> <span style="COLOR: #000000">    delete </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 71</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">  </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 72</span> <span style="COLOR: #000000">  }<br /></span><span style="COLOR: #008080"> 73</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 74</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Used by the reactor to determine the underlying handle</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 75</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    ACE_HANDLE get_handle()  </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> <br /></span><span style="COLOR: #008080"> 76</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 77</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">peer_.get_handle();<br /></span><span style="COLOR: #008080"> 78</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 79</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 80</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Returns a reference to the underlying stream.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 81</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    ACE_SOCK_Stream</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> peer()<br /></span><span style="COLOR: #008080"> 82</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 83</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">peer_;<br /></span><span style="COLOR: #008080"> 84</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 85</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 86</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080"> 87</span> <span style="COLOR: #000000">    ACE_SOCK_Stream peer_;<br /></span><span style="COLOR: #008080"> 88</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> data [</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #008080"> 89</span> <span style="COLOR: #000000">};<br /></span><span style="COLOR: #008080"> 90</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 91</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> My_Accept_Handler:</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> ACE_Event_Handler<br /></span><span style="COLOR: #008080"> 92</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 93</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080"> 94</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Constructor</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 95</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    My_Accept_Handler(ACE_Addr </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">addr)<br /></span><span style="COLOR: #008080"> 96</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080"> 97</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">open(addr);<br /></span><span style="COLOR: #008080"> 98</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080"> 99</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">100</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Open the peer_acceptor so it starts to "listen"<br /></span><span style="COLOR: #008080">101</span> <span style="COLOR: #008000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">for incoming clients</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">102</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> open(ACE_Addr </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">addr)<br /></span><span style="COLOR: #008080">103</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080">104</span> <span style="COLOR: #000000">        peer_acceptor.open(addr);<br /></span><span style="COLOR: #008080">105</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">106</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080">107</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">108</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Overload the handle input method</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">109</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> handle_input(ACE_HANDLE handle)<br /></span><span style="COLOR: #008080">110</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080">111</span> <span style="COLOR: #000000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Client has requested connection to server.<br /></span><span style="COLOR: #008080">112</span> <span style="COLOR: #008000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Create a handler to handle the connection</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">113</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">        My_Input_Handler </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">eh </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> My_Input_Handler();<br /></span><span style="COLOR: #008080">114</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">115</span> <span style="COLOR: #000000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Accept the connection "into" the Event Handler</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">116</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">peer_acceptor.accept(eh</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">peer(),</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">stream</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">117</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">            </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">remote address</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">118</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">            </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">timeout</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">119</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">            </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">restart if interrupted</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">120</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">            ACE_DEBUG((LM_ERROR,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Error in connection \n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080">121</span> <span style="COLOR: #000000">        <br /></span><span style="COLOR: #008080">122</span> <span style="COLOR: #000000">        ACE_DEBUG((LM_DEBUG,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Connection established\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br /></span><span style="COLOR: #008080">123</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">124</span> <span style="COLOR: #000000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Register the input event handler for reading </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">125</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">        ACE_Reactor::instance()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">register_handler(eh,ACE_Event_Handler::READ_MASK);<br /></span><span style="COLOR: #008080">126</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> msg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">按q键使服务安全退出\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">127</span> <span style="COLOR: #000000">    eh</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">peer().send_n(msg,strlen(msg)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">128</span> <span style="COLOR: #000000">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Unregister as the acceptor is not expecting new clients</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">129</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">130</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080">131</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">132</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Used by the reactor to determine the underlying handle</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">133</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    ACE_HANDLE get_handle(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">) </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">134</span> <span style="COLOR: #000000">    {<br /></span><span style="COLOR: #008080">135</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">peer_acceptor.get_handle();<br /></span><span style="COLOR: #008080">136</span> <span style="COLOR: #000000">    }<br /></span><span style="COLOR: #008080">137</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">138</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">139</span> <span style="COLOR: #000000">    Acceptor peer_acceptor;<br /></span><span style="COLOR: #008080">140</span> <span style="COLOR: #000000">};<br /></span><span style="COLOR: #008080">141</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">142</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ACE_TMAIN(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">argv[])<br /></span><span style="COLOR: #008080">143</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">144</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Create an address on which to receive connections</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">145</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000"> <br /></span><span style="COLOR: #008080">146</span> <span style="COLOR: #000000">    ACE_INET_Addr addr(PORT_NO);<br /></span><span style="COLOR: #008080">147</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">148</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Create the Accept Handler which automatically begins to "listen"<br /></span><span style="COLOR: #008080">149</span> <span style="COLOR: #008000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">for client requests for connections</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">150</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    My_Accept_Handler </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">eh</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> My_Accept_Handler(addr);<br /></span><span style="COLOR: #008080">151</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">152</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Register the reator to call back when incoming client connects </span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">153</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    ACE_Reactor::instance()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">register_handler(eh,ACE_Event_Handler::ACCEPT_MASK);<br /></span><span style="COLOR: #008080">154</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">155</span> <span style="COLOR: #000000">    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Start the event loop</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">156</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">    <br /></span><span style="COLOR: #008080">157</span> <span style="COLOR: #000000">  ACE_Reactor::instance()</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">run_reactor_event_loop();<br /></span><span style="COLOR: #008080">158</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">159</span> <span style="COLOR: #000000">  delete eh;<br /></span><span style="COLOR: #008080">160</span> <span style="COLOR: #000000"> <br /></span><span style="COLOR: #008080">161</span> <span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">162</span> <span style="COLOR: #000000">}</span></div>
		<br />/************************************************************************ <br /> * @file: test02.cpp                                                    <br /> * @author: AGP<br /> * @revise: Stone Jiang &lt;<a href="mailto:2005119@gmail.com">2005119@gmail.com</a>&gt; <a href="/ace">http://www.cppblog.com/ace</a><br /> *          增加了用户可调试性;解决了内存问题，注原作者要求忽略内存问题，关注于<br />            Reactor本身<br /> <br /> ************************************************************************/<img src ="http://www.cppblog.com/ace/aggbug/5407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-12 18:01 <a href="http://www.cppblog.com/ace/archive/2006/04/12/5407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE_Reactor Server一例,刊误修正版</title><link>http://www.cppblog.com/ace/archive/2006/04/12/5406.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 12 Apr 2006 09:28:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/12/5406.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5406.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/12/5406.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5406.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5406.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#ifdef _DEBUG<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#pragma comment (lib,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">aced.lib</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">#else</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#pragma comment (lib,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>.lib</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">#endif</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/Reactor.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"><a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a>/SOCK_Acceptor.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">#define</span>
				<span style="COLOR: #000000"> PORT_NO 19998</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />typedef ACE_SOCK_Acceptor Acceptor;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">forward declaration</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> My_Accept_Handler;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> My_Input_Handler:</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ACE_Event_Handler<br /><img id="Codehighlighter1_305_960_Open_Image" onclick="this.style.display='none'; Codehighlighter1_305_960_Open_Text.style.display='none'; Codehighlighter1_305_960_Closed_Image.style.display='inline'; Codehighlighter1_305_960_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_305_960_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_305_960_Closed_Text.style.display='none'; Codehighlighter1_305_960_Open_Image.style.display='inline'; Codehighlighter1_305_960_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_305_960_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_305_960_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">construcor</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    My_Input_Handler()<br /><img id="Codehighlighter1_350_395_Open_Image" onclick="this.style.display='none'; Codehighlighter1_350_395_Open_Text.style.display='none'; Codehighlighter1_350_395_Closed_Image.style.display='inline'; Codehighlighter1_350_395_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_350_395_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_350_395_Closed_Text.style.display='none'; Codehighlighter1_350_395_Open_Image.style.display='inline'; Codehighlighter1_350_395_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_350_395_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_350_395_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ACE_DEBUG((LM_DEBUG,</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Constructor\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Called back to handle any input received</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> handle_input(ACE_HANDLE)<br /><img id="Codehighlighter1_473_671_Open_Image" onclick="this.style.display='none'; Codehighlighter1_473_671_Open_Text.style.display='none'; Codehighlighter1_473_671_Closed_Image.style.display='inline'; Codehighlighter1_473_671_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_473_671_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_473_671_Closed_Text.style.display='none'; Codehighlighter1_473_671_Open_Image.style.display='inline'; Codehighlighter1_473_671_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_473_671_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_473_671_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">receive the data</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        peer().recv_n(data,</span>
								<span style="COLOR: #000000">12</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ACE_DEBUG((LM_DEBUG,</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%s\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,data));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> do something with the input received.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> <img src="http://www.cppblog.com/images/dot.gif" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> keep yourself registerd with the reator</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Used by the reactor to determine the underlying handle</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    ACE_HANDLE get_handle()  </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> <br /><img id="Codehighlighter1_766_804_Open_Image" onclick="this.style.display='none'; Codehighlighter1_766_804_Open_Text.style.display='none'; Codehighlighter1_766_804_Closed_Image.style.display='inline'; Codehighlighter1_766_804_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_766_804_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_766_804_Closed_Text.style.display='none'; Codehighlighter1_766_804_Open_Image.style.display='inline'; Codehighlighter1_766_804_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_766_804_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_766_804_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">peer_.get_handle();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Returns a reference to the underlying stream.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    ACE_SOCK_Stream</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000"> peer()<br /><img id="Codehighlighter1_882_907_Open_Image" onclick="this.style.display='none'; Codehighlighter1_882_907_Open_Text.style.display='none'; Codehighlighter1_882_907_Closed_Image.style.display='inline'; Codehighlighter1_882_907_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_882_907_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_882_907_Closed_Text.style.display='none'; Codehighlighter1_882_907_Open_Image.style.display='inline'; Codehighlighter1_882_907_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_882_907_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_882_907_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">peer_;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ACE_SOCK_Stream peer_;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> data [</span>
						<span style="COLOR: #000000">12</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> My_Accept_Handler:</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ACE_Event_Handler<br /><img id="Codehighlighter1_1013_2136_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1013_2136_Open_Text.style.display='none'; Codehighlighter1_1013_2136_Closed_Image.style.display='inline'; Codehighlighter1_1013_2136_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1013_2136_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1013_2136_Closed_Text.style.display='none'; Codehighlighter1_1013_2136_Open_Image.style.display='inline'; Codehighlighter1_1013_2136_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1013_2136_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1013_2136_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Constructor</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    My_Accept_Handler(ACE_Addr </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">addr)<br /><img id="Codehighlighter1_1074_1097_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1074_1097_Open_Text.style.display='none'; Codehighlighter1_1074_1097_Closed_Image.style.display='inline'; Codehighlighter1_1074_1097_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1074_1097_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1074_1097_Closed_Text.style.display='none'; Codehighlighter1_1074_1097_Open_Image.style.display='inline'; Codehighlighter1_1074_1097_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1074_1097_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1074_1097_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">open(addr);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Open the peer_acceptor so it starts to "listen"<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">for incoming clients</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> open(ACE_Addr </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">addr)<br /><img id="Codehighlighter1_1202_1245_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1202_1245_Open_Text.style.display='none'; Codehighlighter1_1202_1245_Closed_Image.style.display='inline'; Codehighlighter1_1202_1245_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1202_1245_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1202_1245_Closed_Text.style.display='none'; Codehighlighter1_1202_1245_Open_Image.style.display='inline'; Codehighlighter1_1202_1245_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1202_1245_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1202_1245_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        peer_acceptor.open(addr);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Overload the handle input method</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> handle_input(ACE_HANDLE handle)<br /><img id="Codehighlighter1_1322_1956_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1322_1956_Open_Text.style.display='none'; Codehighlighter1_1322_1956_Closed_Image.style.display='inline'; Codehighlighter1_1322_1956_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1322_1956_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1322_1956_Closed_Text.style.display='none'; Codehighlighter1_1322_1956_Open_Image.style.display='inline'; Codehighlighter1_1322_1956_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_1322_1956_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1322_1956_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">Client has requested connection to server.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">Create a handler to handle the connection</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        My_Input_Handler </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">eh </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> My_Input_Handler();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">Accept the connection "into" the Event Handler</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">peer_acceptor.accept(eh</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">peer(),</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">stream</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">remote address</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">timeout</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">) </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">)</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">restart if interrupted</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            ACE_DEBUG((LM_ERROR,</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Error in connection \n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ACE_DEBUG((LM_DEBUG,</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Connection established\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">Register the input event handler for reading </span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        ACE_Reactor::instance()</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">register_handler(eh,ACE_Event_Handler::READ_MASK);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">Unregister as the acceptor is not expecting new clients</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Used by the reactor to determine the underlying handle</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    ACE_HANDLE get_handle(</span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_2053_2099_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2053_2099_Open_Text.style.display='none'; Codehighlighter1_2053_2099_Closed_Image.style.display='inline'; Codehighlighter1_2053_2099_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_2053_2099_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2053_2099_Closed_Text.style.display='none'; Codehighlighter1_2053_2099_Open_Image.style.display='inline'; Codehighlighter1_2053_2099_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_2053_2099_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_2053_2099_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">peer_acceptor.get_handle();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Acceptor peer_acceptor;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> ACE_TMAIN(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc,</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">argv[])<br /><img id="Codehighlighter1_2177_2648_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2177_2648_Open_Text.style.display='none'; Codehighlighter1_2177_2648_Closed_Image.style.display='inline'; Codehighlighter1_2177_2648_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_2177_2648_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2177_2648_Closed_Text.style.display='none'; Codehighlighter1_2177_2648_Open_Image.style.display='inline'; Codehighlighter1_2177_2648_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_2177_2648_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_2177_2648_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Create an address on which to receive connections</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    ACE_INET_Addr addr(PORT_NO);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Create the Accept Handler which automatically begins to "listen"<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">for client requests for connections</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    My_Accept_Handler </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">eh</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> My_Accept_Handler(addr);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Register the reator to call back when incoming client connects </span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    ACE_Reactor::instance()</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">register_handler(eh,ACE_Event_Handler::ACCEPT_MASK);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">Start the event loop</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ACE_Reactor::instance()</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">handle_events();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<br />书的几个印刷错误,修改后放在上面<br /><br />测试说明<br />运行程序后,在19998端口等待客户的连接<br />建立连接后,收到12个字符号,回显示在屏幕上<br /><br />telnet 127.0.0.1 19998<br />通过控制台输入字符,查看对端显示<br /><br /><img src ="http://www.cppblog.com/ace/aggbug/5406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-12 17:28 <a href="http://www.cppblog.com/ace/archive/2006/04/12/5406.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE_Message_Block小知识</title><link>http://www.cppblog.com/ace/archive/2006/04/12/5396.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 12 Apr 2006 07:48:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/12/5396.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5396.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/12/5396.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5396.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5396.html</trackback:ping><description><![CDATA[<div style="PADDING-LEFT: 6px">
				<p>
						<a name="msg_8bed9b6ef68661a2">
						</a>*ACE_Message_Block小知识* <br /><a href="http://spaces.msn.com/stonejiang/blog/cns!A4A8B7175059E42A!273.entry" target="_blank"><font color="#0000cc">http://spaces.msn.com/stonejiang/blog/cns!A4A8B7175059E42A!273.entry</font></a><br /></p>
				<p>  ** **  1 copy() 不需要让写指针后移. <br />  ACE_Message_Block* mb = new ACE_Message_Block(BUFSIZ); <br />  mb-&gt;copy(buff); //buff先已经初始化 <br />2 初始化mb后需要后移指针的情况 <br />  2.1 <br />  ACE_Message_Block* mb = new ACE_Message_Block(buff,len); <br />  mb-&gt;wt_ptr(len);  //len是buff的长度 len = strlen(buff) +1 <br />                    // +1 表示后面的\0 <br />  2.2 <br />  ACE_Message_Block* mb = new ACE_Message_Block(BUFSIZ); <br />  ACE_OS::sprintf(mb-&gt;wt_ptr(),buff); <br />  mb-&gt;wt_ptr(len); <br />  2.3 <br />  ACE_Message_Block* mb = new ACE_Message_Block(len, <br />            ACE_Message_Block::MB_DATA, <br />            mb2,   //表示 mb-&gt;cont(mb2) <br />            buff) <br />  mb-&gt;wt_ptr(len); <br />3.让消息接成串cont()时,千万不要直接或接间的把它接成一个环 <br />   mb-&gt;cont(mb2); <br />   mb2-&gt;cont(mb3); //ok <br />   ***mb3-&gt;cont(mb);  //死定了 <br />4.通知其它线程结束时,可以通过ACE_Message_Block::MB_STOP <br /></p>
				<p>  ACE_Message_Block* lastMsg =ACE_Message_Block ,ACE_Message_Block::MB_STOP) <br />  otherTask-&gt;putq(lastMsg); <br /></p>
				<p>  otherTask在接收到的时候如下处理 <br /></p>
				<p> </p>
				<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<span style="COLOR: #000000">   </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> OtherTask::svc() <br /><img id="Codehighlighter1_28_390_Open_Image" onclick="this.style.display='none'; Codehighlighter1_28_390_Open_Text.style.display='none'; Codehighlighter1_28_390_Closed_Image.style.display='inline'; Codehighlighter1_28_390_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_28_390_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_28_390_Closed_Text.style.display='none'; Codehighlighter1_28_390_Open_Image.style.display='inline'; Codehighlighter1_28_390_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />   </span>
						<span id="Codehighlighter1_28_390_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_28_390_Open_Text">
								<span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />          ACE_Message_Block</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> mb; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">) <br /><img id="Codehighlighter1_97_387_Open_Image" onclick="this.style.display='none'; Codehighlighter1_97_387_Open_Text.style.display='none'; Codehighlighter1_97_387_Closed_Image.style.display='inline'; Codehighlighter1_97_387_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_97_387_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_97_387_Closed_Text.style.display='none'; Codehighlighter1_97_387_Open_Image.style.display='inline'; Codehighlighter1_97_387_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />           </span>
								<span id="Codehighlighter1_97_387_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_97_387_Open_Text">
										<span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />             getq(mb); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(mb</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">get_tpye() </span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> ACE_Message_Block::MB_STOP) <br /><img id="Codehighlighter1_197_275_Open_Image" onclick="this.style.display='none'; Codehighlighter1_197_275_Open_Text.style.display='none'; Codehighlighter1_197_275_Closed_Image.style.display='inline'; Codehighlighter1_197_275_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_197_275_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_197_275_Closed_Text.style.display='none'; Codehighlighter1_197_275_Open_Image.style.display='inline'; Codehighlighter1_197_275_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />           </span>
										<span id="Codehighlighter1_197_275_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_197_275_Open_Text">
												<span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              mb</span>
												<span style="COLOR: #000000">-&gt;</span>
												<span style="COLOR: #000000">release(); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              </span>
												<span style="COLOR: #0000ff">break</span>
												<span style="COLOR: #000000">; </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">退出这个永久限环) </span>
												<span style="COLOR: #008000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />
												</span>
												<span style="COLOR: #000000">           }</span>
										</span>
										<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000"> <br /><img id="Codehighlighter1_306_364_Open_Image" onclick="this.style.display='none'; Codehighlighter1_306_364_Open_Text.style.display='none'; Codehighlighter1_306_364_Closed_Image.style.display='inline'; Codehighlighter1_306_364_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_306_364_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_306_364_Closed_Text.style.display='none'; Codehighlighter1_306_364_Open_Image.style.display='inline'; Codehighlighter1_306_364_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />           </span>
										<span id="Codehighlighter1_306_364_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_306_364_Open_Text">
												<span style="COLOR: #000000">{ <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              handle_message(mb); </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">处理这条消息 </span>
												<span style="COLOR: #008000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />
												</span>
												<span style="COLOR: #000000">           }</span>
										</span>
										<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
								</span>
								<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						</span>
				</div>
				<p>
						<br /> 
</p>
				<p>-- <br />Stone Jiang <br /></p>
		</div><img src ="http://www.cppblog.com/ace/aggbug/5396.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-12 15:48 <a href="http://www.cppblog.com/ace/archive/2006/04/12/5396.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE电子书下载</title><link>http://www.cppblog.com/ace/archive/2006/04/12/5386.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 12 Apr 2006 05:45:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/12/5386.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5386.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/12/5386.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5386.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5386.html</trackback:ping><description><![CDATA[第一本<br /><p><a name="apg"></a>The <a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a> Programmer's Guide: Practical Design Patterns for Network and Systems Programming</p><p>即AGP<br /><img src="http://www.riverace.com/bookstore/APG-cover.jpg" /><br /><br /><a class="" title="下载AGP" href="http://www.infoxa.com/asp/book/xzcs_1.asp?id=2155" target="">下载</a> , <a href="http://www.riverace.com/acebooks/apg_errata.htm">Errata </a><br /><br /><br />第二,三本<br /></p><p><a name="cnpv1"></a>C++ Network Programming, Volume 1: Mastering Complexity with <a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a> and Patterns<br />C++ Network Programming, Volume 2: Systematic Reuse with <a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html" >ace</a> and Frameworks </p><p><img src="http://www.riverace.com/bookstore/CNPv1-cover.jpg" /> <a href="http://www.riverace.com/acebooks/cnpv1_errata.htm">Errata</a><br /><br /><img src="http://www.riverace.com/bookstore/CNPv2-cover.jpg" /> <a href="http://www.riverace.com/acebooks/cnpv2_errata.htm">Errata</a><br /><br /><br /><a class="" title="" href="http://www.infoxa.com/asp/book/xzcs_1.asp?id=922" target="_blank">下载</a><br /></p><img src ="http://www.cppblog.com/ace/aggbug/5386.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-12 13:45 <a href="http://www.cppblog.com/ace/archive/2006/04/12/5386.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE在win32平台上的安装,与VC6的集成 (转至huihoo)</title><link>http://www.cppblog.com/ace/archive/2006/04/12/5380.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Wed, 12 Apr 2006 05:04:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/12/5380.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5380.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/12/5380.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5380.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5380.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">翻译的一点小东西，希望能对大家有帮助。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />其实也不敢称为是翻译的，水平太烂了，大家将就着看吧 ：）<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />使用Microsoft Visual C++ 在win32平台上生成和安装ACE：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />注意：关于MSVC5.0和Service Pack 3的使用有一些问题，过去一些用户在sp2中使用良好的代码在sp3种却会引发一些问题。感谢Bill 的细心查找，这一神秘的问题被解决了。答案？（哦，这儿有一个好答案。。。）这可能是因为有多个版本的sp3较早版本的sp3有一些bug，而后来的版本修正了这些错误，从微软网站上下载的1998年6月16日版本的sp3是一个良好的版本。如果X03-50158是那些拥有sp3的光盘序列号的一部分，那么这些版本也是良好的。但是不管任何版本的sp3，其STL的实现都有错误，详细情况请浏览http://www.dinkumware.com/vc_fixes.html。感谢Ben Eng对这些错误的修正。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />现在的SP4(希望只有一个版本)已经修正了STL中的死锁问题。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />我们现在将不再积极的支持MSVC 4.X以及以前的版本，ACE可和这些编译器一起工作但是可能会丢失一些好处。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />1. 将ACE分发包界压缩到一个目录中，这将在那个目录中生成一个包含ACE的目录ACE_wrappers。接下来的步骤中假设ACE分发包被解压缩到ACE_ROOT=C:\ACE_wrappers中，因此ACE将会存在于ACE_ROOT\ace目录中。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />2. 在ACE_ROOT\ace目录中创建一个文件，命名为config.h，其内容为：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include "<a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a>/config-win32.h"<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />3. 在VC++中加载ACE的工程文件（ACE_ROOT\ace\ace.dsw）<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />4. 每个工程都会包含多个配置，这些配置是Debug/Release, MFC/Non-MFCh和Static/Dynamic库版本等选项的混合。确定你所需要的构造(例如，调试代码需要ACE的调试版本)。所有这些不同的配置可以为你提供一些便利，你可以或者采用不同的模式以构造不同配置的应用，或者通过改变ace\config.h来改变在NT上的不同配置。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />注意：如果你使用动态连接，请保证ACE_ROOT\bin被添加到你的path环境变量中，否则你将在运行程序的时候碰到寻找ace.dll或者aced.dll的问题。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />5. 如果你在Windows NT或者Windows 2k上构建ACE，你可以马上开始构造她而不需任何改变，如果你在Windows 9x/me上构建，那么你必须在<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ACE_ROOT\ace\config.h.的#include块之前添加一行：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#define ACE_HAS_WINNT4 0<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />这将在ACE中移掉一些WinNT/Win2K中特有的代码。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />6. 如果你希望使用MSVC自带的标准C++头文件（C++ Standard Draft 2种定义的iostream,cstdio…..）,则应该在<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ACE_ROOT\ace\config.h.的#include块之前添加一行：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#define ACE_HAS_STANDARD_CPP_LIBRARY 1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />7. 如果需要和MFC一起使用，增加如下定义到你的config.h文件中，注意，如果你想使用spawn一个新的线程，则必须保证使用THR_USE_AFX标志来spawn线程。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#define ACE_HAS_MFC 1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />缺省的，ACE工程使用MSVC运行时的动态DLL版本，你也可以选择使用ACE的不关心运行时库的静态（LIB）版本。我们选择仅与动态运行时库连接的原因在于基本上所有的NT机器上都会安装这些库，而我们则可以因此而减小代码的大小。如果你希望ACE与MFC的静态版本连接，则可以在config.h中定义ACE_USES_STATIC_MFC。然而，如果你希望静态的连接所有的库（包括MSVC运行时库），就需要自己修改工程文件了。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />8. 如果要构建ACE的静态版本，则需要在config.h中定义ACE_AS_STATIC_LIBS，此宏在那些希望使用ACE的静态版本的应用工程中也必须定义。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />作为一个可选项，你可以在<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include statement in ACE_ROOT\ace\config.h.之前添加一行：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#define ACE_NO_INLINE<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />来取消函数内联从而减小静态库（和你的运行码）的大小。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />9. <a title="ac" href="http://www.cs.wustl.edu/~schmidt/ACE.html">ace</a> DLL和LIB库的命名规则：<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />我们使用如下的规则明明使用MSVC的ACE的DLL和LIB文件。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />"Library/DLL name" + (是静态库吗 ? "s" : "") + (包含调试信息 ? "d" : "") + {".dll"|".lib"}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />在MSVC环境中使用ACE的更多信息可以在这里找到。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div><img src ="http://www.cppblog.com/ace/aggbug/5380.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-12 13:04 <a href="http://www.cppblog.com/ace/archive/2006/04/12/5380.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACE课程提纲，ACE学习路径</title><link>http://www.cppblog.com/ace/archive/2006/04/11/5322.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Tue, 11 Apr 2006 13:53:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/11/5322.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5322.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/11/5322.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5322.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5322.html</trackback:ping><description><![CDATA[ACE的历史和动机；<br />复用技术说明 获取和编译ACE；<br />在你的应用中包含ACE ACE工具和技术基础；程序结构，窄/宽字符，日志 <br />Socket，消息块和Reactor(反应器)框架 <br />Acceptor-Connector(接受器-连接器)框架 <br />Service Configurator(服务配置)框架 <br />并行的包装 <br />Task(任务)框架 <br />Stream(流)框架 <br />Proactor(前摄器)框架<br /><br /><img height="499" alt="ace_course.jpg" src="http://www.cppblog.com/images/cppblog_com/ace/ace_course.jpg" width="710" border="0" />eams<img src ="http://www.cppblog.com/ace/aggbug/5322.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-11 21:53 <a href="http://www.cppblog.com/ace/archive/2006/04/11/5322.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++编码不规范出现的错误一例的解析</title><link>http://www.cppblog.com/ace/archive/2006/04/11/5292.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Tue, 11 Apr 2006 07:29:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/04/11/5292.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/5292.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/04/11/5292.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/5292.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/5292.html</trackback:ping><description><![CDATA[<p>
				<br />在Huihoo的ACE论坛中，有一网友问到为什么ACE_Time_Value的秒数在Debug版本少一秒，而<br />在Release版本上“正常”。经过对其代码的复读以及对ACE的跟踪，发现原来是编码不规范犯<br />下的一个很严重的错误造成的。本文就讨论这一例子。<br /><br />以下引用<br /> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span> <span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #008000">我写了个从年月日时分秒数值得到ACE_Time_Value结果的函数:<br /></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #008000"></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> s_get_ace_datetime(ACE_Time_Value </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> ace_datetime,<br /></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> year,<br /></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> month,<br /></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> day,<br /></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> hour,<br /></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> min,<br /></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">      </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sec)<br /></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(year</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1970</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> year</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">2038</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> month</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> month</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> day</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> day</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">31</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">        hour</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> hour</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">23</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> min</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> min</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">59</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> sec</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> sec</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">59</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">          ACE_ERROR_RETURN((LM_ERROR,<br /></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000">                         ACE_TEXT(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%I(日期时间参数溢出合理的习惯日期时间范围1970.1.2-2038.1.18)n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)),</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000">    timespec_t spec_t;<br /></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">    tm time_tm; <br /></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">  time_tm.tm_year</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">year</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1900</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">  time_tm.tm_mon</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">month</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000">  time_tm.tm_mday</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">day;<br /></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">  time_tm.tm_hour</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">hour;<br /></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000">  time_tm.tm_min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">min;<br /></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">#if</span><span style="COLOR: #000000"> defined (ACE_NDEBUG)</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000">    time_tm.tm_sec</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sec;<br /></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">#else</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">26</span> <span style="COLOR: #000000">    time_tm.tm_sec</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sec</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">奇怪,当由各部分数量构造ACE_Time_Value时,debug编译时,秒的数量总是自动减1,在此要补上1</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">27</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">28</span> <span style="COLOR: #000000">   spec_t.tv_sec</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mktime(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">time_tm); <br /></span><span style="COLOR: #008080">29</span> <span style="COLOR: #000000">   </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(spec_t.tv_sec</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">30</span> <span style="COLOR: #000000">   ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%I(日期时间转化错误,得到&lt;0的time_t,日期范围是1970.1.2-2038.1.18)n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)),</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">31</span> <span style="COLOR: #000000">   ace_datetime.</span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">(spec_t);<br /></span><span style="COLOR: #008080">32</span> <span style="COLOR: #000000">   </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">33</span> <span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">34</span> <span style="COLOR: #000000"></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">35</span> <span style="COLOR: #008000">我在VC++7.1上分别编译了Debug版本和Release版本,time_tm.tm_sec竟然会有一秒的差别,莫名其妙地影响了我的项目.<br /></span><span style="COLOR: #008080">36</span> <span style="COLOR: #008000">哪位高手知道为什么?<br /></span><span style="COLOR: #008080">37</span> <span style="COLOR: #008000">另外ACE_Time_Value的范围太小,ACE中是否有大日期时间范围的其它类封装?<br /></span><span style="COLOR: #008080">38</span> <span style="COLOR: #008000"></span><span style="COLOR: #008000">*/</span></div>
		<p>以下是我的回贴:<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">你这个问题还真有趣,我跟踪了ACE相关代码后才发现,问题原来出在你写的函数中,病因是,使用未完全初始化的结构体变量<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />timespec_t spec_t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />后面加上语句<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />memset(</span>
				<span style="COLOR: #ff0000">&amp;spec_t</span>
				<span style="COLOR: #000000">,0,sizeof(timespec_t));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />即可<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />局部变量 spec_t 在debug时,各字段均被初始化为0xCCCCCCCC,它是一个负数<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />在下面的操作中,只修改了tv_sec,而tv_nsec 仍为一个负数<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />spec_t.tv_sec=mktime(</span>
				<span style="COLOR: #ff0000">&amp;time_tm</span>
				<span style="COLOR: #000000">); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ACE_Time_Value::normalize()默默地为你作了规格化处理，就替你减去了一秒钟。<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
		<p>
				<br />
				<br />
				<br />
				<br />原代码更严重的错误在于：<br />原以为 Release版本是“正常”的，其实不然，而是Release隐藏了更严重的错误。<br />严重是因为它表现出错误的时候很随机，一旦产品发布，很难发现。<br /><br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">对象(结构体)timespec有两个公有属性</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000"> typedef </span>
				<span style="COLOR: #0000ff">struct</span>
				<span style="COLOR: #000000"> timespec<br /><img id="Codehighlighter1_55_139_Open_Image" onclick="this.style.display='none'; Codehighlighter1_55_139_Open_Text.style.display='none'; Codehighlighter1_55_139_Closed_Image.style.display='inline'; Codehighlighter1_55_139_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_55_139_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_55_139_Closed_Text.style.display='none'; Codehighlighter1_55_139_Open_Image.style.display='inline'; Codehighlighter1_55_139_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />     </span>
				<span id="Codehighlighter1_55_139_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_55_139_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />       time_t tv_sec; </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Seconds</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">       </span>
						<span style="COLOR: #0000ff">long</span>
						<span style="COLOR: #000000"> tv_nsec; </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Nanoseconds, 十亿分之一秒</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />
						</span>
						<span style="COLOR: #000000">     }</span>
				</span>
				<span style="COLOR: #000000"> timespec_t;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />     </span>
		</div>
		<p>在原代码16行<br />timespec_t spec_t;<br />构造了一个 timespec_t  临时对象spec_t后,debug版把它各字段初始化为 0xcccccccc,这使得问题一下子得于曝光.而Release版本, spec_t 为一个随机值. 本例程中,不允许 spec_t的tv_nsec为非0的任何数,为正常尽管看上去没有问题,但是这个对应的ACE_Time_Value的值也不可靠.在特定情况下可能产生重大事故.<br /><br /></p>
		<p>C++编码规范：<br />初始化对象时要完全。</p>
		<p>声明一个结构体后，如果要对其初始化，建议先把它设为0之后再作后续操作，养成这样一个习惯，就不会出现这样郁闷的事了。<br /><br /><br />原贴出处:<br /><a href="http://www.huihoo.com/forum/viewthread.php?tid=11016">http://www.huihoo.com/forum/viewthread.php?tid=11016</a><br /><br /><br />mooyee<br /></p><img src ="http://www.cppblog.com/ace/aggbug/5292.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-04-11 15:29 <a href="http://www.cppblog.com/ace/archive/2006/04/11/5292.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将ACE事件循环与MFC UI集成的一种实现</title><link>http://www.cppblog.com/ace/archive/2006/03/21/4428.html</link><dc:creator>Stone Jiang</dc:creator><author>Stone Jiang</author><pubDate>Tue, 21 Mar 2006 09:14:00 GMT</pubDate><guid>http://www.cppblog.com/ace/archive/2006/03/21/4428.html</guid><wfw:comment>http://www.cppblog.com/ace/comments/4428.html</wfw:comment><comments>http://www.cppblog.com/ace/archive/2006/03/21/4428.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/ace/comments/commentRss/4428.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ace/services/trackbacks/4428.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 将ACE事件循环与MFC UI集成的一种实现										将ACE事件循环与MFC UI集成的一种实现		有很多种方式可以使界面与ACE事件循环集成在一起。本文件试图提供一种“更好”的集成。这里的“更好”是指：1. 使用简单2. 面向对象，不破坏已有系统的结构3. 尽量解除ACE与界面之间的耦合		本文也仅用作抛砖引玉的“砖”，如果你有更好的方式，欢迎告诉我。		...&nbsp;&nbsp;<a href='http://www.cppblog.com/ace/archive/2006/03/21/4428.html'>阅读全文</a><img src ="http://www.cppblog.com/ace/aggbug/4428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ace/" target="_blank">Stone Jiang</a> 2006-03-21 17:14 <a href="http://www.cppblog.com/ace/archive/2006/03/21/4428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>