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

◆ BeginWriteCore()

unsafe IAsyncResult System.Net.HttpResponseStream.BeginWriteCore ( byte[] buffer,
int offset,
int size,
AsyncCallback callback,
object state )
inlineprivate

Definition at line 282 of file HttpResponseStream.cs.

283 {
284 global::Interop.HttpApi.HTTP_FLAGS hTTP_FLAGS = ComputeLeftToWrite();
285 if (_closed || (size == 0 && _leftToWrite != 0L))
286 {
287 HttpResponseStreamAsyncResult httpResponseStreamAsyncResult = new HttpResponseStreamAsyncResult(this, state, callback);
288 httpResponseStreamAsyncResult.InvokeCallback(0u);
289 return httpResponseStreamAsyncResult;
290 }
291 if (_leftToWrite >= 0 && size > _leftToWrite)
292 {
293 throw new ProtocolViolationException(System.SR.net_entitytoobig);
294 }
295 uint numBytes = 0u;
296 hTTP_FLAGS |= ((_leftToWrite != size) ? global::Interop.HttpApi.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_MORE_DATA : global::Interop.HttpApi.HTTP_FLAGS.NONE);
297 bool sentHeaders = _httpContext.Response.SentHeaders;
298 HttpResponseStreamAsyncResult httpResponseStreamAsyncResult2 = new HttpResponseStreamAsyncResult(this, state, callback, buffer, offset, size, _httpContext.Response.BoundaryType == BoundaryType.Chunked, sentHeaders, _httpContext.RequestQueueBoundHandle);
299 UpdateAfterWrite((_httpContext.Response.BoundaryType != BoundaryType.Chunked) ? ((uint)size) : 0u);
300 uint num;
301 try
302 {
303 if (!sentHeaders)
304 {
305 num = _httpContext.Response.SendHeaders(null, httpResponseStreamAsyncResult2, hTTP_FLAGS, isWebSocketHandshake: false);
306 }
307 else
308 {
309 if (System.Net.NetEventSource.Log.IsEnabled())
310 {
311 System.Net.NetEventSource.Info(this, "Calling Interop.HttpApi.HttpSendResponseEntityBody", "BeginWriteCore");
312 }
313 num = global::Interop.HttpApi.HttpSendResponseEntityBody(_httpContext.RequestQueueHandle, _httpContext.RequestId, (uint)hTTP_FLAGS, httpResponseStreamAsyncResult2.dataChunkCount, httpResponseStreamAsyncResult2.pDataChunks, &numBytes, Microsoft.Win32.SafeHandles.SafeLocalAllocHandle.Zero, 0u, httpResponseStreamAsyncResult2._pOverlapped, null);
314 if (System.Net.NetEventSource.Log.IsEnabled())
315 {
316 System.Net.NetEventSource.Info(this, "Call to Interop.HttpApi.HttpSendResponseEntityBody returned:" + num, "BeginWriteCore");
317 }
318 }
319 }
320 catch (Exception ex)
321 {
322 if (System.Net.NetEventSource.Log.IsEnabled())
323 {
324 System.Net.NetEventSource.Error(this, ex.ToString(), "BeginWriteCore");
325 }
326 httpResponseStreamAsyncResult2.InternalCleanup();
327 _closed = true;
329 throw;
330 }
331 if (num != 0 && num != 997)
332 {
333 httpResponseStreamAsyncResult2.InternalCleanup();
334 if (!(_httpContext.Listener.IgnoreWriteExceptions && sentHeaders))
335 {
336 Exception ex2 = new HttpListenerException((int)num);
337 if (System.Net.NetEventSource.Log.IsEnabled())
338 {
339 System.Net.NetEventSource.Error(this, ex2.ToString(), "BeginWriteCore");
340 }
341 _closed = true;
343 throw ex2;
344 }
345 if (System.Net.NetEventSource.Log.IsEnabled())
346 {
347 System.Net.NetEventSource.Info(this, "BeginWrite() Suppressing error", "BeginWriteCore");
348 }
349 }
350 if (num == 0 && HttpListener.SkipIOCPCallbackOnSuccess)
351 {
352 httpResponseStreamAsyncResult2.IOCompleted(num, numBytes);
353 }
354 if ((hTTP_FLAGS & global::Interop.HttpApi.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_MORE_DATA) == 0)
355 {
356 _lastWrite = httpResponseStreamAsyncResult2;
357 }
358 return httpResponseStreamAsyncResult2;
359 }
static readonly Microsoft.Win32.SafeHandles.SafeLocalAllocHandle Zero
ThreadPoolBoundHandle RequestQueueBoundHandle
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
HttpResponseStreamAsyncResult _lastWrite
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 string net_entitytoobig
Definition SR.cs:118
Definition SR.cs:7

References System.Net.HttpResponseStream._closed, System.Net.HttpResponseStream._httpContext, System.Net.HttpResponseStream._lastWrite, System.Net.HttpResponseStream._leftToWrite, System.Net.HttpResponseStreamAsyncResult._pOverlapped, System.Net.HttpListenerContext.Abort(), System.Net.HttpListenerResponse.BoundaryType, System.buffer, System.Net.HttpResponseStream.ComputeLeftToWrite(), System.Net.HttpResponseStreamAsyncResult.dataChunkCount, System.Net.NetEventSource.Error(), System.Net.HttpListener.IgnoreWriteExceptions, System.Net.NetEventSource.Info(), System.Net.LazyAsyncResult.InternalCleanup(), System.Net.LazyAsyncResult.InvokeCallback(), System.Net.HttpResponseStreamAsyncResult.IOCompleted(), System.L, System.Net.HttpListenerContext.Listener, System.Net.NetEventSource.Log, System.SR.net_entitytoobig, System.offset, System.Net.HttpResponseStreamAsyncResult.pDataChunks, System.Net.HttpListenerContext.RequestId, System.Net.HttpListenerContext.RequestQueueBoundHandle, System.Net.HttpListenerContext.RequestQueueHandle, System.Net.HttpListenerContext.Response, System.Net.HttpListenerResponse.SendHeaders(), System.Net.HttpListenerResponse.SentHeaders, System.Net.HttpListener.SkipIOCPCallbackOnSuccess, System.state, System.Exception.ToString(), System.Net.HttpResponseStream.UpdateAfterWrite(), and Microsoft.Win32.SafeHandles.SafeLocalAllocHandle.Zero.

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