缓存字典
缓存字典
bufs: TDictionary<ICrossConnection, TMemoryStream>; //缓存字典,每个连接都有自己的缓存
bufs := TDictionary<ICrossConnection, TMemoryStream>.Create;
const bufsize = 32768; //每包最大32K
var buf: TMemoryStream; //缓存
if not bufs.ContainsKey(AConnection) then
begin
buf := TMemoryStream.Create;
bufs.Add(AConnection, buf);
end
else
bufs.TryGetValue(AConnection, buf);
buf.Write(ABuf^, ALen);
if ALen < bufsize then //收完 开始解析并处理
begin
//此处省略若干代码
end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/13264793.html