Merged PR 9189: Modify WebSockets ValueTaskSource
Create the GCHandle per operation and Free it when resetting the ValueTaskSource for re-use.
This commit is contained in:
parent
c9f75a1f41
commit
40383cf1f9
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
|||
};
|
||||
|
||||
private readonly WebSocketsAsyncIOEngine _engine;
|
||||
private readonly GCHandle _thisHandle;
|
||||
private GCHandle _thisHandle;
|
||||
private MemoryHandle _inputHandle;
|
||||
private IntPtr _requestHandler;
|
||||
private Memory<byte> _memory;
|
||||
|
|
@ -33,11 +33,11 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
|||
public WebSocketReadOperation(WebSocketsAsyncIOEngine engine)
|
||||
{
|
||||
_engine = engine;
|
||||
_thisHandle = GCHandle.Alloc(this);
|
||||
}
|
||||
|
||||
protected override unsafe bool InvokeOperation(out int hr, out int bytes)
|
||||
{
|
||||
_thisHandle = GCHandle.Alloc(this);
|
||||
_inputHandle = _memory.Pin();
|
||||
|
||||
hr = NativeMethods.HttpWebsocketsReadBytes(
|
||||
|
|
@ -67,6 +67,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
|||
{
|
||||
base.ResetOperation();
|
||||
|
||||
_thisHandle.Free();
|
||||
|
||||
_memory = default;
|
||||
_inputHandle.Dispose();
|
||||
_inputHandle = default;
|
||||
|
|
|
|||
|
|
@ -25,16 +25,16 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
|||
};
|
||||
|
||||
private readonly WebSocketsAsyncIOEngine _engine;
|
||||
private readonly GCHandle _thisHandle;
|
||||
private GCHandle _thisHandle;
|
||||
|
||||
public WebSocketWriteOperation(WebSocketsAsyncIOEngine engine)
|
||||
{
|
||||
_engine = engine;
|
||||
_thisHandle = GCHandle.Alloc(this);
|
||||
}
|
||||
|
||||
protected override unsafe int WriteChunks(IntPtr requestHandler, int chunkCount, HttpApiTypes.HTTP_DATA_CHUNK* dataChunks, out bool completionExpected)
|
||||
{
|
||||
_thisHandle = GCHandle.Alloc(this);
|
||||
return NativeMethods.HttpWebsocketsWriteBytes(requestHandler, dataChunks, chunkCount, WriteCallback, (IntPtr)_thisHandle, out completionExpected);
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +42,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
|||
{
|
||||
base.ResetOperation();
|
||||
|
||||
_thisHandle.Free();
|
||||
|
||||
_engine.ReturnOperation(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
|||
var read = GetReadOperation();
|
||||
read.Initialize(_handler, memory);
|
||||
read.Invoke();
|
||||
return new ValueTask<int>(read, 0);
|
||||
return new ValueTask<int>(read, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue