int CCSocketHandler::Connect(){ int ret = -1; if (_stage == CONN_IDLE){ ret = CNet::tcp_connect(&netfd, GetSIP().c_str(), GetPort(), 0,500); log_debug("Connect..."); } else { if (netfd < 0) { ret = CNet::tcp_connect(&netfd, GetSIP().c_str(), GetPort(), 0,500); } else { ret = 1; } } if(ret <0) { /* if (ret == SOCKET_CREATE_FAILED) { log_error("*STEP: helper create socket failed, errno[%d], msg[%s]", errno, strerror(errno)); return -1; } if(errno != EINPROGRESS) { log_error("*STEP: PROXY connect to logic failed, errno[%d], msg[%s]", errno , strerror(errno)); return -1; } _stage = CONN_CONNECTING; log_debug("*STEP: PROXY connecting to logic, unix fd[%d]", netfd); goto exit;*/ if( netfd > 0) { close(netfd); } return -1; } else if( 0 == ret) { _stage = CONN_CONNECTED; OnConnected(); } //exit: return CCReactor::Instance()->AttachPoller(this); }
int NL_QQwry::GetIndex(CString szIP) { int index=-1; DWORD dwInputIP; DWORD dwStartIP; dwInputIP=IP2DWORD(szIP); // //利用半跳方法速度快一些 // int iT; int iB,iE; iB=0; iE=GetRecordCount()-1; iT=iE/2; while(iB<iE) { dwStartIP=GetSIP(iT); if(dwInputIP==dwStartIP) { index =iT; break; } if((iE-iB)<=1) { for(int i=iB;i<=iE;i++) { dwStartIP=GetSIP(i); if(dwStartIP<=dwInputIP && dwInputIP<=m_dwLastIP) { index=i; break; } } break; } if(dwInputIP>dwStartIP) { iB=iT; } else { iE=iT; } iT=iB+(iE-iB)/2; } return index; }