DWORD CServerApp::WorkTh(LPVOID param) { UserPoolData* ud = (UserPoolData*)param; MessageQueue::ValueType msg = (MessageQueue::ValueType)ud->pData; switch(msg->DataType()) { case D_BASE_INIT_COMP: // 通道初始化 InitComp(msg); break; case D_BASE_CALLIN: // 呼入通知 break; case D_BASE_TRUNK_INFO: // 通道状态变迁 break; case D_DB_RESULT: // 定表处理 RunSql(msg); break; case D_DB_FIELD: // 动态表处理 RunDynSql(msg); break; } //释放消息占用内存 delete msg; return 0; }
int CsObjectInt::CsComprLZC (SAP_INT sumlen, SAP_BYTE * inbuf, SAP_INT inlen, SAP_BYTE * outbuf, SAP_INT outlen, SAP_INT option, SAP_INT * bytes_read, SAP_INT * bytes_written) /*--------------------------------------------------------------------*/ /* LZC method to compress a file */ /* */ /* Adaptive Dictionary Compression */ /* Lempel-Zip-Thomas */ /* */ /* */ /* Input: */ /* ----- */ /* sumlen length of data stream to compress */ /* inbuf Pointer to input memory */ /* inlen Length of input memory */ /* outbuf Pointer to output area */ /* outlen Length of output area */ /* option Compress option: */ /* CS_INIT_COMPRESS initial */ /* CS_NORMAL_COMPRESS */ /* Output: */ /* ------ */ /* bytes_read Bytes read from input buffer */ /* bytes_compressed Bytes compressed to output buffer */ /* */ /* Internal Functions: */ /* ------------------ */ /* InitComp Initialize Compression */ /* PUTCODE Write Code to output buffer */ /* */ /* Return Code: */ /* ----------- */ /* CS_END_OF_STREAM End of input reached */ /* CS_END_INBUFFER End of input reached */ /* CS_END_OUTBUFFER End of output reached */ /* */ /* CS_E_IN_BUFFER_LEN Input buffer length to short */ /* CS_E_OUT_BUFFER_LEN Output Buffer length to short */ /* CS_E_INVALID_SUMLEN sumlen <= 0 */ /* CS_E_INVALID_ADDR Invalid addr for input or output buffer*/ /* CS_E_FATAL internal (should never happen) */ /* */ /*--------------------------------------------------------------------*/ { register SAP_INT fcode; register CODE_INT i = 0; register BYTE_TYP *inptr = inbuf; register int c; register CODE_INT disp; int rc; *bytes_read = 0; *bytes_written = 0; /* Check input parameters ..........................................*/ if (inlen < 0) return CS_E_IN_BUFFER_LEN; /* return ............*/ if (outlen < 0) return CS_E_OUT_BUFFER_LEN; /* return ............*/ if (inbuf == (BYTE_TYP *) 0 || outbuf == (BYTE_TYP *) 0) return CS_E_INVALID_ADDR; /* return ............*/ if (inbuf == outbuf) return CS_E_IN_EQU_OUT; /* return ............*/ csc.outptr = outbuf; if (option & CS_INIT_COMPRESS) /* only initial ................*/ { if (sumlen <= 0) return CS_E_INVALID_SUMLEN; /* return ..........*/ rc = InitComp (outbuf, outlen, sumlen); if (rc) return rc; /* return with Error ...............*/ csc.cs_offset = 0; csc.csc_offset = 0; csc.in_count_sum = 0; csc.put_n_bytes = 0; csc.bytes_out = 0; csc.sflush = 0; csc.org_len = sumlen; /* save sum length .................*/ csc.outptr = outbuf + CS_HEAD_SIZE; /* 4 byte length, 4 byte header*/ csc.hshift = 0; for (fcode = (SAP_INT) csc.hsize; fcode < 65536; fcode += fcode) (csc.hshift)++; csc.hshift = 8 - csc.hshift; /* set hash code range bound .......*/ csc.ent = (CODE_INT) -1; if (inlen == 0) /* only header .....................*/ { *bytes_written = CS_HEAD_SIZE; csc.bytes_out += *bytes_written; return CS_END_INBUFFER; } } if (csc.ent == (CODE_INT) -1) /* get first byte ..................*/ csc.ent = *inptr++; csc.end_inbuf = inbuf + inlen; /* end of input buffer .............*/ csc.end_outbuf = outbuf + outlen; /* end of output buffer ............*/ if (csc.sflush == 1) /* end of outbuf in last run, must output CLEAR .*/ { if ((rc = PutCode ((CODE_INT) CLEAR)) < 0) goto ende; if (csc.put_n_bytes) /* no more space in outbuf .........*/ { rc = CS_END_OUTBUFFER; goto ende; } csc.sflush = 0; } while (inptr < csc.end_inbuf) /* until end of input ...........*/ { c = *inptr++; /* next char ....................*/ /* hash function ................*/ fcode = (SAP_INT) (((SAP_INT) c << csc.maxbits) + csc.ent); i = (((CODE_INT)c << csc.hshift) ^ csc.ent); /* xor hashing ...........*/ if (i < 0) return CS_E_FATAL; /* should never happen ..........*/ if (HTABOF (i) == fcode) /* found in htab ................*/ { csc.ent = CODETABOF (i); continue; } else if ((SAP_INT)HTABOF (i) < 0) /* empty slot ....................*/ goto nomatch; disp = csc.hsize - i; /* secondary hash (G. Knott) .....*/ if (i == 0) disp = 1; probe: if ((i -= disp) < 0) i += csc.hsize; if (HTABOF (i) == fcode) /* found in htab .................*/ { csc.ent = CODETABOF (i); continue; /* get next char .................*/ } if ( (SAP_INT)HTABOF (i) > 0 ) goto probe; /* test again ....................*/ nomatch: /* new entry .....................*/ PUTCODE ((CODE_INT) csc.ent) csc.ent = c; if (csc.free_ent < csc.maxmaxcode) /* enough space in table ? .......*/ { CODETABOF (i) = (csc.free_ent)++; /* code -> hashtable .............*/ HTABOF (i) = fcode; } else /* test clear code table .........*/ if (((SAP_INT)(inptr - inbuf) + csc.in_count_sum >= csc.checkpoint) && csc.block_compress) { rc = ClearBlock (csc.in_count_sum + (SAP_INT)(inptr - inbuf), csc.bytes_out + (SAP_INT) (csc.outptr - outbuf)); if (rc) { if (csc.put_n_bytes) /* no more space in outbuf .......*/ { csc.sflush = 1; rc = CS_END_OUTBUFFER; goto ende; } if ((rc = PutCode ((CODE_INT) CLEAR)) < 0) goto ende; } } if (csc.put_n_bytes) /* not enough space in outbuffer .*/ { rc = CS_END_OUTBUFFER; goto ende; } } /* end while ....................................................*/ rc = CS_END_INBUFFER; /* end of stream ....*/ if (csc.in_count_sum + (SAP_INT)(inptr - inbuf) >= csc.org_len) { if (csc.sflush < 3) { if ((rc = PutCode ((CODE_INT) csc.ent)) < 0) goto ende; if (csc.put_n_bytes) /* not enough space in outbuffer ...*/ { csc.sflush = 3; rc = CS_END_OUTBUFFER; goto ende; } } if (csc.sflush != 4) { if ((rc = PutCode ((CODE_INT) -1)) < 0) goto ende; if (csc.put_n_bytes) /* not enough space in outbuffer ...*/ { csc.sflush = 4; rc = CS_END_OUTBUFFER; goto ende; } } else if ((rc = PutCode ((CODE_INT) -1)) < 0) goto ende; rc = CS_END_OF_STREAM; /* end of data reached ..............*/ } ende: /* set output parameters and save */ *bytes_written = (SAP_INT) (csc.outptr - outbuf); *bytes_read = (SAP_INT) (inptr - inbuf); csc.in_count_sum += *bytes_read; /* the sum of input length .......*/ csc.bytes_out += *bytes_written; /* the sum of output length ......*/ return rc; }