mirror of
https://gitee.com/ldcsaa/HP-Socket.git
synced 2024-12-01 19:27:46 +08:00
20220116
This commit is contained in:
parent
0bc6270227
commit
47fa15bd7a
@ -29,7 +29,7 @@
|
||||
#define HP_VERSION_MAJOR 5 // 主版本号
|
||||
#define HP_VERSION_MINOR 8 // 子版本号
|
||||
#define HP_VERSION_REVISE 6 // 修正版本号
|
||||
#define HP_VERSION_BUILD 2 // 构建编号
|
||||
#define HP_VERSION_BUILD 3 // 构建编号
|
||||
|
||||
//#define _UDP_DISABLED // 禁用 UDP
|
||||
//#define _SSL_DISABLED // 禁用 SSL
|
||||
|
@ -5,7 +5,7 @@
|
||||
<VER_MAJOR>5</VER_MAJOR>
|
||||
<VER_MINOR>8</VER_MINOR>
|
||||
<VER_REVISE>6</VER_REVISE>
|
||||
<VER_BUILD>2</VER_BUILD>
|
||||
<VER_BUILD>3</VER_BUILD>
|
||||
<ArmDeptToCopyRemotely>..\..\dependent\arm\include\brotli\decode.h:=$(RemoteRootDir)/dependent/arm/include/brotli/decode.h;..\..\dependent\arm\include\brotli\encode.h:=$(RemoteRootDir)/dependent/arm/include/brotli/encode.h;..\..\dependent\arm\include\brotli\port.h:=$(RemoteRootDir)/dependent/arm/include/brotli/port.h;..\..\dependent\arm\include\brotli\types.h:=$(RemoteRootDir)/dependent/arm/include/brotli/types.h;..\..\dependent\arm\lib\libbrotli.a:=$(RemoteRootDir)/dependent/arm/lib/libbrotli.a;..\..\dependent\arm\lib\libjemalloc_pic.a:=$(RemoteRootDir)/dependent/arm/lib/libjemalloc_pic.a;..\..\dependent\arm\lib\libmimalloc.a:=$(RemoteRootDir)/dependent/arm/lib/libmimalloc.a</ArmDeptToCopyRemotely>
|
||||
<Arm64DeptToCopyRemotely>..\..\dependent\arm64\include\brotli\decode.h:=$(RemoteRootDir)/dependent/arm64/include/brotli/decode.h;..\..\dependent\arm64\include\brotli\encode.h:=$(RemoteRootDir)/dependent/arm64/include/brotli/encode.h;..\..\dependent\arm64\include\brotli\port.h:=$(RemoteRootDir)/dependent/arm64/include/brotli/port.h;..\..\dependent\arm64\include\brotli\types.h:=$(RemoteRootDir)/dependent/arm64/include/brotli/types.h;..\..\dependent\arm64\lib\libbrotli.a:=$(RemoteRootDir)/dependent/arm64/lib/libbrotli.a;..\..\dependent\arm64\lib\libjemalloc_pic.a:=$(RemoteRootDir)/dependent/arm64/lib/libjemalloc_pic.a;..\..\dependent\arm64\lib\libmimalloc.a:=$(RemoteRootDir)/dependent/arm64/lib/libmimalloc.a</Arm64DeptToCopyRemotely>
|
||||
<ArmScriptToCopyRemotely>..\..\script\clean.sh:=$(RemoteRootDir)/script/clean.sh;..\..\script\cp-dependent.sh:=$(RemoteRootDir)/script/cp-dependent.sh;..\..\script\cp-include.sh:=$(RemoteRootDir)/script/cp-include.sh;..\..\script\env.sh:=$(RemoteRootDir)/script/env.sh;..\..\script\post-link.sh:=$(RemoteRootDir)/script/post-link.sh;..\..\script\pre-link.sh:=$(RemoteRootDir)/script/pre-link.sh;..\..\compile.sh:=$(RemoteRootDir)/compile.sh;..\..\install.sh:=$(RemoteRootDir)/install.sh</ArmScriptToCopyRemotely>
|
||||
|
@ -2333,7 +2333,7 @@ HPSOCKET_API int __HP_CALL SYS_BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLe
|
||||
|
||||
HPSOCKET_API int __HP_CALL SYS_BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD* pdwDestLen, int iQuality, int iWindow, int iMode)
|
||||
{
|
||||
return ::BrotliCompressEx(lpszSrc, dwSrcLen, lpszDest, *pdwDestLen, iQuality, iWindow , (BrotliEncoderMode)iMode);
|
||||
return ::BrotliCompressEx(lpszSrc, dwSrcLen, lpszDest, *pdwDestLen, iQuality, iWindow , iMode);
|
||||
}
|
||||
|
||||
HPSOCKET_API int __HP_CALL SYS_BrotliUncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD* pdwDestLen)
|
||||
|
@ -1059,7 +1059,7 @@ DWORD GuessCompressBound(DWORD dwSrcLen, BOOL bGZip)
|
||||
{
|
||||
DWORD dwBound = (DWORD)::compressBound(dwSrcLen);
|
||||
|
||||
if(bGZip) dwBound += 11;
|
||||
if(bGZip) dwBound += 16;
|
||||
|
||||
return dwBound;
|
||||
}
|
||||
@ -1091,10 +1091,10 @@ int BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& d
|
||||
return BrotliCompressEx(lpszSrc, dwSrcLen, lpszDest, dwDestLen, BROTLI_DEFAULT_QUALITY, BROTLI_DEFAULT_WINDOW, BROTLI_DEFAULT_MODE);
|
||||
}
|
||||
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality, int iWindow, BrotliEncoderMode enMode)
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality, int iWindow, int iMode)
|
||||
{
|
||||
size_t stDestLen = (size_t)dwDestLen;
|
||||
int rs = ::BrotliEncoderCompress(iQuality, iWindow, enMode, (size_t)dwSrcLen, lpszSrc, &stDestLen, lpszDest);
|
||||
int rs = ::BrotliEncoderCompress(iQuality, iWindow, (BrotliEncoderMode)iMode, (size_t)dwSrcLen, lpszSrc, &stDestLen, lpszDest);
|
||||
dwDestLen = (DWORD)stDestLen;
|
||||
|
||||
return (rs == 1) ? 0 : ((rs == 3) ? -5 : -3);
|
||||
|
@ -312,7 +312,6 @@ struct TSocketObjBase : public CSafeCounter
|
||||
PVOID extra;
|
||||
PVOID reserved;
|
||||
PVOID reserved2;
|
||||
BOOL valid;
|
||||
DWORD activeTime;
|
||||
|
||||
union
|
||||
@ -321,6 +320,7 @@ struct TSocketObjBase : public CSafeCounter
|
||||
DWORD connTime;
|
||||
};
|
||||
|
||||
volatile BOOL valid;
|
||||
volatile BOOL connected;
|
||||
volatile BOOL paused;
|
||||
|
||||
@ -825,7 +825,7 @@ DWORD GZipGuessUncompressBound(const BYTE* lpszSrc, DWORD dwSrcLen);
|
||||
// Brotli 压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Brotli 高级压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality = BROTLI_DEFAULT_QUALITY, int iWindow = BROTLI_DEFAULT_WINDOW, BrotliEncoderMode enMode = BROTLI_DEFAULT_MODE);
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality = BROTLI_DEFAULT_QUALITY, int iWindow = BROTLI_DEFAULT_WINDOW, int iMode = BROTLI_DEFAULT_MODE);
|
||||
// Brotli 解压(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int BrotliUncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Brotli 推测压缩结果长度
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define HP_VERSION_MAJOR 5 // 主版本号
|
||||
#define HP_VERSION_MINOR 8 // 子版本号
|
||||
#define HP_VERSION_REVISE 6 // 修正版本号
|
||||
#define HP_VERSION_BUILD 2 // 构建编号
|
||||
#define HP_VERSION_BUILD 3 // 构建编号
|
||||
|
||||
//#define _UDP_DISABLED // 禁用 UDP
|
||||
//#define _SSL_DISABLED // 禁用 SSL
|
||||
@ -531,3 +531,23 @@ THeader, HP_THeader, *LPHEADER, *HP_LPHEADER,
|
||||
TCookie, HP_TCookie, *LPCOOKIE, *HP_LPCOOKIE;
|
||||
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
名称:数据回调函数
|
||||
描述:回调处理过程中产生的数据输出
|
||||
参数:
|
||||
pData -- 数据缓冲区
|
||||
iLength -- 数据长度
|
||||
pContext -- 回调上下文
|
||||
|
||||
返回值:
|
||||
TRUE -- 成功
|
||||
FALSE -- 失败
|
||||
|
||||
************************************************************************/
|
||||
typedef BOOL (__HP_CALL *Fn_DataCallback)(const BYTE* pData, int iLength, PVOID pContext);
|
||||
typedef Fn_DataCallback Fn_CompressDataCallback;
|
||||
typedef Fn_DataCallback Fn_DecompressDataCallback;
|
||||
typedef Fn_DataCallback HP_Fn_DataCallback;
|
||||
typedef Fn_DataCallback HP_Fn_CompressDataCallback;
|
||||
typedef Fn_DataCallback HP_Fn_DecompressDataCallback;
|
||||
|
@ -3013,3 +3013,79 @@ public:
|
||||
virtual void OnWorkerThreadStart(IHPThreadPool* pThreadPool, THR_ID dwThreadID) {}
|
||||
virtual void OnWorkerThreadEnd(IHPThreadPool* pThreadPool, THR_ID dwThreadID) {}
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
名称:压缩器接口
|
||||
描述:定义压缩器的所有操作方法和属性访问方法
|
||||
************************************************************************/
|
||||
class IHPCompressor
|
||||
{
|
||||
public:
|
||||
|
||||
/***********************************************************************/
|
||||
/***************************** 组件操作方法 *****************************/
|
||||
|
||||
/*
|
||||
* 名称:执行压缩
|
||||
* 描述:可循环调用以压缩流式或分段数据
|
||||
*
|
||||
* 参数: pData -- 待压缩数据缓冲区
|
||||
* iLength -- 待压缩数据长度
|
||||
* pContext -- 压缩回调函数 Fn_CompressDataCallback 的上下文参数
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取错误代码
|
||||
*/
|
||||
virtual BOOL Process(const BYTE* pData, int iLength, BOOL bLast, PVOID pContext = nullptr) = 0;
|
||||
|
||||
/* 重置压缩器 */
|
||||
virtual BOOL Reset() = 0;
|
||||
|
||||
/***********************************************************************/
|
||||
/***************************** 属性访问方法 *****************************/
|
||||
|
||||
/* 检测压缩器是否可用 */
|
||||
virtual BOOL IsValid() = 0;
|
||||
|
||||
public:
|
||||
virtual ~IHPCompressor() {};
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
名称:解压器接口
|
||||
描述:定义解压器的所有操作方法和属性访问方法
|
||||
************************************************************************/
|
||||
class IHPDecompressor
|
||||
{
|
||||
public:
|
||||
|
||||
/***********************************************************************/
|
||||
/***************************** 组件操作方法 *****************************/
|
||||
|
||||
/*
|
||||
* 名称:执行解压
|
||||
* 描述:可循环调用以解压流式或分段数据
|
||||
*
|
||||
* 参数: pData -- 待解压数据缓冲区
|
||||
* iLength -- 待解压数据长度
|
||||
* pContext -- 解压回调函数 Fn_DecompressDataCallback 的上下文参数
|
||||
*
|
||||
* 返回值: TRUE -- 成功
|
||||
* FALSE -- 失败,可通过 SYS_GetLastError() 获取错误代码
|
||||
*/
|
||||
virtual BOOL Process(const BYTE* pData, int iLength, PVOID pContext = nullptr) = 0;
|
||||
|
||||
/* 重置解压器 */
|
||||
virtual BOOL Reset() = 0;
|
||||
|
||||
public:
|
||||
|
||||
/***********************************************************************/
|
||||
/***************************** 属性访问方法 *****************************/
|
||||
|
||||
/* 检测解压器是否可用 */
|
||||
virtual BOOL IsValid() = 0;
|
||||
|
||||
public:
|
||||
virtual ~IHPDecompressor() {};
|
||||
};
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3053,7 +3053,7 @@ HPSOCKET_API int __HP_CALL SYS_BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLe
|
||||
|
||||
HPSOCKET_API int __HP_CALL SYS_BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD* pdwDestLen, int iQuality, int iWindow, int iMode)
|
||||
{
|
||||
return ::BrotliCompressEx(lpszSrc, dwSrcLen, lpszDest, *pdwDestLen, iQuality, iWindow , (BrotliEncoderMode)iMode);
|
||||
return ::BrotliCompressEx(lpszSrc, dwSrcLen, lpszDest, *pdwDestLen, iQuality, iWindow , iMode);
|
||||
}
|
||||
|
||||
HPSOCKET_API int __HP_CALL SYS_BrotliUncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD* pdwDestLen)
|
||||
|
@ -102,6 +102,9 @@
|
||||
/* TCP Pack 관庫칵훰깃街令 */
|
||||
#define TCP_PACK_DEFAULT_HEADER_FLAG 0x000000
|
||||
|
||||
/* 压缩/解压数据缓冲器长度 */
|
||||
#define COMPRESS_BUFFER_SIZE (16 * 1024)
|
||||
|
||||
#define PORT_SEPARATOR_CHAR ':'
|
||||
#define IPV6_ADDR_BEGIN_CHAR '['
|
||||
#define IPV6_ADDR_END_CHAR ']'
|
||||
|
@ -1515,8 +1515,193 @@ ERROR_DEST_LEN:
|
||||
return -5;
|
||||
}
|
||||
|
||||
void DestroyCompressor(IHPCompressor* pCompressor)
|
||||
{
|
||||
delete pCompressor;
|
||||
}
|
||||
|
||||
void DestroyDecompressor(IHPDecompressor* pDecompressor)
|
||||
{
|
||||
delete pDecompressor;
|
||||
}
|
||||
|
||||
#ifdef _ZLIB_SUPPORT
|
||||
|
||||
CHPZlibCompressor::CHPZlibCompressor(Fn_CompressDataCallback fnCallback, int iWindowBits, int iLevel, int iMethod, int iMemLevel, int iStrategy)
|
||||
: m_fnCallback (fnCallback)
|
||||
, m_bValid (FALSE)
|
||||
{
|
||||
ASSERT(m_fnCallback != nullptr);
|
||||
|
||||
m_bValid = (::deflateInit2(&m_Stream, iLevel, iMethod, iWindowBits, iMemLevel, iStrategy) == Z_OK);
|
||||
}
|
||||
CHPZlibCompressor::~CHPZlibCompressor()
|
||||
{
|
||||
if(m_bValid) ::deflateEnd(&m_Stream);
|
||||
}
|
||||
|
||||
BOOL CHPZlibCompressor::Reset()
|
||||
{
|
||||
return (m_bValid = (::deflateReset(&m_Stream) == Z_OK));
|
||||
}
|
||||
|
||||
BOOL CHPZlibCompressor::Process(const BYTE* pData, int iLength, BOOL bLast, PVOID pContext)
|
||||
{
|
||||
ASSERT(IsValid() && iLength > 0);
|
||||
|
||||
if(!IsValid())
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_STATE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BYTE szBuff[COMPRESS_BUFFER_SIZE];
|
||||
|
||||
m_Stream.next_in = (z_const Bytef*)pData;
|
||||
m_Stream.avail_in = iLength;
|
||||
int rs = Z_OK;
|
||||
BOOL isOK = TRUE;
|
||||
|
||||
while(m_Stream.avail_in > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
m_Stream.next_out = szBuff;
|
||||
m_Stream.avail_out = COMPRESS_BUFFER_SIZE;
|
||||
|
||||
rs = ::deflate(&m_Stream, bLast ? Z_FINISH : Z_NO_FLUSH);
|
||||
|
||||
if(rs == Z_STREAM_ERROR)
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_DATA);
|
||||
isOK = FALSE;
|
||||
|
||||
goto ZLIB_COMPRESS_END;
|
||||
}
|
||||
|
||||
int iRead = (int)(COMPRESS_BUFFER_SIZE - m_Stream.avail_out);
|
||||
|
||||
if(iRead == 0)
|
||||
break;
|
||||
|
||||
if(!m_fnCallback(szBuff, iRead, pContext))
|
||||
{
|
||||
::SetLastError(ERROR_CANCELLED);
|
||||
isOK = FALSE;
|
||||
|
||||
goto ZLIB_COMPRESS_END;
|
||||
}
|
||||
} while(m_Stream.avail_out == 0);
|
||||
}
|
||||
|
||||
ZLIB_COMPRESS_END:
|
||||
|
||||
ASSERT(!isOK || (rs == Z_OK && !bLast) || (rs == Z_STREAM_END && bLast));
|
||||
|
||||
if(!isOK || bLast) Reset();
|
||||
|
||||
return isOK;
|
||||
}
|
||||
|
||||
CHPZlibDecompressor::CHPZlibDecompressor(Fn_DecompressDataCallback fnCallback, int iWindowBits)
|
||||
: m_fnCallback (fnCallback)
|
||||
, m_bValid (FALSE)
|
||||
{
|
||||
ASSERT(m_fnCallback != nullptr);
|
||||
|
||||
m_bValid = (::inflateInit2(&m_Stream, iWindowBits) == Z_OK);
|
||||
}
|
||||
CHPZlibDecompressor::~CHPZlibDecompressor()
|
||||
{
|
||||
if(m_bValid) ::inflateEnd(&m_Stream);
|
||||
}
|
||||
|
||||
BOOL CHPZlibDecompressor::Reset()
|
||||
{
|
||||
return (m_bValid = (::inflateReset(&m_Stream) == Z_OK));
|
||||
}
|
||||
|
||||
BOOL CHPZlibDecompressor::Process(const BYTE* pData, int iLength, PVOID pContext)
|
||||
{
|
||||
ASSERT(IsValid() && iLength > 0);
|
||||
|
||||
if(!IsValid())
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_STATE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BYTE szBuff[COMPRESS_BUFFER_SIZE];
|
||||
|
||||
m_Stream.next_in = (z_const Bytef*)pData;
|
||||
m_Stream.avail_in = iLength;
|
||||
int rs = Z_OK;
|
||||
BOOL isOK = TRUE;
|
||||
|
||||
while(m_Stream.avail_in > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
m_Stream.next_out = szBuff;
|
||||
m_Stream.avail_out = COMPRESS_BUFFER_SIZE;
|
||||
|
||||
rs = ::inflate(&m_Stream, Z_NO_FLUSH);
|
||||
|
||||
if(rs != Z_OK && rs != Z_STREAM_END)
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_DATA);
|
||||
isOK = FALSE;
|
||||
|
||||
goto ZLIB_DECOMPRESS_END;
|
||||
}
|
||||
|
||||
int iRead = (int)(COMPRESS_BUFFER_SIZE - m_Stream.avail_out);
|
||||
|
||||
if(iRead == 0)
|
||||
break;
|
||||
|
||||
if(!m_fnCallback(szBuff, iRead, pContext))
|
||||
{
|
||||
::SetLastError(ERROR_CANCELLED);
|
||||
isOK = FALSE;
|
||||
|
||||
goto ZLIB_DECOMPRESS_END;
|
||||
}
|
||||
} while(m_Stream.avail_out == 0);
|
||||
|
||||
if(rs == Z_STREAM_END)
|
||||
break;
|
||||
}
|
||||
|
||||
ZLIB_DECOMPRESS_END:
|
||||
|
||||
ASSERT(!isOK || rs == Z_OK || rs == Z_STREAM_END);
|
||||
|
||||
if(!isOK || rs == Z_STREAM_END) Reset();
|
||||
|
||||
return isOK;
|
||||
}
|
||||
|
||||
IHPCompressor* CreateZLibCompressor(Fn_CompressDataCallback fnCallback, int iWindowBits, int iLevel, int iMethod, int iMemLevel, int iStrategy)
|
||||
{
|
||||
return new CHPZlibCompressor(fnCallback, iWindowBits, iLevel, iMethod, iMemLevel, iStrategy);
|
||||
}
|
||||
|
||||
IHPCompressor* CreateGZipCompressor(Fn_CompressDataCallback fnCallback, int iLevel, int iMethod, int iMemLevel, int iStrategy)
|
||||
{
|
||||
return new CHPZlibCompressor(fnCallback, MAX_WBITS + 16, iLevel, iMethod, iMemLevel, iStrategy);
|
||||
}
|
||||
|
||||
IHPDecompressor* CreateZLibDecompressor(Fn_DecompressDataCallback fnCallback, int iWindowBits)
|
||||
{
|
||||
return new CHPZlibDecompressor(fnCallback, iWindowBits);
|
||||
}
|
||||
|
||||
IHPDecompressor* CreateGZipDecompressor(Fn_DecompressDataCallback fnCallback)
|
||||
{
|
||||
return new CHPZlibDecompressor(fnCallback, MAX_WBITS + 32);
|
||||
}
|
||||
|
||||
int Compress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen)
|
||||
{
|
||||
return CompressEx(lpszSrc, dwSrcLen, lpszDest, dwDestLen);
|
||||
@ -1565,7 +1750,7 @@ int UncompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwD
|
||||
z_stream stream;
|
||||
|
||||
stream.next_in = (z_const Bytef*)lpszSrc;
|
||||
stream.avail_in = (uInt)dwSrcLen;
|
||||
stream.avail_in = dwSrcLen;
|
||||
stream.next_out = lpszDest;
|
||||
stream.avail_out = dwDestLen;
|
||||
stream.zalloc = nullptr;
|
||||
@ -1596,7 +1781,7 @@ DWORD GuessCompressBound(DWORD dwSrcLen, BOOL bGZip)
|
||||
{
|
||||
DWORD dwBound = ::compressBound(dwSrcLen);
|
||||
|
||||
if(bGZip) dwBound += 11;
|
||||
if(bGZip) dwBound += 16;
|
||||
|
||||
return dwBound;
|
||||
}
|
||||
@ -1623,15 +1808,184 @@ DWORD GZipGuessUncompressBound(const BYTE* lpszSrc, DWORD dwSrcLen)
|
||||
|
||||
#ifdef _BROTLI_SUPPORT
|
||||
|
||||
CHPBrotliCompressor::CHPBrotliCompressor(Fn_CompressDataCallback fnCallback)
|
||||
: m_fnCallback (fnCallback)
|
||||
, m_bValid (FALSE)
|
||||
{
|
||||
ASSERT(m_fnCallback != nullptr);
|
||||
|
||||
Reset();
|
||||
}
|
||||
CHPBrotliCompressor::~CHPBrotliCompressor()
|
||||
{
|
||||
if(m_bValid) ::BrotliEncoderDestroyInstance(m_pState);
|
||||
}
|
||||
|
||||
BOOL CHPBrotliCompressor::Reset()
|
||||
{
|
||||
if(m_bValid) ::BrotliEncoderDestroyInstance(m_pState);
|
||||
m_pState = ::BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);
|
||||
|
||||
return (m_bValid = (m_pState != nullptr));
|
||||
}
|
||||
|
||||
BOOL CHPBrotliCompressor::Process(const BYTE* pData, int iLength, BOOL bLast, PVOID pContext)
|
||||
{
|
||||
ASSERT(IsValid() && iLength > 0);
|
||||
|
||||
if(!IsValid())
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_STATE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BYTE szBuff[COMPRESS_BUFFER_SIZE];
|
||||
|
||||
const BYTE* pNextInData = pData;
|
||||
size_t iAvlInLen = (SIZE_T)iLength;
|
||||
BYTE* pNextOutData = nullptr;
|
||||
size_t iAvlOutLen = 0;
|
||||
BOOL isOK = TRUE;
|
||||
|
||||
while(iAvlInLen > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
pNextOutData = szBuff;
|
||||
iAvlOutLen = COMPRESS_BUFFER_SIZE;
|
||||
|
||||
if(!::BrotliEncoderCompressStream(m_pState, bLast ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS, &iAvlInLen, &pNextInData, &iAvlOutLen, &pNextOutData, nullptr))
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_DATA);
|
||||
isOK = FALSE;
|
||||
|
||||
goto BROTLI_COMPRESS_END;
|
||||
}
|
||||
|
||||
int iRead = (int)(COMPRESS_BUFFER_SIZE - iAvlOutLen);
|
||||
|
||||
if(iRead == 0)
|
||||
break;
|
||||
|
||||
if(!m_fnCallback(szBuff, iRead, pContext))
|
||||
{
|
||||
::SetLastError(ERROR_CANCELLED);
|
||||
isOK = FALSE;
|
||||
|
||||
goto BROTLI_COMPRESS_END;
|
||||
}
|
||||
} while (iAvlOutLen == 0);
|
||||
}
|
||||
|
||||
BROTLI_COMPRESS_END:
|
||||
|
||||
if(!isOK || bLast) Reset();
|
||||
|
||||
return isOK;
|
||||
}
|
||||
|
||||
CHPBrotliDecompressor::CHPBrotliDecompressor(Fn_DecompressDataCallback fnCallback)
|
||||
: m_fnCallback (fnCallback)
|
||||
, m_bValid (FALSE)
|
||||
{
|
||||
ASSERT(m_fnCallback != nullptr);
|
||||
|
||||
Reset();
|
||||
}
|
||||
CHPBrotliDecompressor::~CHPBrotliDecompressor()
|
||||
{
|
||||
if(m_bValid) ::BrotliDecoderDestroyInstance(m_pState);
|
||||
}
|
||||
|
||||
BOOL CHPBrotliDecompressor::Reset()
|
||||
{
|
||||
if(m_bValid) ::BrotliDecoderDestroyInstance(m_pState);
|
||||
m_pState = ::BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
|
||||
|
||||
return (m_bValid = (m_pState != nullptr));
|
||||
}
|
||||
|
||||
BOOL CHPBrotliDecompressor::Process(const BYTE* pData, int iLength, PVOID pContext)
|
||||
{
|
||||
ASSERT(IsValid() && iLength > 0);
|
||||
|
||||
if(!IsValid())
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_STATE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BYTE szBuff[COMPRESS_BUFFER_SIZE];
|
||||
|
||||
const BYTE* pNextInData = pData;
|
||||
size_t iAvlInLen = (SIZE_T)iLength;
|
||||
BYTE* pNextOutData = nullptr;
|
||||
size_t iAvlOutLen = 0;
|
||||
BOOL isOK = TRUE;
|
||||
BrotliDecoderResult rs = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT;
|
||||
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
pNextOutData = szBuff;
|
||||
iAvlOutLen = COMPRESS_BUFFER_SIZE;
|
||||
|
||||
rs = ::BrotliDecoderDecompressStream(m_pState, &iAvlInLen, &pNextInData, &iAvlOutLen, &pNextOutData, nullptr);
|
||||
|
||||
if(rs == BROTLI_DECODER_RESULT_ERROR)
|
||||
{
|
||||
::SetLastError(ERROR_INVALID_DATA);
|
||||
isOK = FALSE;
|
||||
|
||||
goto BROTLI_DECOMPRESS_END;
|
||||
}
|
||||
|
||||
int iRead = (int)(COMPRESS_BUFFER_SIZE - iAvlOutLen);
|
||||
|
||||
if(iRead == 0)
|
||||
break;
|
||||
|
||||
if(!m_fnCallback(szBuff, iRead, pContext))
|
||||
{
|
||||
::SetLastError(ERROR_CANCELLED);
|
||||
isOK = FALSE;
|
||||
|
||||
goto BROTLI_DECOMPRESS_END;
|
||||
}
|
||||
} while (iAvlOutLen == 0);
|
||||
|
||||
if(rs == BROTLI_DECODER_RESULT_SUCCESS)
|
||||
break;;
|
||||
|
||||
} while(rs == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT);
|
||||
|
||||
BROTLI_DECOMPRESS_END:
|
||||
|
||||
if(!isOK || rs == BROTLI_DECODER_RESULT_SUCCESS) Reset();
|
||||
|
||||
return isOK;
|
||||
}
|
||||
|
||||
IHPCompressor* CreateBrotliCompressor(Fn_CompressDataCallback fnCallback)
|
||||
{
|
||||
return new CHPBrotliCompressor(fnCallback);
|
||||
}
|
||||
|
||||
IHPDecompressor* CreateBrotliDecompressor(Fn_DecompressDataCallback fnCallback)
|
||||
{
|
||||
return new CHPBrotliDecompressor(fnCallback);
|
||||
}
|
||||
|
||||
int BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen)
|
||||
{
|
||||
return BrotliCompressEx(lpszSrc, dwSrcLen, lpszDest, dwDestLen, BROTLI_DEFAULT_QUALITY, BROTLI_DEFAULT_WINDOW, BROTLI_DEFAULT_MODE);
|
||||
}
|
||||
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality, int iWindow, BrotliEncoderMode enMode)
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality, int iWindow, int iMode)
|
||||
{
|
||||
size_t stDestLen = (size_t)dwDestLen;
|
||||
int rs = ::BrotliEncoderCompress(iQuality, iWindow, enMode, (size_t)dwSrcLen, lpszSrc, &stDestLen, lpszDest);
|
||||
int rs = ::BrotliEncoderCompress(iQuality, iWindow, (BrotliEncoderMode)iMode, (size_t)dwSrcLen, lpszSrc, &stDestLen, lpszDest);
|
||||
dwDestLen = (DWORD)stDestLen;
|
||||
|
||||
return (rs == 1) ? 0 : ((rs == 3) ? -5 : -3);
|
||||
|
@ -413,7 +413,6 @@ struct TSocketObjBase : public CSafeCounter
|
||||
PVOID extra;
|
||||
PVOID reserved;
|
||||
PVOID reserved2;
|
||||
BOOL valid;
|
||||
|
||||
union
|
||||
{
|
||||
@ -423,6 +422,7 @@ struct TSocketObjBase : public CSafeCounter
|
||||
|
||||
DWORD activeTime;
|
||||
|
||||
volatile BOOL valid;
|
||||
volatile BOOL smooth;
|
||||
volatile long pending;
|
||||
volatile long sndCount;
|
||||
@ -952,8 +952,59 @@ int UrlEncode(BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// URL 解码(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int UrlDecode(BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
|
||||
|
||||
/* 删除压缩器 */
|
||||
void DestroyCompressor(IHPCompressor* pCompressor);
|
||||
/* 删除解压器 */
|
||||
void DestroyDecompressor(IHPDecompressor* pDecompressor);
|
||||
|
||||
#ifdef _ZLIB_SUPPORT
|
||||
|
||||
/* ZLib 压缩器 */
|
||||
class CHPZlibCompressor : public IHPCompressor
|
||||
{
|
||||
public:
|
||||
virtual BOOL Process(const BYTE* pData, int iLength, BOOL bLast, PVOID pContext = nullptr);
|
||||
virtual BOOL IsValid() {return m_bValid;}
|
||||
virtual BOOL Reset();
|
||||
|
||||
public:
|
||||
CHPZlibCompressor(Fn_CompressDataCallback fnCallback, int iWindowBits = DEF_WBITS, int iLevel = Z_DEFAULT_COMPRESSION, int iMethod = Z_DEFLATED, int iMemLevel = DEF_MEM_LEVEL, int iStrategy = Z_DEFAULT_STRATEGY);
|
||||
virtual ~CHPZlibCompressor();
|
||||
|
||||
private:
|
||||
Fn_CompressDataCallback m_fnCallback;
|
||||
z_stream m_Stream;
|
||||
BOOL m_bValid;
|
||||
};
|
||||
|
||||
/* ZLib 解压器 */
|
||||
class CHPZlibDecompressor : public IHPDecompressor
|
||||
{
|
||||
public:
|
||||
virtual BOOL Process(const BYTE* pData, int iLength, PVOID pContext = nullptr);
|
||||
virtual BOOL IsValid() {return m_bValid;}
|
||||
virtual BOOL Reset();
|
||||
|
||||
public:
|
||||
CHPZlibDecompressor(Fn_DecompressDataCallback fnCallback, int iWindowBits = DEF_WBITS);
|
||||
virtual ~CHPZlibDecompressor();
|
||||
|
||||
private:
|
||||
Fn_DecompressDataCallback m_fnCallback;
|
||||
z_stream m_Stream;
|
||||
BOOL m_bValid;
|
||||
};
|
||||
|
||||
/* 创建 ZLib 压缩器 */
|
||||
IHPCompressor* CreateZLibCompressor(Fn_CompressDataCallback fnCallback, int iWindowBits = DEF_WBITS, int iLevel = Z_DEFAULT_COMPRESSION, int iMethod = Z_DEFLATED, int iMemLevel = DEF_MEM_LEVEL, int iStrategy = Z_DEFAULT_STRATEGY);
|
||||
/* 创建 GZip 压缩器 */
|
||||
IHPCompressor* CreateGZipCompressor(Fn_CompressDataCallback fnCallback, int iLevel = Z_DEFAULT_COMPRESSION, int iMethod = Z_DEFLATED, int iMemLevel = DEF_MEM_LEVEL, int iStrategy = Z_DEFAULT_STRATEGY);
|
||||
/* 创建 ZLib 解压器 */
|
||||
IHPDecompressor* CreateZLibDecompressor(Fn_DecompressDataCallback fnCallback, int iWindowBits = DEF_WBITS);
|
||||
/* 创建 GZip 解压器 */
|
||||
IHPDecompressor* CreateGZipDecompressor(Fn_DecompressDataCallback fnCallback);
|
||||
|
||||
// 普通压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int Compress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// 高级压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
@ -976,10 +1027,51 @@ DWORD GZipGuessUncompressBound(const BYTE* lpszSrc, DWORD dwSrcLen);
|
||||
|
||||
#ifdef _BROTLI_SUPPORT
|
||||
|
||||
/* Brotli 压缩器 */
|
||||
class CHPBrotliCompressor : public IHPCompressor
|
||||
{
|
||||
public:
|
||||
virtual BOOL Process(const BYTE* pData, int iLength, BOOL bLast, PVOID pContext = nullptr);
|
||||
virtual BOOL IsValid() {return m_bValid;}
|
||||
virtual BOOL Reset();
|
||||
|
||||
public:
|
||||
CHPBrotliCompressor(Fn_CompressDataCallback fnCallback);
|
||||
virtual ~CHPBrotliCompressor();
|
||||
|
||||
private:
|
||||
Fn_CompressDataCallback m_fnCallback;
|
||||
BrotliEncoderState* m_pState;
|
||||
BOOL m_bValid;
|
||||
};
|
||||
|
||||
/* Brotli 解压器 */
|
||||
class CHPBrotliDecompressor : public IHPDecompressor
|
||||
{
|
||||
public:
|
||||
virtual BOOL Process(const BYTE* pData, int iLength, PVOID pContext = nullptr);
|
||||
virtual BOOL IsValid() {return m_bValid;}
|
||||
virtual BOOL Reset();
|
||||
|
||||
public:
|
||||
CHPBrotliDecompressor(Fn_DecompressDataCallback fnCallback);
|
||||
virtual ~CHPBrotliDecompressor();
|
||||
|
||||
private:
|
||||
Fn_DecompressDataCallback m_fnCallback;
|
||||
BrotliDecoderState* m_pState;
|
||||
BOOL m_bValid;
|
||||
};
|
||||
|
||||
/* 创建 Brotli 压缩器 */
|
||||
IHPCompressor* CreateBrotliCompressor(Fn_CompressDataCallback fnCallback);
|
||||
/* 创建 Brotli 解压器 */
|
||||
IHPDecompressor* CreateBrotliDecompressor(Fn_DecompressDataCallback fnCallback);
|
||||
|
||||
// Brotli 压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int BrotliCompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Brotli 高级压缩(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality = BROTLI_DEFAULT_QUALITY, int iWindow = BROTLI_DEFAULT_WINDOW, BrotliEncoderMode enMode = BROTLI_DEFAULT_MODE);
|
||||
int BrotliCompressEx(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen, int iQuality = BROTLI_DEFAULT_QUALITY, int iWindow = BROTLI_DEFAULT_WINDOW, int iMode = BROTLI_DEFAULT_MODE);
|
||||
// Brotli 解压(返回值:0 -> 成功,-3 -> 输入数据不正确,-5 -> 输出缓冲区不足)
|
||||
int BrotliUncompress(const BYTE* lpszSrc, DWORD dwSrcLen, BYTE* lpszDest, DWORD& dwDestLen);
|
||||
// Brotli 推测压缩结果长度
|
||||
|
@ -84,9 +84,6 @@ EnHandleResult CTcpAgent::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pB
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if(pBufferObj->ReleaseSendCounter() == 0)
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
@ -991,64 +988,61 @@ void CTcpAgent::HandleConnect(CONNID dwConnID, TSocketObj* pSocketObj, TBufferOb
|
||||
|
||||
void CTcpAgent::HandleSend(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj)
|
||||
{
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
long iLength = -(long)(pBufferObj->buff.len);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
if(TSocketObj::IsValid(pSocketObj))
|
||||
{
|
||||
case SP_PACK:
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
long iLength = -(long)(pBufferObj->buff.len);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
{
|
||||
case SP_PACK:
|
||||
::InterlockedExchangeAdd(&pSocketObj->sndCount, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
|
||||
DoSendPack(pSocketObj);
|
||||
}
|
||||
|
||||
break;
|
||||
case SP_SAFE:
|
||||
{
|
||||
break;
|
||||
case SP_SAFE:
|
||||
::InterlockedExchangeAdd(&pSocketObj->sndCount, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
|
||||
DoSendSafe(pSocketObj);
|
||||
}
|
||||
|
||||
break;
|
||||
case SP_DIRECT:
|
||||
{
|
||||
break;
|
||||
case SP_DIRECT:
|
||||
::InterlockedExchangeAdd(&pSocketObj->pending, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if(pBufferObj->ReleaseSendCounter() == 0)
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
}
|
||||
|
||||
void CTcpAgent::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj)
|
||||
{
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
EnHandleResult hr = TSocketObj::IsValid(pSocketObj) ? HR_OK : (EnHandleResult)HR_CLOSED;
|
||||
|
||||
if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();
|
||||
|
||||
EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj);
|
||||
|
||||
if(hr == HR_OK || hr == HR_IGNORE)
|
||||
if(hr == HR_OK)
|
||||
{
|
||||
if(::ContinueReceive(this, pSocketObj, pBufferObj, hr))
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();
|
||||
|
||||
hr = TriggerFireReceive(pSocketObj, pBufferObj);
|
||||
|
||||
if(hr == HR_OK || hr == HR_IGNORE)
|
||||
{
|
||||
if(::ContinueReceive(this, pSocketObj, pBufferObj, hr))
|
||||
{
|
||||
CSpinLock locallock(pSocketObj->sgPause);
|
||||
{
|
||||
CSpinLock locallock(pSocketObj->sgPause);
|
||||
|
||||
pSocketObj->recving = FALSE;
|
||||
pSocketObj->recving = FALSE;
|
||||
}
|
||||
|
||||
DoReceive(pSocketObj, pBufferObj);
|
||||
}
|
||||
|
||||
DoReceive(pSocketObj, pBufferObj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1476,6 +1470,9 @@ int CTcpAgent::DoSend(CONNID dwConnID)
|
||||
|
||||
int CTcpAgent::DoSend(TSocketObj* pSocketObj)
|
||||
{
|
||||
if(!TSocketObj::IsValid(pSocketObj))
|
||||
return ERROR_OBJECT_NOT_FOUND;
|
||||
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
|
@ -82,9 +82,6 @@ EnHandleResult CTcpServer::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* p
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if(pBufferObj->ReleaseSendCounter() == 0)
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
@ -1079,64 +1076,61 @@ void CTcpServer::HandleAccept(SOCKET soListen, TBufferObj* pBufferObj)
|
||||
|
||||
void CTcpServer::HandleSend(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj)
|
||||
{
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
long iLength = -(long)(pBufferObj->buff.len);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
if(TSocketObj::IsValid(pSocketObj))
|
||||
{
|
||||
case SP_PACK:
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
long iLength = -(long)(pBufferObj->buff.len);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
{
|
||||
case SP_PACK:
|
||||
::InterlockedExchangeAdd(&pSocketObj->sndCount, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
|
||||
DoSendPack(pSocketObj);
|
||||
}
|
||||
|
||||
break;
|
||||
case SP_SAFE:
|
||||
{
|
||||
break;
|
||||
case SP_SAFE:
|
||||
::InterlockedExchangeAdd(&pSocketObj->sndCount, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
|
||||
DoSendSafe(pSocketObj);
|
||||
}
|
||||
|
||||
break;
|
||||
case SP_DIRECT:
|
||||
{
|
||||
break;
|
||||
case SP_DIRECT:
|
||||
::InterlockedExchangeAdd(&pSocketObj->pending, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if(pBufferObj->ReleaseSendCounter() == 0)
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
}
|
||||
|
||||
void CTcpServer::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj)
|
||||
{
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
EnHandleResult hr = TSocketObj::IsValid(pSocketObj) ? HR_OK : (EnHandleResult)HR_CLOSED;
|
||||
|
||||
if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();
|
||||
|
||||
EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj);
|
||||
|
||||
if(hr == HR_OK || hr == HR_IGNORE)
|
||||
if(hr == HR_OK)
|
||||
{
|
||||
if(::ContinueReceive(this, pSocketObj, pBufferObj, hr))
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();
|
||||
|
||||
hr = TriggerFireReceive(pSocketObj, pBufferObj);
|
||||
|
||||
if(hr == HR_OK || hr == HR_IGNORE)
|
||||
{
|
||||
if(::ContinueReceive(this, pSocketObj, pBufferObj, hr))
|
||||
{
|
||||
CSpinLock locallock(pSocketObj->sgPause);
|
||||
{
|
||||
CSpinLock locallock(pSocketObj->sgPause);
|
||||
|
||||
pSocketObj->recving = FALSE;
|
||||
pSocketObj->recving = FALSE;
|
||||
}
|
||||
|
||||
DoReceive(pSocketObj, pBufferObj);
|
||||
}
|
||||
|
||||
DoReceive(pSocketObj, pBufferObj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1384,6 +1378,9 @@ int CTcpServer::DoSend(CONNID dwConnID)
|
||||
|
||||
int CTcpServer::DoSend(TSocketObj* pSocketObj)
|
||||
{
|
||||
if(!TSocketObj::IsValid(pSocketObj))
|
||||
return ERROR_OBJECT_NOT_FOUND;
|
||||
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
|
@ -87,9 +87,6 @@ EnHandleResult CUdpServer::TriggerFireSend(TUdpSocketObj* pSocketObj, TUdpBuffer
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if(pBufferObj->ReleaseSendCounter() == 0)
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
@ -1099,49 +1096,35 @@ void CUdpServer::HandleSend(CONNID dwConnID, TUdpBufferObj* pBufferObj)
|
||||
{
|
||||
TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);
|
||||
|
||||
if(!TUdpSocketObj::IsValid(pSocketObj))
|
||||
if(TUdpSocketObj::IsValid(pSocketObj))
|
||||
{
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
return;
|
||||
}
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
long iLength = -(long)(pBufferObj->buff.len);
|
||||
|
||||
long iLength = -(long)(pBufferObj->buff.len);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
{
|
||||
case SP_PACK:
|
||||
switch(m_enSendPolicy)
|
||||
{
|
||||
case SP_PACK:
|
||||
::InterlockedExchangeAdd(&pSocketObj->sndCount, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
|
||||
DoSendPack(pSocketObj);
|
||||
}
|
||||
|
||||
break;
|
||||
case SP_SAFE:
|
||||
{
|
||||
break;
|
||||
case SP_SAFE:
|
||||
::InterlockedExchangeAdd(&pSocketObj->sndCount, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
|
||||
DoSendSafe(pSocketObj);
|
||||
}
|
||||
|
||||
break;
|
||||
case SP_DIRECT:
|
||||
{
|
||||
break;
|
||||
case SP_DIRECT:
|
||||
::InterlockedExchangeAdd(&pSocketObj->pending, iLength);
|
||||
|
||||
TriggerFireSend(pSocketObj, pBufferObj);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if(pBufferObj->ReleaseSendCounter() == 0)
|
||||
AddFreeBufferObj(pBufferObj);
|
||||
}
|
||||
|
||||
void CUdpServer::HandleReceive(CONNID dwConnID, TUdpBufferObj* pBufferObj)
|
||||
@ -1161,10 +1144,10 @@ void CUdpServer::ProcessReceive(CONNID dwConnID, TUdpBufferObj* pBufferObj)
|
||||
{
|
||||
TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);
|
||||
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
if(TUdpSocketObj::IsValid(pSocketObj))
|
||||
{
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
pSocketObj->detectFails = 0;
|
||||
if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();
|
||||
|
||||
@ -1388,6 +1371,9 @@ int CUdpServer::DoSend(CONNID dwConnID)
|
||||
|
||||
int CUdpServer::DoSend(TUdpSocketObj* pSocketObj)
|
||||
{
|
||||
if(!TSocketObj::IsValid(pSocketObj))
|
||||
return ERROR_OBJECT_NOT_FOUND;
|
||||
|
||||
CLocalSafeCounter localcounter(*pSocketObj);
|
||||
|
||||
switch(m_enSendPolicy)
|
||||
|
Loading…
Reference in New Issue
Block a user