//连接池监控 void scpool_check() { int n,i,num; pool *pl; resource *rs; INT64 now; char buf[32]; T_Connect *conn=NULL; if(!scpool) return; now=now_usec(); pl=scpool; for(n=0;n<SCPOOLNUM;n++,pl++) { if(!pl->lnk) continue; rs=pl->lnk; num=pl->resource_num; if(log_level) ShowLog(log_level,"%s:scpool[%d],num=%d",__FUNCTION__,n,num); pthread_mutex_lock(&pl->mut); for(i=0;i<num;i++,rs++) if(rs->TCBno<0) { if(rs->Conn.Socket>-1 && (now-rs->timestamp)>299000000) { //空闲时间太长了 disconnect(&rs->Conn); rs->cli.Errno=-1; if(log_level) ShowLog(log_level,"%s:Close SCpool[%d].lnk[%d],since %s",__FUNCTION__, n,i,rusecstrfmt(buf,rs->timestamp,YEAR_TO_USEC)); } } else { if(rs->Conn.Socket>-1 && (now-rs->timestamp)>299000000) { //占用时间太长了 if(-1==get_TCB_status(rs->TCBno)) { //TCB已经结束,释放之 if(log_level) ShowLog(log_level,"%s:scpool[%d].lnk[%d] TCB:%d to be release", __FUNCTION__,n,i,rs->TCBno); rs->cli.Errno=-1; conn=&rs->Conn; release_SC_connect(&conn,rs->TCBno,n); } else { if(log_level) ShowLog(log_level,"%s:scpool[%d].lnk[%d] used by TCB:%d,since %s", __FUNCTION__,n,i,rs->TCBno, rusecstrfmt(buf,rs->timestamp,YEAR_TO_USEC)); } } } pthread_mutex_unlock(&pl->mut); } }
int get_one_str(char *buf,void *data,T_PkgType *typ,char CURDLM) { register char *cp1,*cp2; int cnt,J,len; char datebuf[31]; char *sp; //short iTiny; T_PkgType Char_Type[2]; cp1=buf; *cp1=0; cnt=0; cp2 = (char *)data+typ->offset; sp=cp2; if(isnull(cp2,typ->type)) return cnt; switch(typ->type) { case CH_BYTE: cnt=b2h(cp1,cp2,typ->len); break; case CH_CLOB: Char_Type[0].type=CH_CHAR; Char_Type[0].len=-1; Char_Type[0].offset=0; Char_Type[1].type=-1; Char_Type[1].len=0; J=get_one_str(buf,*(char **)cp2,Char_Type,CURDLM); cnt += J; break; case CH_DATE: case CH_CNUM: case CH_CHAR: len=(typ->len>0)?typ->len-1:strlen(cp2); for(J=0;J<len&&*cp2;J++,cnt++) { if(!CURDLM) goto norm; switch(*cp2) { case ESC_CHAR: if(cp2>sp && GBK_flag && firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) goto norm; *cp1++=*cp2; *cp1++=*cp2++; cnt++; break; case '\n': if(cp2>sp && firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) cp1[-1]&=0x7f; *cp1++=ESC_CHAR; *cp1++='n'; cp2++; cnt++; break; default: if(*cp2==CURDLM) { if(cp2>sp && GBK_flag && firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) goto norm; *cp1++=ESC_CHAR; *cp1++='G'; cp2++; cnt++; break; } norm: *cp1++=*cp2++; break; } } *cp1=0; if(cp2>sp) { if(firstcc((unsigned char *)sp,(unsigned char *)cp2-1)) cp1[-1] &= 0x7f; } break; case CH_FLOAT: if(!typ->format) cnt=sprintf(cp1,"%g", (double)*(float *)cp2); else cnt=sprintf(cp1,typ->format,(double)*(float *)cp2); break; case CH_DOUBLE: if(!typ->format) cnt=sprintf(cp1,"%g", *(double *)cp2); else cnt=sprintf(cp1,typ->format,*(double *)cp2); break; case CH_LDOUBLE: if(!typ->format) cnt=sprintf(cp1,"%Lg", *(long double *)cp2); else cnt=sprintf(cp1,typ->format,*(long double *)cp2); break; case CH_TINY: if(typ->format) cnt=sprintf(cp1,typ->format,255&*cp2); else cnt=itoStr((int)(*cp2),cp1)-cp1; break; case CH_SHORT: if(typ->format) cnt=sprintf(cp1,typ->format,0XFFFF&*(short *)cp2); else cnt=itoStr((int)(*(short *)cp2),cp1)-cp1; break; case CH_INT: if(typ->format) cnt=sprintf(cp1,typ->format,*(int *)cp2); else cnt=itoStr(*(int *)cp2,cp1)-cp1; break; case CH_LONG: if(typ->format) cnt=sprintf(cp1,typ->format,*(long *)cp2); else cnt=lltoStr((INT64)(*(long *)cp2),cp1)-cp1; break; case CH_INT64: if(typ->format) cnt=sprintf(cp1,typ->format,*(INT64 *)cp2); else cnt=lltoStr(*(INT64 *)cp2,cp1)-cp1; break; case CH_CJUL: case CH_JUL: if(typ->format) { rjultostrfmt(datebuf,*(int *)cp2, typ->format); } else { rjultostrfmt(datebuf,*(int *)cp2, "YYYYMMDD"); } cnt=sprintf(cp1,"%s",datebuf); break; case CH_MINUTS: case CH_CMINUTS: if(typ->format) { rminstrfmt(datebuf,*(INT4 *)cp2,typ->format); } else rminstr(datebuf,*(INT4 *)cp2); cnt=sprintf(cp1,"%s",datebuf); break; case CH_TIME: case CH_CTIME: if(typ->format) { rsecstrfmt(datebuf,*(INT64 *)cp2,typ->format); } else rsecstrfmt(datebuf,*(INT64 *)cp2,"YYYYMMDDHH24MISS"); cnt=sprintf(cp1,"%s",datebuf); break; case CH_USEC: if(typ->format) { rusecstrfmt(datebuf,*(INT64 *)cp2,typ->format); } else rusecstrfmt(datebuf,*(INT64 *)cp2,"YYYYMMDDHH24MISS.FF6"); cnt=sprintf(cp1,"%s",datebuf); break; default: break; } return cnt; }