int CCSocketHandler::handle_output() { log_debug("*STEP: send data, len:[%d] netfd[%d]", _w.data_len(), netfd); if (_w.data_len() != 0) { int ret = ::send (netfd, _w.data(), _w.data_len(), 0); if(-1 == ret) { if(errno == EINTR || errno == EAGAIN || errno == EINPROGRESS) { log_boot("sending,INTR|EAGAIN|EINPROGRESS,errno:[%d]", errno); EnableOutput (); ApplyEvents (); _stage = CONN_DATA_SENDING; return _stage; } log_boot ("sending package to client failed, ret[%d]", ret); DisableInput (); DisableOutput (); ApplyEvents (); _stage = CONN_FATAL_ERROR; return _stage; } if(ret == (int)_w.data_len()) { log_debug("send complete, send len=[%d]",ret); DisableOutput(); ApplyEvents (); _w.skip(ret); _stage = CONN_SEND_DONE; return _stage; } else if (ret < (int)_w.data_len()) { log_debug("had sent part of data, send len=[%d]",ret); EnableOutput (); ApplyEvents (); _w.skip(ret); _stage = CONN_DATA_SENDING; return _stage; } } DisableOutput(); ApplyEvents (); _stage = CONN_FATAL_ERROR; log_debug("send process failure"); return _stage; }
void CSpliceScreenConfigDlg::EnableOutputs( const WMBlock* pBlockActive ) { int i = 0; for (i = 0; i < m_lbOutputs.GetCount(); ++i) { m_lbOutputs.Enable(i, TRUE); m_lbOutputs.SetCheck(i, FALSE); } for (i = 0; i < m_wndWall.GetBlockCount(); ++i) { const WMBlock* pBlock = m_wndWall.GetBlock(i); if (pBlock && pBlock != pBlockActive) { for (int j = 0; j < pBlock->vecOutputs.size(); ++j) { EnableOutput(pBlock->vecOutputs[j], FALSE); } } } for (i = 0; i < pBlockActive->vecOutputs.size(); ++i) { CheckOutput(pBlockActive->vecOutputs[i], TRUE); } }
int CCSocketHandler::Send(const char * buff, int len) { if(len>0) { if (GetReconnectFlag()==true){ Connect(); } const char* sendbuff = buff; int sendlen = len; if(this->_w.data_len()==0) { int ret = ::send (netfd,buff, len, 0); log_debug("Send Fd[%d]", netfd); if(-1 == ret) { if(errno == EINTR || errno == EAGAIN || errno == EINPROGRESS) { log_boot("sending,INTR|EAGAIN|EINPROGRESS,errno:[%d]", errno); this->_w.append(sendbuff, sendlen); EnableOutput (); ApplyEvents (); _stage = CONN_DATA_SENDING; return 0; } else { log_boot ("sending package to client failed, ret[%d]", ret); _stage = CONN_FATAL_ERROR; this->OnClose(); if(GetReconnectFlag()==false){//����Ҫ���� delete this; } else{ Reset(); } return -1; } } else if(ret<len) { sendbuff += ret; sendlen -= ret; this->_w.append(sendbuff, sendlen); EnableOutput (); ApplyEvents (); _stage = CONN_DATA_SENDING; log_debug("had sent part of data, send len=[%d]",ret); return ret; } else if(ret==len) { log_debug("send complete, send len=[%d]",len); _stage = CONN_SEND_DONE; return ret; } } else { this->_w.append(sendbuff, sendlen); if( handle_output() ==CONN_FATAL_ERROR ) { this->OnClose(); if(GetReconnectFlag()==false){//����Ҫ���� delete this; } else{ Reset(); } return -1; } else return len; } } return len; }
int CHelperUnit::send_to_cgi(void) { int ret = 0; int reConnectCount = 0; log_debug("_w data size:[%d]", _w.data_len()); logic: if (_w.data_len() != 0) { ret = ::send (netfd, _w.data(), _w.data_len(), 0); log_debug("sent packet size:[%d]", ret); if(-1 == ret) { if(errno == EINTR || errno == EAGAIN || errno == EINPROGRESS) { _send_error_times++; if(_send_error_times >= 50) { g_pErrorLog->logMsg("CHelperUnit::send_to_cgi, send error more"); reset_helper(); _stage = CONN_FATAL_ERROR; return -1; } EnableOutput (); ApplyEvents (); return CONN_DATA_SENDING; } log_error("*STEP: sending package to logic server failed, ret code[%d], errno:[%d], ip:[%s], port:[%d]", ret, errno, addr.c_str(), port); reset_helper(); _stage = CONN_FATAL_ERROR; return -1; } if(ret == (int)_w.data_len()) { _w.skip(ret); DisableOutput (); ApplyEvents(); _stage = CONN_SEND_DONE; //重置发送错误次数 _send_error_times = 0; log_debug ("*STEP: sent package to logic server, netfd[%d] packet size[%d]", netfd, ret); return ret; } else if (ret < (int)_w.data_len()) { EnableOutput (); ApplyEvents (); _w.skip(ret); _stage = CONN_DATA_SENDING; //重置发送错误次数 _send_error_times = 0; return ret; } DisableInput (); DisableOutput (); ApplyEvents(); _stage = CONN_FATAL_ERROR; log_debug ("*STEP: sending package to logic server in exception, netfd[%d]", netfd); return ret; } return ret; }