|
奇怪的问题,之前在局域网内运行了几个月完全没问题,服务器放到公网后客户端与服务器建立连接总是失败:在 open 中initiate_read_stream调用中启动异步读操作总是失败,返回 -1,导致连接被终止。之前一直没这个问题,最后尝试在首次启动异步读操作之前休眠4500毫秒,居然就不再出现问题了。这到底是为何?
客户端操作系统是 Xp ,ACE 版本是 5.6.9。大家帮忙一下,谢谢!
void
ACEChannel_Handler::open(ACE_HANDLE new_handle, ACE_Message_Block& message_block) {
if (this->reader_.open((*this), new_handle, 0, this->proactor()) == -1) {
ACE_ERROR(
(LM_ERROR, ACE_TEXT("%p\n"),
ACE_TEXT("ACEChannel_Handler::open-Read")));
} else if (this->writer_.open((*this), new_handle, 0, this->proactor()) == -1) {
ACE_ERROR(
(LM_ERROR, ACE_TEXT("%p\n"),
ACE_TEXT("ACEChannel_Handler::open-Write")));
} else {
//::Sleep(4500); 休眠之后 initiate_read_stream 才会成功。
this->initiate_read_stream();
}
this->check_destroy();
}
int
ACEChannel_Handler::initiate_read_stream() {
ACE_Guard<ACE_Recursive_Thread_Mutex> lock(this->lock_);
if (this->read_mblk_.space() <= 0) {
this->read_mblk_.size(this->read_mblk_.size() + 521);
}
if (this->reader_.read(this->read_mblk_, this->read_mblk_.space()) == -1) {
ACE_ERROR_RETURN(
(LM_ERROR, ACE_TEXT("%p%d\n"),
ACE_TEXT("ACEChannel_Handler::initiate_read_stream"), GetLastError()),
-1);
}
++(this->io_counter_);
return 0;
} |
|