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);
}
}