Skip to content

Commit

Permalink
[fix]修正IPacket.ToStr()回收内存后缓冲区被清空的问题。所有单元测试通过
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 12, 2024
1 parent 6b9197c commit 9d1bb9e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion NewLife.Remoting/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,12 @@ public virtual Int32 InvokeOneWay(String action, Object? args = null, Byte flag

if (message.Data == null) return default;
if (resultType == typeof(IPacket)) return (TResult)(Object)message.Data;
if (resultType == typeof(Packet)) return (TResult)(Object)message.Data;
if (resultType == typeof(Packet))
{
if (message.Data is Packet) return (TResult)(Object)message.Data;

return (TResult)(Object)new Packet(message.Data.ToArray());
}

try
{
Expand Down
3 changes: 2 additions & 1 deletion NewLife.Remoting/IApiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ public virtual ControllerContext Prepare(IApiSession session, String action, IPa
// 例如接口 Say(String text),客户端可用 InvokeAsync<Object>("Say", "Hello NewLife!")
else if (args != null)
{
ps[pi.Name] = args.ToStr().ChangeType(pi.ParameterType);
//ps[pi.Name] = args.ToStr().ChangeType(pi.ParameterType);
ps[pi.Name] = raw == null ? null : encoder.Convert(raw, pi.ParameterType);

return ps;
}
Expand Down
6 changes: 3 additions & 3 deletions XUnitTest/ApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ public async void BigMessage()

class BigController
{
public Packet Test(Packet pk)
public IPacket Test(IPacket pk)
{
Assert.Equal(5 * 8 * 1024, pk.Total);

var buf = pk.ReadBytes().Select(e => (Byte)(e ^ 'x')).ToArray();

return buf;
return (ArrayPacket)buf;
}

public void TestOneWay(Packet pk)
public void TestOneWay(IPacket pk)
{
Assert.Equal(5 * 8 * 1024, pk.Total);
}
Expand Down

0 comments on commit 9d1bb9e

Please sign in to comment.