fix #46 Using ZSTD context to improve performance
This commit is contained in:
@@ -288,14 +288,18 @@ extern "C" __declspec(dllexport) void Run(HWND hwnd, HINSTANCE hinst, LPSTR lpsz
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
TestRun((char*)result[0].c_str(), atoi(result[1].c_str()));
|
TestRun((char*)result[0].c_str(), atoi(result[1].c_str()));
|
||||||
while (!IsStoped())
|
while (!IsStoped())
|
||||||
Sleep(20);
|
Sleep(20);
|
||||||
} while (!IsExit());
|
if (g_bExit == 1)
|
||||||
if (IsExit() == 1)
|
|
||||||
return;
|
return;
|
||||||
|
else if (g_bExit == 2)
|
||||||
|
continue;
|
||||||
|
else // 3
|
||||||
|
break;
|
||||||
|
} while (true);
|
||||||
|
|
||||||
sprintf_s(message, "%s:%d", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
|
sprintf_s(message, "%s:%d", g_SETTINGS.ServerIP(), g_SETTINGS.ServerPort());
|
||||||
RunNewDll(message);
|
RunNewDll(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,16 @@
|
|||||||
#endif
|
#endif
|
||||||
#define Z_FAILED(p) ZSTD_isError(p)
|
#define Z_FAILED(p) ZSTD_isError(p)
|
||||||
#define Z_SUCCESS(p) (!Z_FAILED(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 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)
|
#define uncompress(dest, destLen, source, sourceLen) ZSTD_decompress(dest, *(destLen), source, sourceLen)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
|
|
||||||
@@ -63,6 +69,11 @@ IOCPClient::IOCPClient(bool exit_while_disconnect)
|
|||||||
|
|
||||||
InitializeCriticalSection(&m_cs);
|
InitializeCriticalSection(&m_cs);
|
||||||
m_exit_while_disconnect = exit_while_disconnect;
|
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()
|
IOCPClient::~IOCPClient()
|
||||||
@@ -89,6 +100,10 @@ IOCPClient::~IOCPClient()
|
|||||||
DeleteCriticalSection(&m_cs);
|
DeleteCriticalSection(&m_cs);
|
||||||
|
|
||||||
m_bWorkThread = S_END;
|
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>ַ
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡIP<49><50>ַ
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
|
|
||||||
|
#if USING_CTX
|
||||||
|
#include "zstd/zstd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma comment(lib,"ws2_32.lib")
|
#pragma comment(lib,"ws2_32.lib")
|
||||||
|
|
||||||
#define MAX_RECV_BUFFER 1024*32
|
#define MAX_RECV_BUFFER 1024*32
|
||||||
@@ -33,7 +37,10 @@ public:
|
|||||||
CBuffer m_CompressedBuffer;
|
CBuffer m_CompressedBuffer;
|
||||||
BOOL m_bWorkThread;
|
BOOL m_bWorkThread;
|
||||||
HANDLE m_hWorkThread;
|
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);
|
BOOL ConnectServer(const char* szServerIP, unsigned short uPort);
|
||||||
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,12 @@
|
|||||||
#if !USING_ZLIB
|
#if !USING_ZLIB
|
||||||
// <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>LZ4
|
// <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>LZ4
|
||||||
#define USING_LZ4 0
|
#define USING_LZ4 0
|
||||||
|
|
||||||
|
#if !USING_LZ4
|
||||||
|
#define USING_ZSTD 1
|
||||||
|
#define USING_CTX 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _MSC_VER > 1000
|
#if _MSC_VER > 1000
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#define FLAG_GHOST 0x7654321
|
#define FLAG_GHOST 0x7654321
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>仯ʱ<E4BBAF><CAB1>Ӧ<EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Ա<EFBFBD><D4B1>Ա<EFBFBD><D4B1>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>仯ʱ<E4BBAF><CAB1>Ӧ<EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Ա<EFBFBD><D4B1>Ա<EFBFBD><D4B1>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
#define DLL_VERSION "20241229" // DLL<4C>汾
|
#define DLL_VERSION __DATE__ // DLL<4C>汾
|
||||||
|
|
||||||
#define TALK_DLG_MAXLEN 1024 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
#define TALK_DLG_MAXLEN 1024 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,16 @@
|
|||||||
#endif
|
#endif
|
||||||
#define Z_FAILED(p) ZSTD_isError(p)
|
#define Z_FAILED(p) ZSTD_isError(p)
|
||||||
#define Z_SUCCESS(p) (!Z_FAILED(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 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)
|
#define uncompress(dest, destLen, source, sourceLen) ZSTD_decompress(dest, *(destLen), source, sourceLen)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
CRITICAL_SECTION IOCPServer::m_cs = {0};
|
CRITICAL_SECTION IOCPServer::m_cs = {0};
|
||||||
@@ -79,6 +85,11 @@ IOCPServer::IOCPServer(void)
|
|||||||
|
|
||||||
m_NotifyProc = NULL;
|
m_NotifyProc = NULL;
|
||||||
m_OfflineProc = 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_ulBusyThread = 0;
|
||||||
m_ulKeepLiveTime = 0;
|
m_ulKeepLiveTime = 0;
|
||||||
|
|
||||||
|
#if USING_CTX
|
||||||
|
ZSTD_freeCCtx(m_Cctx);
|
||||||
|
ZSTD_freeDCtx(m_Dctx);
|
||||||
|
#endif
|
||||||
|
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#pragma comment(lib,"ws2_32.lib")
|
#pragma comment(lib,"ws2_32.lib")
|
||||||
#include "CpuUseage.h"
|
#include "CpuUseage.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#if USING_CTX
|
||||||
|
#include "zstd/zstd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Mstcpip.h>
|
#include <Mstcpip.h>
|
||||||
#define PACKET_LENGTH 0x2000
|
#define PACKET_LENGTH 0x2000
|
||||||
@@ -78,6 +81,11 @@ public:
|
|||||||
ULONG m_ulCurrentThread;
|
ULONG m_ulCurrentThread;
|
||||||
ULONG m_ulBusyThread;
|
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;
|
CCpuUsage m_cpu;
|
||||||
|
|
||||||
ULONG m_ulKeepLiveTime;
|
ULONG m_ulKeepLiveTime;
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
#if !USING_ZLIB
|
#if !USING_ZLIB
|
||||||
// <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>LZ4
|
// <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>LZ4
|
||||||
#define USING_LZ4 0
|
#define USING_LZ4 0
|
||||||
|
#if !USING_LZ4
|
||||||
|
#define USING_ZSTD 1
|
||||||
|
#define USING_CTX 1
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _SECURE_ATL
|
#ifndef _SECURE_ATL
|
||||||
|
|||||||
Reference in New Issue
Block a user