fix #46 Using ZSTD context to improve performance
This commit is contained in:
@@ -25,10 +25,16 @@
|
||||
#endif
|
||||
#define Z_FAILED(p) ZSTD_isError(p)
|
||||
#define Z_SUCCESS(p) (!Z_FAILED(p))
|
||||
#define ZSTD_CLEVEL 5
|
||||
#if USING_CTX
|
||||
#define compress(dest, destLen, source, sourceLen) ZSTD_compress2(m_Cctx, dest, *(destLen), source, sourceLen)
|
||||
#define uncompress(dest, destLen, source, sourceLen) ZSTD_decompressDCtx(m_Dctx, dest, *(destLen), source, sourceLen)
|
||||
#else
|
||||
#define compress(dest, destLen, source, sourceLen) ZSTD_compress(dest, *(destLen), source, sourceLen, ZSTD_CLEVEL_DEFAULT)
|
||||
#define uncompress(dest, destLen, source, sourceLen) ZSTD_decompress(dest, *(destLen), source, sourceLen)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
CRITICAL_SECTION IOCPServer::m_cs = {0};
|
||||
@@ -79,6 +85,11 @@ IOCPServer::IOCPServer(void)
|
||||
|
||||
m_NotifyProc = NULL;
|
||||
m_OfflineProc = NULL;
|
||||
#if USING_CTX
|
||||
m_Cctx = ZSTD_createCCtx();
|
||||
m_Dctx = ZSTD_createDCtx();
|
||||
ZSTD_CCtx_setParameter(m_Cctx, ZSTD_c_compressionLevel, ZSTD_CLEVEL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +154,11 @@ IOCPServer::~IOCPServer(void)
|
||||
m_ulBusyThread = 0;
|
||||
m_ulKeepLiveTime = 0;
|
||||
|
||||
#if USING_CTX
|
||||
ZSTD_freeCCtx(m_Cctx);
|
||||
ZSTD_freeDCtx(m_Dctx);
|
||||
#endif
|
||||
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#pragma comment(lib,"ws2_32.lib")
|
||||
#include "CpuUseage.h"
|
||||
#include "Buffer.h"
|
||||
#if USING_CTX
|
||||
#include "zstd/zstd.h"
|
||||
#endif
|
||||
|
||||
#include <Mstcpip.h>
|
||||
#define PACKET_LENGTH 0x2000
|
||||
@@ -78,6 +81,11 @@ public:
|
||||
ULONG m_ulCurrentThread;
|
||||
ULONG m_ulBusyThread;
|
||||
|
||||
#if USING_CTX
|
||||
ZSTD_CCtx* m_Cctx; // ѹ<><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ZSTD_DCtx* m_Dctx; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#endif
|
||||
|
||||
CCpuUsage m_cpu;
|
||||
|
||||
ULONG m_ulKeepLiveTime;
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
#if !USING_ZLIB
|
||||
// <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>LZ4
|
||||
#define USING_LZ4 0
|
||||
#if !USING_LZ4
|
||||
#define USING_ZSTD 1
|
||||
#define USING_CTX 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _SECURE_ATL
|
||||
|
||||
Reference in New Issue
Block a user