svc() return 时也调用handle_close , 怪事。
acceptor框架, 反应式。svc() return 时也调用handle_close , 怪事。
acceptor的ace_svc_handler里头。
简单一点:
handle_close()
{
if(recv()== -1)
{
发送退出svc的消息。
//wait();
}
}
svc()
{
return 0;
}
handle_close()
{
wait();
//做其它关闭工作。
}
当connector关闭时,
结果进来两次。handle_input返回-1进来一次。 svc返回也进来一次。
我要是把wait()放到handle_input里头吧,connector不发消息, 连上后直接关闭在wait()处中断。
[ 本帖最后由 jolly_w23 于 2008-5-19 21:09 编辑 ] 贴上代码,你的代码写错了。 就是在handle_close里头调了下wait()啊。 是不是这有问题。 Line 21 Convert TPC_Logging_Handler into an active object. The newly spawned detached thread runs the following TPC_Logging_Handler::svc() hook method:virtual int svc () {
for (;;)
switch (logging_handler_.log_record ()) {
case -1: return -1; // Error.
case 0: return 0; // Client closed connection.
default: continue; // Default case.
}
/* NOTREACHED */
return 0;
}
};
This method focuses solely on reading and processing client log records. We break out of the for loop and return from the method when the log_record() method detects that its peer service handler has closed the connection or when an error occurs. Returning from the method causes the thread to exit, which in turn triggers ACE_Task::svc_run() to call the inherited ACE_Svc_Handler::close() method on the object. By default, this method closes the peer stream and deletes the service handler if it was allocated dynamically, as described in the table on page 210. Since the thread was spawned using the THR_DETACHED flag, there's no need to wait for it to exit.
你的代码有错误,对ACE理解还不够深刻,读书哦。svc中返回0,会导致调用handle_close()的。这是多调的一次。 呵呵,我自己也找到了。 还是学生嘛。学习ing......
主动对象式关闭(close()): 当ACE_Svc_Handler 派生的对象通过activate()函数转变为主动对象,处理器的的svc()方法在它产生的线程中运行后进行回调。当svc()返回时,线程
退出,但在它要退出时,仍在将要退出线程的上下文中,ACE_Task框架调用它的close()方法。ACE_Svc_Handler::close()方法调用handle_close()完成服务处理器的清理工作。 我override了ACE_Svc_Handler::close() 方法,让他不调handle_close.
页:
[1]