int ExtConn::connError(int errCode) { LS_DBG_L(this, "Connection to [%s] on request #%d, confirmed %d, error: %s!", m_pWorker->getURL(), m_iReqProcessed, (int)m_iCPState, strerror(errCode)); if (errCode == EINTR) return 0; close(); ExtRequest *pReq = getReq(); if (pReq) { if (((m_pWorker->getConnPool().getFreeConns() == 0) || ((pReq->getAttempts() % 3) == 0)) && ((errCode == EPIPE) || (errCode == ECONNRESET)) && (pReq->isRecoverable()) && (m_iReqProcessed) && (!m_iCPState)) { pReq->incAttempts(); pReq->resetConnector(); if (reconnect() == 0) return 0; close(); } } return m_pWorker->connectionError(this, errCode); // if ( !m_pWorker->connectionError( this, errCode ) ) // { // //if (( errCode != ENOMEM )&&(errCode != EMFILE ) // // &&( errCode != ENFILE )) // } }
int ExtConn::onEventDone() { switch (m_iState) { case ABORT: case CLOSING: close(); if (!getReq()) m_pWorker->getConnPool().removeConn(this); else getReq()->endResponse(0, 0); //reconnect(); break; } return 0; }
void ExtConn::onSecTimer() { int secs = DateTime::s_curTime - m_tmLastAccess; if (m_iState == CONNECTING) { if (secs >= 2) { LS_NOTICE(this, "ExtConn timed out while connecting."); connError(ETIMEDOUT); } } else if (m_iState == DISCONNECTED) { } else if (getReq()) { if (!m_iCPState && m_iReqProcessed == 0) { if (secs >= m_pWorker->getTimeout()) { LS_NOTICE(this, "ExtConn timed out while processing."); connError(ETIMEDOUT); } else if ((secs == 10) && (getReq()->isRecoverable())) { // LS_DBG_L(this, "No response in 10 seconds, possible dead " // "lock, try starting a new instance."); m_pWorker->addNewProcess(); } } } else if ((m_iState == PROCESSING) && (secs > m_pWorker->getConfigPointer()->getKeepAliveTimeout())) { LS_DBG_L(this, "Idle connection timed out, close!"); close(); } }
int main(int argc,char* argv[]) { int retCode = 0; unsigned int uid; unsigned int age; unsigned int lv = 0; std::string name; std::string city; std::string descr; unsigned int salary; unsigned int uid1; unsigned int age1; std::string name1; std::string city1; std::string descr1; unsigned int salary1; lv = atoi(argv[1]); TTC::init_log("dtc_client"); TTC::set_log_level(lv); TTC::Server stServer; // 只要server不析构,后台会保持长连接 stServer.IntKey(); // 声明key类型 stServer.SetTableName("t_dtc_example");//设置ttc的表名,与table.conf中tablename应该一样 stServer.SetAddress("192.168.214.62", "10901");//设置的ttc的ip和端口 stServer.SetTimeout(5); // 设置网络超时时间 stServer.SetAccessKey("0000090184d9cfc2f395ce883a41d7ffc1bbcf4e"); // 设置访问码 AccessToken,在申请dtc实例的时候网站端会生成 TTC::InsertRequest insertReq(&stServer); //retCode = insertReq.SetKey(key); uid = atoi(argv[2]); name = std::string(argv[3]); city = std::string(argv[4]); descr = std::string(argv[5]); age = atoi(argv[6]); salary = atoi(argv[7]); insertReq.SetKey(uid); //insertReq.Set("key", 100003); insertReq.Set("uid", uid); insertReq.Set("name", name.c_str()); insertReq.Set("city", city.c_str()); insertReq.Set("descr", descr.c_str()); insertReq.Set("age", age); insertReq.Set("salary", salary); TTC::Result stResult; retCode = insertReq.Execute(stResult); printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.ErrorMessage(), stResult.ErrorFrom()); if(retCode == 0) { TTC::GetRequest getReq(&stServer); getReq.SetKey(uid); if(retCode == 0) retCode = getReq.Need("uid");//设置需要select的字段,注意第一个key字段不能在这里出现 if(retCode == 0) retCode = getReq.Need("name"); if(retCode == 0) retCode = getReq.Need("city"); if(retCode == 0) retCode = getReq.Need("descr"); if(retCode == 0) retCode = getReq.Need("age"); if(retCode == 0) retCode = getReq.Need("salary"); if(retCode != 0) { printf("get-req set key or need error: %d", retCode); fflush(stdout); return(-1); } // execute & get result stResult.Reset(); retCode = getReq.Execute(stResult); printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult.ErrorMessage(), stResult.ErrorFrom()); retCode = stResult.FetchRow();//开始获取数据 printf("uid:%lu\n", stResult.IntValue("uid")); printf("name: %s\n", stResult.StringValue("name"));//输出binary类型的数据 printf("city: %s\n", stResult.StringValue("city")); printf("descr: %s\n", stResult.BinaryValue("descr")); printf("age: %lu\n", stResult.IntValue("age"));//输出int类型的数据 printf("salary: %lu\n", stResult.IntValue("salary"));//输出int类型的数据 } printf("-------------first request end -----------------\n"); printf("-------------second request begin---------------\n"); TTC::Server stServer1; // 只要server不析构,后台会保持长连接 stServer1.IntKey(); // 声明key类型 stServer1.SetTableName("tp1");//设置ttc的表名,与table.conf中tablename应该一样 stServer1.SetAddress("192.168.214.62", "10201");//设置的ttc的ip和端口 stServer1.SetTimeout(5); // 设置网络超时时间 stServer1.SetAccessKey("0000020184d9cfc2f395ce883a41d7ffc1bbcf4e"); // 设置访问码 AccessToken,在申请dtc实例的时候网站端会生成 TTC::InsertRequest insertReq1(&stServer1); //retCode = insertReq.SetKey(key); uid1 = atoi(argv[8]); name1 = std::string(argv[9]); city1 = std::string(argv[10]); descr1 = std::string(argv[11]); age1 = atoi(argv[12]); salary1 = atoi(argv[13]); insertReq1.SetKey(uid1); //insertReq.Set("key", 100003); insertReq1.Set("uid", uid1); insertReq1.Set("name", name1.c_str()); insertReq1.Set("city", city1.c_str()); insertReq1.Set("descr", descr1.c_str()); insertReq1.Set("age", age1); insertReq1.Set("salary", salary1); TTC::Result stResult1; retCode = insertReq1.Execute(stResult1); printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult1.ErrorMessage(), stResult1.ErrorFrom()); if(retCode == 0) { TTC::GetRequest getReq1(&stServer1); getReq1.SetKey(uid); if(retCode == 0) retCode = getReq1.Need("uid");//设置需要select的字段,注意第一个key字段不能在这里出现 if(retCode == 0) retCode = getReq1.Need("name"); if(retCode == 0) retCode = getReq1.Need("city"); if(retCode == 0) retCode = getReq1.Need("descr"); if(retCode == 0) retCode = getReq1.Need("age"); if(retCode == 0) retCode = getReq1.Need("salary"); if(retCode != 0) { printf("get-req set key or need error: %d", retCode); fflush(stdout); return(-1); } // execute & get result stResult1.Reset(); retCode = getReq1.Execute(stResult1); printf("retCode:%d, errmsg:%s, errfrom:%s\n", retCode, stResult1.ErrorMessage(), stResult1.ErrorFrom()); retCode = stResult1.FetchRow();//开始获取数据 printf("uid:%lu\n", stResult1.IntValue("uid")); printf("name: %s\n", stResult1.StringValue("name"));//输出binary类型的数据 printf("city: %s\n", stResult1.StringValue("city")); printf("descr: %s\n", stResult1.BinaryValue("descr")); printf("age: %lu\n", stResult1.IntValue("age"));//输出int类型的数据 printf("salary: %lu\n", stResult1.IntValue("salary"));//输出int类型的数据 } return 0; }
HttpSession *HttpSession::newSubSession(SubSessInfo_t *pSubSessInfo) { //for subsession, we intentionally turn off // keepalive // chunk // gzip compression // security //detect loop subsessions int depth = 1; if (m_pParent) { depth = 1 + ((HioChainStream *)getStream())->getDepth(); if (depth > 9) return NULL; } if (detectLoopSubSession(pSubSessInfo) == 1) return NULL; HttpSession *pSession = HttpSessionPool::getSession(); if (! pSession) return NULL; //pSession->setSsiRuntime( m_pSsiRuntime ); HioChainStream *pStream = new HioChainStream(); pStream->setHandler(pSession); pSession->setStream(pStream); pSession->getReq()->setILog(pStream); pSession->m_pClientInfo = m_pClientInfo; pSession->m_pSslConn = m_pSslConn; pStream->setDepth(depth); pSession->getReq()->setMethod(pSubSessInfo->m_method); if (pSession->getReq()->clone(getReq(), pSubSessInfo)) { pStream->setHandler(NULL); delete pStream; HttpSessionPool::recycle(pSession); return NULL; } pSession->setFlag(HSF_SEC_CLEARED | HSF_SEC_RESP_CLEARED | HSF_SUB_SESSION); pSession->getResp()->reset(); #ifdef _ENTERPRISE_ pSession->getResp()->setCacheStore(getCacheStore()); #endif LS_DBG_M(getLogSession(), "Create SUB SESSION: %d, flag: %d, " "method: %s, URI: %s, len: %d, QS: %s, len: %d", m_iSubReqSeq, pSubSessInfo->m_flag, HttpMethod::get(pSubSessInfo->m_method), pSubSessInfo->m_cacheKey.m_pUri, pSubSessInfo->m_cacheKey.m_iUriLen, pSubSessInfo->m_cacheKey.m_pQs ? pSubSessInfo->m_cacheKey.m_pQs : "", pSubSessInfo->m_cacheKey.m_iQsLen); HttpSession *parent = NULL; if (pSubSessInfo->m_flag & SUB_REQ_DETACHED) { pStream->setParentSession(NULL); //set Stream to black hole mode, pStream->setFlag(HIO_FLAG_BLACK_HOLE, 1); //parent = getBackGroundSession(); } else { pStream->setSequence(m_iSubReqSeq++); parent = this; } if (pSubSessInfo->m_flag & SUB_REQ_NOABORT) pSession->setFlag(HSF_NO_ABORT, 1); if (pSubSessInfo->m_flag & SUB_REQ_NOCACHE) pSession->setFlag(HSF_NOCACHE, 1); pSession->m_pParent = parent; return pSession; }