这到底什么机制!
intSupplier_Handler::handle_input (ACE_HANDLE)
{
char buf;
ssize_t received = this->peer ().recv (buf, sizeof buf);
switch (received)
{
case -1:
this->state (Connection_Handler::FAILED);
ACE_ERROR_RETURN ((LM_ERROR,
"(%t) Peer has failed unexpectedly for Client_Handler %d\n",
this->connection_id ()),
-1);
/* NOTREACHED */
case 0:
this->state (Connection_Handler::FAILED);
ACE_ERROR_RETURN ((LM_ERROR,
"(%t) Peer has shutdown unexpectedly for Client_Handler%d\n",
this->connection_id ()),
-1);
/* NOTREACHED */
default:
ACE_DEBUG((LM_DEBUG,"(%t) from %d: %s %d \n",connection_id_,buf,received));
return 0;
}
}
为什么当对面连接关闭的时候,调用handle_input时候,buf字符组不是空,还是上次收到的字符值! char buf;
改成
char buf = {'\0'}; 回复 2# freeeyes
那为什么第二次调用的时候 (buf为局部对象,应该为空阿),怎么还存储上次的字符呢? 局部变量不一定都是空(0值),你应该在用之前初始化,然后再看调用完毕后是什么值,否则一个没有初始化的内存有可能是脏数据。 xiexie le!!!! 顺便问问:ACE_NOTREACHED这个有什么用?
页:
[1]