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

◆ Send() [2/3]

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

Definition at line 184 of file SocketPal.cs.

185 {
186 int count = buffers.Count;
187 bool flag = count <= 16;
188 WSABuffer[] array = null;
189 GCHandle[] array2 = null;
192 if (flag)
193 {
194 span = stackalloc WSABuffer[16];
196 }
197 else
198 {
199 span = (array = ArrayPool<WSABuffer>.Shared.Rent(count));
200 span2 = (array2 = ArrayPool<GCHandle>.Shared.Rent(count));
201 }
202 span2 = span2.Slice(0, count);
203 span2.Clear();
204 try
205 {
206 for (int i = 0; i < count; i++)
207 {
209 RangeValidationHelpers.ValidateSegment(segment);
210 span2[i] = GCHandle.Alloc(segment.Array, GCHandleType.Pinned);
211 span[i].Length = segment.Count;
213 }
214 SocketError socketError = global::Interop.Winsock.WSASend(handle, span, count, out bytesTransferred, socketFlags, null, IntPtr.Zero);
215 if (socketError == SocketError.SocketError)
216 {
218 }
219 return socketError;
220 }
221 finally
222 {
223 for (int j = 0; j < count; j++)
224 {
225 if (span2[j].IsAllocated)
226 {
227 span2[j].Free();
228 }
229 }
230 if (!flag)
231 {
232 ArrayPool<WSABuffer>.Shared.Return(array);
233 ArrayPool<GCHandle>.Shared.Return(array2);
234 }
235 }
236 }
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.Send(), System.Net.Sockets.Socket.Send(), and System.Net.Sockets.Socket.Send().