Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Receive() [2/3]

static unsafe SocketError System.Net.Sockets.SocketPal.Receive ( SafeSocketHandle handle,
IList< ArraySegment< byte > > buffers,
SocketFlags socketFlags,
out int bytesTransferred )
inlinestatic

Definition at line 295 of file SocketPal.cs.

296 {
297 int count = buffers.Count;
298 bool flag = count <= 16;
299 WSABuffer[] array = null;
300 GCHandle[] array2 = null;
303 if (flag)
304 {
305 span = stackalloc WSABuffer[16];
307 }
308 else
309 {
310 span = (array = ArrayPool<WSABuffer>.Shared.Rent(count));
311 span2 = (array2 = ArrayPool<GCHandle>.Shared.Rent(count));
312 }
313 span2 = span2.Slice(0, count);
314 span2.Clear();
315 try
316 {
317 for (int i = 0; i < count; i++)
318 {
320 RangeValidationHelpers.ValidateSegment(segment);
321 span2[i] = GCHandle.Alloc(segment.Array, GCHandleType.Pinned);
322 span[i].Length = segment.Count;
324 }
325 SocketError socketError = global::Interop.Winsock.WSARecv(handle, span, count, out bytesTransferred, ref socketFlags, null, IntPtr.Zero);
326 if (socketError == SocketError.SocketError)
327 {
329 }
330 return socketError;
331 }
332 finally
333 {
334 for (int j = 0; j < count; j++)
335 {
336 if (span2[j].IsAllocated)
337 {
338 span2[j].Free();
339 }
340 }
341 if (!flag)
342 {
343 ArrayPool<WSABuffer>.Shared.Return(array);
344 ArrayPool<GCHandle>.Shared.Return(array2);
345 }
346 }
347 }
static SocketError GetLastSocketError()
Definition SocketPal.cs:22
static unsafe IntPtr UnsafeAddrOfPinnedArrayElement(Array arr, int index)
Definition Marshal.cs:775
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81

References System.Runtime.InteropServices.GCHandle.Alloc(), System.array, System.buffers, System.Collections.Generic.Dictionary< TKey, TValue >.Clear(), System.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Net.Sockets.SocketPal.GetLastSocketError(), System.handle, System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(), System.Net.RangeValidationHelpers.ValidateSegment(), and System.IntPtr.Zero.

Referenced by System.Net.Sockets.Socket.Dispose(), System.Net.Sockets.Socket.Receive(), System.Net.Sockets.Socket.Receive(), and System.Net.Sockets.Socket.Receive().