fix #46 Using ZSTD context to improve performance

This commit is contained in:
yuanyuanxiang
2025-02-07 18:59:15 +08:00
parent 2b9ef8e935
commit 1fce74e06e
8 changed files with 67 additions and 7 deletions

View File

@@ -288,14 +288,18 @@ extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpsz
return;
}
do
{
do {
TestRun((char*)result[0].c_str(), atoi(result[1].c_str()));
while (!IsStoped())
Sleep(20);
} while (!IsExit());
if (IsExit() == 1)
return;
if (g_bExit == 1)
return;
else if (g_bExit == 2)
continue;
else // 3
break;
} while (true);
sprintf_s(message, "%s:%d", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
RunNewDll(message);
}

View File

@@ -26,10 +26,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
#include <assert.h>
#include "Manager.h"
@@ -63,6 +69,11 @@ IOCPClient::IOCPClient(bool exit_while_disconnect)
InitializeCriticalSection(&m_cs);
m_exit_while_disconnect = exit_while_disconnect;
#if USING_CTX
m_Cctx = ZSTD_createCCtx();
m_Dctx = ZSTD_createDCtx();
ZSTD_CCtx_setParameter(m_Cctx, ZSTD_c_compressionLevel, ZSTD_CLEVEL);
#endif
}
IOCPClient::~IOCPClient()
@@ -89,6 +100,10 @@ IOCPClient::~IOCPClient()
DeleteCriticalSection(&m_cs);
m_bWorkThread = S_END;
#if USING_CTX
ZSTD_freeCCtx(m_Cctx);
ZSTD_freeDCtx(m_Dctx);
#endif
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡIP<49><50>ַ

View File

@@ -15,6 +15,10 @@
#include "Buffer.h"
#include "Manager.h"
#if USING_CTX
#include "zstd/zstd.h"
#endif
#pragma comment(lib,"ws2_32.lib")
#define MAX_RECV_BUFFER 1024*32
@@ -33,7 +37,10 @@ public:
CBuffer m_CompressedBuffer;
BOOL m_bWorkThread;
HANDLE m_hWorkThread;
#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
BOOL ConnectServer(const char* szServerIP, unsigned short uPort);
static DWORD WINAPI WorkThreadProc(LPVOID lParam);

View File

@@ -15,6 +15,12 @@
#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
#if _MSC_VER > 1000