|
我有一ACE做的程式, 先初始化接收. 在收到数据后,打印收到的信息. 再接收.
但程式却进入死循环. 因在handle_read_stream 这个中, 总是返回, 但BYTE_TRANSFERD=0
这如何是好呀?
int
Client::initiate_read_stream (void)
{
if (this->flg_cancel_ != 0 || this->handle_ == ACE_INVALID_HANDLE)
return -1;
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN (mb,
ACE_Message_Block (1024), //BUFSIZ + 1),
-1);
// Inititiate read
if (this->rs_.read (*mb, mb->size ()-1) == -1)
{
mb->release ();
// On peer close, ReadFile will yield ERROR_NETNAME_DELETED; won't get
// a 0-byte read as we would if underlying calls used WSARecv.
if (ACE_OS::last_error () == ERROR_NETNAME_DELETED)
ACE_ERROR_RETURN ((LM_DEBUG,
ACE_TEXT ("(%t) Server %d, peer closed\n"),
this->id_),
-1);
}
}
void
Client::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
{
{
ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->lock_);
ACE_Message_Block & mb = result.message_block ();
if (loglevel > 1)
{
LogLocker log_lock;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) **** Client %d: handle_read_stream() ****\n"),
this->id_));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %B\n"),
ACE_TEXT ("bytes_to_read"),
result.bytes_to_read ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("handle"),
result.handle ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %B\n"),
ACE_TEXT ("bytes_transfered"),
result.bytes_transferred ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = [url=]%@\n[/url]"),
ACE_TEXT ("act"),
result.act ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("success"),
result.success ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = [url=]%@\n[/url]"),
ACE_TEXT ("completion_key"),
result.completion_key ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("error"),
result.error ()));
}
this->initiate_read_stream (); //再接收数据.
} |
|