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

◆ WriteCore()

unsafe void System.Net.HttpResponseStream.WriteCore ( byte[] buffer,
int offset,
int size )
inlineprivate

Definition at line 185 of file HttpResponseStream.cs.

186 {
187 global::Interop.HttpApi.HTTP_FLAGS hTTP_FLAGS = ComputeLeftToWrite();
188 if (size == 0 && _leftToWrite != 0L)
189 {
190 return;
191 }
192 if (_leftToWrite >= 0 && size > _leftToWrite)
193 {
194 throw new ProtocolViolationException(System.SR.net_entitytoobig);
195 }
196 uint num = (uint)size;
197 Microsoft.Win32.SafeHandles.SafeLocalAllocHandle safeLocalAllocHandle = null;
198 IntPtr zero = IntPtr.Zero;
199 bool sentHeaders = _httpContext.Response.SentHeaders;
200 uint num2;
201 try
202 {
203 if (size == 0)
204 {
205 num2 = _httpContext.Response.SendHeaders(null, null, hTTP_FLAGS, isWebSocketHandshake: false);
206 }
207 else
208 {
209 fixed (byte* ptr = buffer)
210 {
211 byte* ptr2 = ptr;
212 if (_httpContext.Response.BoundaryType == BoundaryType.Chunked)
213 {
214 string text = size.ToString("x", CultureInfo.InvariantCulture);
215 num += (uint)(text.Length + 4);
216 safeLocalAllocHandle = Microsoft.Win32.SafeHandles.SafeLocalAllocHandle.LocalAlloc((int)num);
217 zero = safeLocalAllocHandle.DangerousGetHandle();
218 for (int i = 0; i < text.Length; i++)
219 {
220 Marshal.WriteByte(zero, i, (byte)text[i]);
221 }
222 Marshal.WriteInt16(zero, text.Length, 2573);
223 Marshal.Copy(buffer, offset, zero + text.Length + 2, size);
224 Marshal.WriteInt16(zero, (int)(num - 2), 2573);
225 ptr2 = (byte*)(void*)zero;
226 offset = 0;
227 }
228 global::Interop.HttpApi.HTTP_DATA_CHUNK hTTP_DATA_CHUNK = default(global::Interop.HttpApi.HTTP_DATA_CHUNK);
229 hTTP_DATA_CHUNK.DataChunkType = global::Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
230 hTTP_DATA_CHUNK.pBuffer = ptr2 + offset;
231 hTTP_DATA_CHUNK.BufferLength = num;
232 hTTP_FLAGS |= ((_leftToWrite != size) ? global::Interop.HttpApi.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_MORE_DATA : global::Interop.HttpApi.HTTP_FLAGS.NONE);
233 if (!sentHeaders)
234 {
235 num2 = _httpContext.Response.SendHeaders(&hTTP_DATA_CHUNK, null, hTTP_FLAGS, isWebSocketHandshake: false);
236 }
237 else
238 {
239 if (System.Net.NetEventSource.Log.IsEnabled())
240 {
241 System.Net.NetEventSource.Info(this, "Calling Interop.HttpApi.HttpSendResponseEntityBody", "WriteCore");
242 }
243 num2 = global::Interop.HttpApi.HttpSendResponseEntityBody(_httpContext.RequestQueueHandle, _httpContext.RequestId, (uint)hTTP_FLAGS, 1, &hTTP_DATA_CHUNK, null, Microsoft.Win32.SafeHandles.SafeLocalAllocHandle.Zero, 0u, null, null);
244 if (System.Net.NetEventSource.Log.IsEnabled())
245 {
246 System.Net.NetEventSource.Info(this, "Call to Interop.HttpApi.HttpSendResponseEntityBody returned:" + num2, "WriteCore");
247 }
249 {
250 if (System.Net.NetEventSource.Log.IsEnabled())
251 {
252 System.Net.NetEventSource.Info(this, "Write() suppressing error", "WriteCore");
253 }
254 num2 = 0u;
255 }
256 }
257 }
258 }
259 }
260 finally
261 {
262 safeLocalAllocHandle?.Close();
263 }
264 if (num2 != 0 && num2 != 38)
265 {
266 Exception ex = new HttpListenerException((int)num2);
267 if (System.Net.NetEventSource.Log.IsEnabled())
268 {
269 System.Net.NetEventSource.Error(this, ex.ToString(), "WriteCore");
270 }
271 _closed = true;
273 throw ex;
274 }
275 UpdateAfterWrite(num);
276 if (System.Net.NetEventSource.Log.IsEnabled())
277 {
278 System.Net.NetEventSource.DumpBuffer(this, buffer, offset, (int)num, "WriteCore");
279 }
280 }
static readonly Microsoft.Win32.SafeHandles.SafeLocalAllocHandle Zero
static Microsoft.Win32.SafeHandles.SafeLocalAllocHandle LocalAlloc(int cb)
static CultureInfo InvariantCulture
unsafe uint SendHeaders(global::Interop.HttpApi.HTTP_DATA_CHUNK *pDataChunk, HttpResponseStreamAsyncResult asyncResult, global::Interop.HttpApi.HTTP_FLAGS flags, bool isWebSocketHandshake)
void UpdateAfterWrite(uint dataWritten)
global::Interop.HttpApi.HTTP_FLAGS ComputeLeftToWrite()
readonly HttpListenerContext _httpContext
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static void DumpBuffer(object thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string memberName=null)
static void WriteInt16(object ptr, int ofs, short val)
Definition Marshal.cs:97
static void WriteByte(object ptr, int ofs, byte val)
Definition Marshal.cs:89
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static string net_entitytoobig
Definition SR.cs:118
Definition SR.cs:7

References System.Net.HttpResponseStream._closed, System.Net.HttpResponseStream._httpContext, System.Net.HttpResponseStream._leftToWrite, System.Net.HttpListenerContext.Abort(), System.Net.HttpListenerResponse.BoundaryType, System.buffer, System.Runtime.InteropServices.SafeHandle.Close(), System.Net.HttpResponseStream.ComputeLeftToWrite(), System.Runtime.InteropServices.Marshal.Copy(), System.Runtime.InteropServices.SafeHandle.DangerousGetHandle(), System.Net.NetEventSource.DumpBuffer(), System.Net.NetEventSource.Error(), System.Net.HttpListener.IgnoreWriteExceptions, System.Net.NetEventSource.Info(), System.Globalization.CultureInfo.InvariantCulture, System.L, System.Net.HttpListenerContext.Listener, Microsoft.Win32.SafeHandles.SafeLocalAllocHandle.LocalAlloc(), System.Net.NetEventSource.Log, System.SR.net_entitytoobig, System.offset, System.Net.HttpListenerContext.RequestId, System.Net.HttpListenerContext.RequestQueueHandle, System.Net.HttpListenerContext.Response, System.Net.HttpListenerResponse.SendHeaders(), System.Net.HttpListenerResponse.SentHeaders, System.text, System.Exception.ToString(), System.Net.HttpResponseStream.UpdateAfterWrite(), System.Runtime.InteropServices.Marshal.WriteByte(), System.Runtime.InteropServices.Marshal.WriteInt16(), Microsoft.Win32.SafeHandles.SafeLocalAllocHandle.Zero, and System.IntPtr.Zero.

Referenced by System.Net.HttpResponseStream.Write().