public void Close(byte[] responseEntity, bool willBlock) { if (NetEventSource.IsEnabled) { NetEventSource.Enter(this, $"responseEntity={responseEntity},willBlock={willBlock}"); } try { CheckDisposed(); if (responseEntity == null) { throw new ArgumentNullException(nameof(responseEntity)); } if (NetEventSource.IsEnabled) { NetEventSource.Info(this, $"ResponseState:{_responseState}, BoundaryType:{_boundaryType}, ContentLength:{_contentLength}"); } if (_responseState < ResponseState.SentHeaders && _boundaryType != BoundaryType.Chunked) { ContentLength64 = responseEntity.Length; } EnsureResponseStream(); if (willBlock) { try { _responseStream.Write(responseEntity, 0, responseEntity.Length); } catch (Win32Exception) { } finally { _responseStream.Close(); _responseState = ResponseState.Closed; HttpListenerContext.Close(); } } else { _responseStream.BeginWrite(responseEntity, 0, responseEntity.Length, new AsyncCallback(NonBlockingCloseCallback), null); } } finally { if (NetEventSource.IsEnabled) { NetEventSource.Exit(this); } } }
public void Close(byte[] responseEntity, bool willBlock) { if (Logging.On) { Logging.Enter(Logging.HttpListener, this, "Close", " responseEntity=" + ValidationHelper.HashString(responseEntity) + " willBlock=" + willBlock); } try { CheckDisposed(); if (responseEntity == null) { throw new ArgumentNullException("responseEntity"); } GlobalLog.Print("HttpListenerResponse#" + ValidationHelper.HashString(this) + "::Close() ResponseState:" + m_ResponseState + " BoundaryType:" + m_BoundaryType + " ContentLength:" + m_ContentLength); if (m_ResponseState < ResponseState.SentHeaders && m_BoundaryType != BoundaryType.Chunked) { ContentLength64 = responseEntity.Length; } EnsureResponseStream(); if (willBlock) { try { m_ResponseStream.Write(responseEntity, 0, responseEntity.Length); } catch (Win32Exception) { } finally { m_ResponseStream.Close(); m_ResponseState = ResponseState.Closed; HttpListenerContext.Close(); } } else { // < m_ResponseStream.BeginWrite(responseEntity, 0, responseEntity.Length, new AsyncCallback(NonBlockingCloseCallback), null); } } finally { if (Logging.On) { Logging.Exit(Logging.HttpListener, this, "Close", ""); } } }