unsafe private void SetupOverlappedMultiple()
{
ArraySegment<byte>[] tempList = new ArraySegment<byte>[_bufferList.Count];
_bufferList.CopyTo(tempList, 0);
// Number of things to pin is number of buffers.
// Ensure we have properly sized object array.
if (_objectsToPin == null || (_objectsToPin.Length != tempList.Length))
{
_objectsToPin = new object[tempList.Length];
}
// Fill in object array.
for (int i = 0; i < (tempList.Length); i++)
{
_objectsToPin[i] = tempList[i].Array;
}
if (_wsaBufferArray == null || _wsaBufferArray.Length != tempList.Length)
{
_wsaBufferArray = new WSABuffer[tempList.Length];
}
// Pin buffers and fill in WSABuffer descriptor pointers and lengths.
_preAllocatedOverlapped = new PreAllocatedOverlapped(CompletionPortCallback, this, _objectsToPin);
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"new PreAllocatedOverlapped.{_preAllocatedOverlapped}");
for (int i = 0; i < tempList.Length; i++)
{
ArraySegment<byte> localCopy = tempList[i];
RangeValidationHelpers.ValidateSegment(localCopy);
_wsaBufferArray[i].Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(localCopy.Array, localCopy.Offset);
_wsaBufferArray[i].Length = localCopy.Count;
}
_pinState = PinState.MultipleBuffer;
}