public override unsafe IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
{
if (Logging.On)
{
Logging.Enter(Logging.HttpListener, this, "BeginRead", "");
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if ((offset < 0) || (offset > buffer.Length))
{
throw new ArgumentOutOfRangeException("offset");
}
if ((size < 0) || (size > (buffer.Length - offset)))
{
throw new ArgumentOutOfRangeException("size");
}
if ((size == 0) || this.m_Closed)
{
if (Logging.On)
{
Logging.Exit(Logging.HttpListener, this, "BeginRead", "");
}
HttpRequestStreamAsyncResult result = new HttpRequestStreamAsyncResult(this, state, callback);
result.InvokeCallback(0);
return(result);
}
HttpRequestStreamAsyncResult result2 = null;
uint num = 0;
if (this.m_DataChunkIndex != -1)
{
num = UnsafeNclNativeMethods.HttpApi.GetChunks(this.m_HttpContext.Request.RequestBuffer, this.m_HttpContext.Request.OriginalBlobAddress, ref this.m_DataChunkIndex, ref this.m_DataChunkOffset, buffer, offset, size);
if ((this.m_DataChunkIndex != -1) && (num == size))
{
result2 = new HttpRequestStreamAsyncResult(this, state, callback, buffer, offset, (uint)size, 0);
result2.InvokeCallback(num);
}
}
if ((this.m_DataChunkIndex == -1) && (num < size))
{
uint num2 = 0;
offset += (int)num;
size -= (int)num;
if (size > 0x20000)
{
size = 0x20000;
}
result2 = new HttpRequestStreamAsyncResult(this, state, callback, buffer, offset, (uint)size, num);
try
{
byte[] buffer2 = buffer;
if (buffer2 != null)
{
int length = buffer2.Length;
}
this.m_HttpContext.EnsureBoundHandle();
num2 = UnsafeNclNativeMethods.HttpApi.HttpReceiveRequestEntityBody(this.m_HttpContext.RequestQueueHandle, this.m_HttpContext.RequestId, 1, result2.m_pPinnedBuffer, (uint)size, null, result2.m_pOverlapped);
}
catch (Exception exception)
{
if (Logging.On)
{
Logging.Exception(Logging.HttpListener, this, "BeginRead", exception);
}
result2.InternalCleanup();
throw;
}
switch (num2)
{
case 0:
case 0x3e5:
goto Label_0217;
}
if (num2 == 0x26)
{
result2.m_pOverlapped.InternalLow = IntPtr.Zero;
}
result2.InternalCleanup();
if (num2 != 0x26)
{
Exception e = new HttpListenerException((int)num2);
if (Logging.On)
{
Logging.Exception(Logging.HttpListener, this, "BeginRead", e);
}
result2.InternalCleanup();
throw e;
}
result2 = new HttpRequestStreamAsyncResult(this, state, callback, num);
result2.InvokeCallback(0);
}
Label_0217:
if (Logging.On)
{
Logging.Exit(Logging.HttpListener, this, "BeginRead", "");
}
return(result2);
}