|
- int CClientService::handle_output (ACE_HANDLE){
- ACE_Message_Block *mb;
- ACE_Time_Value nowait (ACE_OS::gettimeofday ());
- if(-1 != this->getq (mb, &nowait)){ //这里用while还是if好些,对于一个putq相当快的线程
- int recv_cnt = mb->length();
- ssize_t send_cnt = this->peer ().send(mb->rd_ptr (), mb->length ()); //因为send相对来说比较费时
- if(send_cnt == -1 && ACE_OS::last_error() != EWOULDBLOCK){
- return -1;
- }else{
- if(send_cnt == -1){
- send_cnt = 0;
- }
- mb->rd_ptr (static_cast (send_cnt));
- }
- if(mb->length () > 0) {
- this->ungetq (mb);
- return 1;
- }
- mb->release ();
- /* //是否需要sleep来,对CPU占用缓解有没有更好的方法
- ACE_Time_Value tv(0, 100);
- ACE_OS::sleep(tv);
- */
- }
- if (this->msg_queue ()->is_empty())
- this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
- else
- this->reactor ()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK);
- return 0;
- }
复制代码 |
|