diff --git a/demo/insert.c b/demo/insert.c index de11bfa..4f96c1b 100644 --- a/demo/insert.c +++ b/demo/insert.c @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量 // stUser.acct_id = time(NULL); // 对结构体赋值 - strcpy(stUser.user_no, "20180223"); // 对结构体赋值 + strcpy(stUser.user_no, "20180224"); // 对结构体赋值 strcpy(stUser.user_type, "1"); // 对结构体赋值 strcpy(stUser.user_nm, "Savens Liu"); // 对结构体赋值 strcpy(stUser.user_addr, "China"); // 对结构体赋值 diff --git a/demo/tvmpop.c b/demo/tvmpop.c index 51116c2..66e0982 100644 --- a/demo/tvmpop.c +++ b/demo/tvmpop.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) } queueinit(pstSavm, stUser, QUEUE_USER_INFO); - if(RC_SUCC != lTvmPop(pstSavm, (void *)&stUser, QUE_NORMAL)) // 插入记录 + if(RC_SUCC != lTvmPop(pstSavm, (void *)&stUser, QUE_NORMAL)) { fprintf(stderr, "Pop error:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno)); return RC_FAIL; diff --git a/include/tvm.h b/include/tvm.h index a097092..b50ff7d 100644 --- a/include/tvm.h +++ b/include/tvm.h @@ -198,10 +198,11 @@ typedef long CREATE; #define IS_TRUCK_NRML(p) ((p)->m_chTag == DATA_TRUCK_NRML) #define IS_TRUCK_LOCK(p) ((p)->m_chTag == DATA_TRUCK_LOCK) #define SET_DATA_TRUCK(p, type) ((p)->m_chTag = type) -#define TFree(p) if(p) { free(p); p = NULL; } -#define TFgrp(p) do{vDeleteRowgrp(p);p = NULL;}while(0); -#define TFlst(p) do{vDestroyList(p);p = NULL;}while(0); -#define TClose(f) if(f) { fclose(f); f = NULL; } +#define TFree(p) if(p) { free(p); p = NULL; } +#define TFgrp(p) do{vDeleteRowgrp(p);p = NULL;}while(0); +#define TFlst(p) do{vDestroyList(p);p = NULL;}while(0); +#define TClose(f) if(f) { fclose(f); f = NULL; } +#define Tdefstr(d,s,l) if(0 == *d) strncpy(d, s, l); #define Futex(a,o,v,t) syscall(SYS_futex, a, o, v, t, NULL, 0) #define Tremohold(p,r) if(p->m_bHold) r->m_lState = RESOURCE_ABLE; @@ -677,6 +678,13 @@ typedef struct __TVM_BOOT_PARAM char m_szLog[MAX_STRIG_LEN]; }TBoot; +typedef struct __THREAD_RUN +{ + BSock m_epfd; + pthread_t m_tPid; + bool m_bRun; +}TThread; + /************************************************************************************************* STVM user define *************************************************************************************************/ diff --git a/src/conf.c b/src/conf.c index 629cb56..c6edb0b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -791,7 +791,7 @@ long lParseResouce(SATvm *pstSavm, char *pszFile, long *plCout, TDomain **pps strncpy(pv->m_szIp, sgetvalue(szValue, ":", 1), sizeof(pv->m_szIp)); pv->m_lPort = atol(sgetvalue(szValue, ":", 2)); } - else if(!strcasecmp(szTarg, "TIMTOUT")) + else if(!strcasecmp(szTarg, "TIMEOUT")) pv->m_lTimeOut = atol(szValue); else if(!strcasecmp(szTarg, "MAXTRY")) pv->m_lTryMax = atol(szValue); @@ -819,7 +819,7 @@ long lParseResouce(SATvm *pstSavm, char *pszFile, long *plCout, TDomain **pps } pv->m_lGroup = pv->m_lGroup > 0 ? pv->m_lGroup : 1; - pv->m_lTimeOut = pv->m_lTimeOut > 0 ? pv->m_lTimeOut : 5; + pv->m_lTimeOut = pv->m_lTimeOut > 0 ? pv->m_lTimeOut : 2; pv->m_lTryMax = pv->m_lTryMax > 0 ? pv->m_lTryMax : 3; pv->m_lKeepLive= pv->m_lKeepLive > 0 ? pv->m_lKeepLive : 30; } @@ -925,20 +925,19 @@ long lParseDomain(char *pszBuffer, TIndex *pstIndex, TDomain *pstDom, long *p } } - pv->m_lTryMax = 0; + pv->m_lTryMax = 0; pv->m_lLastTime = 0; - pv->m_lStatus = RESOURCE_INIT; - pv->m_table = pstIndex->m_table; - pv->m_lPort = pstDom->m_lPort; - pv->m_lGroup = pstDom->m_lGroup; + pv->m_lStatus = RESOURCE_INIT; + pv->m_table = pstIndex->m_table; + pv->m_lPort = pstDom->m_lPort; + pv->m_lGroup = pstDom->m_lGroup; pv->m_lKeepLive = pstDom->m_lKeepLive; - pv->m_lTimeOut = pstDom->m_lTimeOut; - pv->m_lTryMax = pstDom->m_lTryMax; + pv->m_lTimeOut = pstDom->m_lTimeOut; + pv->m_lTryMax = pstDom->m_lTryMax; strcpy(pv->m_szIp, pstDom->m_szIp); strcpy(pv->m_szTable, pstIndex->m_szTable); strcpy(pv->m_szOwner, pstDom->m_szOwner); - if(!strlen(pv->m_szPart)) - strcpy(pv->m_szPart, pstDom->m_szOwner); + Tdefstr(pv->m_szPart, pstDom->m_szOwner, sizeof(pv->m_szPart)); return RC_SUCC; } @@ -1242,7 +1241,7 @@ long lUnmakeConfig(char *pszFile) if(!bf) { bf = !bf; - fprintf(fp, "GROUP=%ld TIMTOUT=%ld MAXTRY=%ld KEEPALIVE=%ld\n", + fprintf(fp, "GROUP=%ld TIMEOUT=%ld MAXTRY=%ld KEEPALIVE=%ld\n", pstDomain[j].m_lGroup, pstDomain[j].m_lTimeOut, pstDomain[j].m_lTryMax, pstDomain[j].m_lKeepLive); } diff --git a/src/makefile b/src/makefile index 5c1688e..23fb5cf 100755 --- a/src/makefile +++ b/src/makefile @@ -11,7 +11,7 @@ LDFLAG=-shared -g OUTLIB=../lib OUTBIN=../bin -OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o queue.o +OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o queue.o func.o TARGET=$(OUTLIB)/libstvm.a #TARDLL=$(OUTLIB)/libstvm.so TARVER=$(OUTLIB)/libstvm.so.1.2 diff --git a/src/stvm.c b/src/stvm.c index 88d1347..27e2847 100644 --- a/src/stvm.c +++ b/src/stvm.c @@ -404,8 +404,7 @@ long _lParseAlias(SATvm *pstSavm, char *pszTable, char *pszField, char *pszAl strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex)) return RC_FAIL; @@ -1358,8 +1357,7 @@ long _lShowTableInfo(SATvm *pstSavm, char *pszTable, bool bRmt) strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(bRmt) { @@ -2013,11 +2011,8 @@ long _lExeUpdate(SATvm *pstSavm, TIndex *pstIndex, void *pvNew, char *pvData, else lRet = lUpdate(pstSavm, (void *)pvNew); if(RC_SUCC != lRet) - { - fprintf(stderr, "update table (%s) failure, %s\n", pstIndex->m_szTable, - sGetTError(pstSavm->m_lErrno)); return RC_FAIL; - } + lTime -= lGetTiskTime(); fprintf(stdout, "---(%ld) records updated, ep(%d), %s---\n", pstSavm->m_lEffect, pstSavm->m_lEType, @@ -2078,13 +2073,9 @@ long _lExeInsert(SATvm *pstSavm, TIndex *pstIndex, void *pvInsert, bool bRmt) else lRet = lInsert(pstSavm); if(RC_SUCC != lRet) - { - fprintf(stderr, "insert table (%s) failure, %s\n", pstIndex->m_szTable, - sGetTError(pstSavm->m_lErrno)); return RC_FAIL; - } - lTime -= lGetTiskTime(); + lTime -= lGetTiskTime(); fprintf(stdout, "---(%ld) records inserted, %s---\n", pstSavm->m_lEffect, sGetCostTime(-1 * lTime)); return RC_SUCC; } @@ -2205,11 +2196,8 @@ long _lCountSelect(SATvm *pstSavm, TIndex *pstIndex, char *pvData, bool bRmt) else lRet = lCount(pstSavm, &lSum); if(lRet != RC_SUCC) - { - fprintf(stderr, "count table (%s) failure, %s\n", pstIndex->m_szTable, - sGetTError(pstSavm->m_lErrno)); return RC_FAIL; - } + lTime -= lGetTiskTime(); fprintf(stdout, "COUNT(*)\n"); @@ -2241,13 +2229,9 @@ long _lExeClick(SATvm *pstSavm, TIndex *pstIndex, char *pvData, bool bRmt) else lRet = lClick(pstSavm, &ulHits); if(lRet != RC_SUCC) - { - fprintf(stderr, "count table (%s) failure, %s\n", pstIndex->m_szTable, - sGetTError(pstSavm->m_lErrno)); return RC_FAIL; - } - lTime -= lGetTiskTime(); + lTime -= lGetTiskTime(); fprintf(stdout, "HITSPOT\n"); fprintf(stdout, "%zu\n", ulHits); fflush(stdout); @@ -2822,8 +2806,7 @@ long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(!strcmp(stIndex.m_szTable, "SEQUENCE")) return lParseSequece(pstSavm, stIndex.m_szPart, pszField, bRmt); @@ -3034,8 +3017,7 @@ long _lParseUpdate(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(bRmt) { @@ -3178,8 +3160,7 @@ long _lParseDelete(SATvm *pstSavm, char *pszTable, char *pszWhere, bool bRmt strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(bRmt) { @@ -3439,8 +3420,7 @@ long _lParseInsert(SATvm *pstSavm, char *pszTable, char *pszField, char *pszV strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(bRmt) { @@ -3597,8 +3577,7 @@ long _lTruncateSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt) strncpy(stIndex.m_szPart, sgetvalue(szTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(szTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(bRmt) { @@ -3654,8 +3633,7 @@ long _lDropSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt) strncpy(stIndex.m_szPart, sgetvalue(szTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(szTable, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(bRmt) { @@ -3717,8 +3695,7 @@ long _lLoadSyntax(SATvm *pstSavm, char *pszSQL) strncpy(stIndex.m_szPart, sgetvalue(szParam, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szTable, sgetvalue(szParam, "@", 1), sizeof(stIndex.m_szTable)); supper(stIndex.m_szTable); - if(0x00 == stIndex.m_szPart[0]) - strcpy(stIndex.m_szPart, sGetNode()); + Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart)); if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex)) return RC_FAIL; @@ -4074,6 +4051,8 @@ long lStopSystem(TBoot *pstBoot, char *pszApp) snprintf(szCmd, sizeof(szCmd), "ps -u %s|grep -E \"%s|%s\"|awk '{print $1}'", getenv("LOGNAME"), TVM_LOCAL_SERV, TVM_REMOTE_DOM); + if(!bIsTvmBoot()) return RC_SUCC; + if(TVM_BOOT_CLUSTER == pstBoot->m_lBootType) lOfflineNotify(pstSavm, pstBoot->m_lBootPort); @@ -4880,7 +4859,15 @@ int main(int argc, char *argv[]) TBoot *pstBoot = (TBoot *)pBootInitial(); if(3 == argc && !strcmp(argv[1], "-c")) + { + if(bIsTvmBoot() && TVM_BOOT_SIMPLE != pstBoot->m_lBootType) + { + fprintf(stderr, "build failure, please stop STVM and do this !\n"); + return RC_FAIL; + } + return lMakeConfig(argv[2]); + } else if(3 == argc && !strcmp(argv[1], "-o")) return lUnmakeConfig(argv[2]); @@ -4892,7 +4879,7 @@ int main(int argc, char *argv[]) vCheckTvmEnv(); memset(szCom, 0, sizeof(szCom)); - while(-1 != (iChoose = getopt(argc, argv, "w::s::p::f::d:m:t:i:u:l:c:v?::"))) + while(-1 != (iChoose = getopt(argc, argv, "w::s::p::f::d:m:t:i:u::l:c:v?::"))) { switch(iChoose) { @@ -4933,9 +4920,12 @@ int main(int argc, char *argv[]) if(0x59 != lRet && 0x79 != lRet) return RC_SUCC; if(RC_SUCC != lResetLock(pstSavm, atol(optarg))) - fprintf(stderr, "重置表(%ld)失败, %s\n", atol(optarg), sGetTError(pstSavm->m_lErrno)); + { + fprintf(stderr, "reset table (%ld) lock failure, %s\n", atol(optarg), + sGetTError(pstSavm->m_lErrno)); + } else - fprintf(stderr, "重置表(%ld)完成, completed successfully !!\n", atol(optarg)); + fprintf(stderr, "reset table (%ld) success, completed successfully !!\n", atol(optarg)); return RC_SUCC; case 'v': fprintf(stdout, "%s\n", sGetTVMVers()); @@ -4949,14 +4939,11 @@ int main(int argc, char *argv[]) if(1 == lAction) { - vTableStruck(atol(optarg)); - return RC_SUCC; - } - else if(2 == lAction) - { -// vTableStruck(atol(optarg)); + vTableStruck(table); return RC_SUCC; } + else if(3 == lAction) + return lUnuseDump(pstSavm, table); vPrintFunc(basename(argv[0])); return RC_SUCC; diff --git a/src/tcp.c b/src/tcp.c index bb82fab..b7bde42 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -1836,18 +1836,24 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi pstCon->m_lRead = 0; pstCon->m_bHead = false; - pstRun = (RunTime *)pGetRunTime(pstSovm, pstFace->m_table); - pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch; - pstRun->m_pvAddr = pstSovm->stRunTime[pstFace->m_table].m_pvAddr; + + pstRun = (RunTime *)pGetRunTime(pstSavm, pstFace->m_table); if(!pstRun->m_bAttch || !pstRun->m_pvAddr) { //Tlog("initial table:%d, %d, %d", pstFace->m_table, pstFace->m_enum, pstRun->m_bAttch); - if(RC_SUCC != lInitSATvm(pstSovm, pstFace->m_table)) + if(RC_SUCC != lInitSATvm(pstSavm, pstFace->m_table)) { pstFace->m_lRows = 0; pstFace->m_lErrno = pstSovm->m_lErrno; return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); } + + memcpy(&pstSovm->stRunTime[pstFace->m_table], pstRun, sizeof(RunTime)); + } + else + { + pstSovm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch; + pstSovm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr; } if(PROTOCAL_JAVA & pstFace->m_enum) @@ -1865,10 +1871,8 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi pstSovm->lFind = pstFace->m_lFind; pstSovm->tblName = pstFace->m_table; pstSovm->lSize = pstFace->m_lDLen; - lRet = lProcaOperate(pstSovm, pstCon, pstFace, pvData); - pstSavm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch; - pstSavm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr; - if(RC_SUCC == lRet) return RC_SUCC; + if(RC_SUCC == lProcaOperate(pstSovm, pstCon, pstFace, pvData)) + return RC_SUCC; return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); } @@ -1885,10 +1889,8 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi pstSovm->lFind = pstFace->m_lFind; pstSovm->tblName = pstFace->m_table; pstSovm->lSize = pstFace->m_lDLen; - lRet = lEventOperate(pstSovm, pstCon, pstFace, pvData); - pstSavm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch; - pstSavm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr; - if(RC_SUCC == lRet) return RC_SUCC; + if(RC_SUCC == lEventOperate(pstSovm, pstCon, pstFace, pvData)) + return RC_SUCC; return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); } @@ -1906,23 +1908,21 @@ void* vEpollListen(void *pvParam) SKCon *pstCon = NULL; TFace *pstFace = NULL; epollevt events[MAX_EVENTS]; - BSock epfd = *((long *)pvParam); - SATvm *pstSavm = (SATvm *)calloc(1, sizeof(SATvm)); + TThread *pstTrd = (TThread *)pvParam; + SATvm *pstSavm = (SATvm *)pCloneSATvm(); pthread_detach(pthread_self()); - - vHoldConnect(pstSavm); if(RC_SUCC != lTvmBuffer(pstSavm)) return NULL; while(g_eRun) { - nWait = epoll_wait(epfd, events, MAX_EVENTS, 500); + nWait = epoll_wait(pstTrd->m_epfd, events, MAX_EVENTS, 500); for(i = 0; i < nWait; i++) { pstCon = (SKCon *)events[i].data.ptr; if(pstCon->m_isListen) - lEpollAccept(pstSavm, epfd, pstCon); + lEpollAccept(pstSavm, pstTrd->m_epfd, pstCon); else if(events[i].events & EPOLLIN) { if(false == pstCon->m_bHead) @@ -1938,7 +1938,7 @@ void* vEpollListen(void *pvParam) pstCon->m_bWork = false; } pstCon->m_pstWork = NULL; - epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); + epoll_ctl(pstTrd->m_epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); TFree(pstCon->pstFace); TFree(pstCon->pstVoid); close(pstCon->m_skSock); @@ -1973,7 +1973,7 @@ void* vEpollListen(void *pvParam) pstCon->m_bWork = false; } pstCon->m_pstWork = NULL; - epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); + epoll_ctl(pstTrd->m_epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); TFree(pstCon->pstFace); TFree(pstCon->pstVoid); close(pstCon->m_skSock); @@ -1987,9 +1987,11 @@ LISTEN_ERROR: continue; } - close(epfd); + close(pstTrd->m_epfd); pstSavm->pstVoid = NULL; vTvmDisconnect(pstSavm); + pstTrd->m_bRun = false; + pthread_exit(NULL); return NULL; } @@ -2152,7 +2154,7 @@ void vDomainEvent(SATvm *pstSavm, long lPort) while(g_eRun) { - for(sleep(1), list = pGetDomgrp(); list; list = list->pstNext) + for(usleep(5000), list = pGetDomgrp(); list && g_eRun; list = list->pstNext) { if(NULL == (pstDom = (TDomain *)list->psvData)) continue; @@ -2407,8 +2409,8 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode) pid_t lPid; epollevt event; BSock epfd = -1; - pthread_t *tPid = NULL; SKCon *pstCon = NULL; + TThread *pstTrd = NULL; if(!pstBoot || pstBoot->m_lBootExec < 1) // 线程数量 { @@ -2462,11 +2464,18 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode) signal(SIGPIPE, SIG_IGN); signal(SIGTRAP, SIG_IGN); - tPid = malloc(sizeof(pthread_t) * pstBoot->m_lBootExec); vHoldConnect(pstSavm); + if(NULL == (pstTrd = (TThread *)calloc(pstBoot->m_lBootExec, sizeof(TThread)))) + { + fprintf(stderr, "create pthread tid failed, %s\n", strerror(errno)); + return RC_FAIL; + } + for(i = 0; i < pstBoot->m_lBootExec; i ++) { - if(0 != pthread_create(&tPid[i], NULL, vEpollListen, (void*)&epfd)) + pstTrd[i].m_epfd = epfd; + pstTrd[i].m_bRun = true; + if(0 != pthread_create(&pstTrd[i].m_tPid, NULL, vEpollListen, (void*)&pstTrd[i])) { fprintf(stderr, "create thread error, %s\n", strerror(errno)); exit(-1); @@ -2479,13 +2488,18 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode) vRemoteResouce(pstSavm, eMode, pstBoot->m_lBootPort); vTvmDisconnect(pstSavm); + for(i = 0; i < pstBoot->m_lBootExec; i ++) { - for(usleep(1000);ESRCH != pthread_kill(tPid[i], 0); usleep(1000)); + usleep(500); + if(!pstTrd[i].m_bRun) + continue; + + for(;(pstTrd[i].m_bRun) && (ESRCH != pthread_kill(pstTrd[i].m_tPid, 0)); usleep(1000)); } vCloseDomain(); - TFree(tPid); + TFree(pstTrd); Tlog("Service thread exits"); exit(-1); } diff --git a/src/tree.c b/src/tree.c index e131446..0b687e0 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1103,8 +1103,7 @@ char* sGetTableName(TABLE t) *************************************************************************************************/ char* sGetTablePart(TABLE t, char *pszNode) { - if(0x00 == g_stTblDef[t].m_szPart[0]) - strncpy(g_stTblDef[t].m_szPart, pszNode, MAX_FIELD_LEN); + Tdefstr(g_stTblDef[t].m_szPart, pszNode, MAX_FIELD_LEN); return g_stTblDef[t].m_szPart; } diff --git a/stvm.conf b/stvm.conf index 7c29027..45b2022 100644 --- a/stvm.conf +++ b/stvm.conf @@ -15,8 +15,8 @@ LOGNAME="/home/stvm/log/stvm.log" TABLE=15 PERMIT=15 *REMOTE_DOMAIN -GROUP=1 DOMAINID="DBS" WSADDR="192.168.5.20:5010" TIMETOUT=2 MAXTRY=3 KEEPALIVE=30 -GROUP=2 DOMAINID="CTS" WSADDR="192.168.5.20:5011" TIMETOUT=2 MAXTRY=3 KEEPALIVE=30 +GROUP=1 DOMAINID="DBS" WSADDR="192.168.5.20:5010" TIMEOUT=2 MAXTRY=3 KEEPALIVE=30 +GROUP=2 DOMAINID="CTS" WSADDR="192.168.5.20:5011" TIMEOUT=2 MAXTRY=3 KEEPALIVE=30 *REMOTE_TABLE TABLE=8 TABLENAME="TBL_BRH_INFO"