scripts
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
// Token: 0x02000202 RID: 514
|
||||
internal class ChunkedInputStream : RequestStream
|
||||
{
|
||||
// Token: 0x06001165 RID: 4453 RVA: 0x00033010 File Offset: 0x00031210
|
||||
public ChunkedInputStream(HttpListenerContext context, Stream stream, byte[] buffer, int offset, int length)
|
||||
: base(stream, buffer, offset, length)
|
||||
{
|
||||
this.context = context;
|
||||
WebHeaderCollection webHeaderCollection = (WebHeaderCollection)context.Request.Headers;
|
||||
this.decoder = new ChunkStream(webHeaderCollection);
|
||||
}
|
||||
|
||||
// Token: 0x170005B7 RID: 1463
|
||||
// (get) Token: 0x06001166 RID: 4454 RVA: 0x00033050 File Offset: 0x00031250
|
||||
// (set) Token: 0x06001167 RID: 4455 RVA: 0x00033058 File Offset: 0x00031258
|
||||
public ChunkStream Decoder
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.decoder;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.decoder = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06001168 RID: 4456 RVA: 0x00033064 File Offset: 0x00031264
|
||||
public override int Read([In] [Out] byte[] buffer, int offset, int count)
|
||||
{
|
||||
IAsyncResult asyncResult = this.BeginRead(buffer, offset, count, null, null);
|
||||
return this.EndRead(asyncResult);
|
||||
}
|
||||
|
||||
// Token: 0x06001169 RID: 4457 RVA: 0x00033084 File Offset: 0x00031284
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
|
||||
{
|
||||
if (this.disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().ToString());
|
||||
}
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("buffer");
|
||||
}
|
||||
int num = buffer.Length;
|
||||
if (offset < 0 || offset > num)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||||
}
|
||||
if (count < 0 || offset > num - count)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||||
}
|
||||
HttpStreamAsyncResult httpStreamAsyncResult = new HttpStreamAsyncResult();
|
||||
httpStreamAsyncResult.Callback = cback;
|
||||
httpStreamAsyncResult.State = state;
|
||||
if (this.no_more_data)
|
||||
{
|
||||
httpStreamAsyncResult.Complete();
|
||||
return httpStreamAsyncResult;
|
||||
}
|
||||
int num2 = this.decoder.Read(buffer, offset, count);
|
||||
offset += num2;
|
||||
count -= num2;
|
||||
if (count == 0)
|
||||
{
|
||||
httpStreamAsyncResult.Count = num2;
|
||||
httpStreamAsyncResult.Complete();
|
||||
return httpStreamAsyncResult;
|
||||
}
|
||||
if (!this.decoder.WantMore)
|
||||
{
|
||||
this.no_more_data = num2 == 0;
|
||||
httpStreamAsyncResult.Count = num2;
|
||||
httpStreamAsyncResult.Complete();
|
||||
return httpStreamAsyncResult;
|
||||
}
|
||||
httpStreamAsyncResult.Buffer = new byte[8192];
|
||||
httpStreamAsyncResult.Offset = 0;
|
||||
httpStreamAsyncResult.Count = 8192;
|
||||
ChunkedInputStream.ReadBufferState readBufferState = new ChunkedInputStream.ReadBufferState(buffer, offset, count, httpStreamAsyncResult);
|
||||
readBufferState.InitialCount += num2;
|
||||
base.BeginRead(httpStreamAsyncResult.Buffer, httpStreamAsyncResult.Offset, httpStreamAsyncResult.Count, new AsyncCallback(this.OnRead), readBufferState);
|
||||
return httpStreamAsyncResult;
|
||||
}
|
||||
|
||||
// Token: 0x0600116A RID: 4458 RVA: 0x000331D8 File Offset: 0x000313D8
|
||||
private void OnRead(IAsyncResult base_ares)
|
||||
{
|
||||
ChunkedInputStream.ReadBufferState readBufferState = (ChunkedInputStream.ReadBufferState)base_ares.AsyncState;
|
||||
HttpStreamAsyncResult ares = readBufferState.Ares;
|
||||
try
|
||||
{
|
||||
int num = base.EndRead(base_ares);
|
||||
this.decoder.Write(ares.Buffer, ares.Offset, num);
|
||||
num = this.decoder.Read(readBufferState.Buffer, readBufferState.Offset, readBufferState.Count);
|
||||
readBufferState.Offset += num;
|
||||
readBufferState.Count -= num;
|
||||
if (readBufferState.Count == 0 || !this.decoder.WantMore || num == 0)
|
||||
{
|
||||
this.no_more_data = !this.decoder.WantMore && num == 0;
|
||||
ares.Count = readBufferState.InitialCount - readBufferState.Count;
|
||||
ares.Complete();
|
||||
}
|
||||
else
|
||||
{
|
||||
ares.Offset = 0;
|
||||
ares.Count = Math.Min(8192, this.decoder.ChunkLeft + 6);
|
||||
base.BeginRead(ares.Buffer, ares.Offset, ares.Count, new AsyncCallback(this.OnRead), readBufferState);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.context.Connection.SendError(ex.Message, 400);
|
||||
ares.Complete(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600116B RID: 4459 RVA: 0x00033344 File Offset: 0x00031544
|
||||
public override int EndRead(IAsyncResult ares)
|
||||
{
|
||||
if (this.disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().ToString());
|
||||
}
|
||||
HttpStreamAsyncResult httpStreamAsyncResult = ares as HttpStreamAsyncResult;
|
||||
if (ares == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid IAsyncResult", "ares");
|
||||
}
|
||||
if (!ares.IsCompleted)
|
||||
{
|
||||
ares.AsyncWaitHandle.WaitOne();
|
||||
}
|
||||
if (httpStreamAsyncResult.Error != null)
|
||||
{
|
||||
throw new HttpListenerException(400, "I/O operation aborted.");
|
||||
}
|
||||
return httpStreamAsyncResult.Count;
|
||||
}
|
||||
|
||||
// Token: 0x0600116C RID: 4460 RVA: 0x000333C4 File Offset: 0x000315C4
|
||||
public override void Close()
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
this.disposed = true;
|
||||
base.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x04000F6A RID: 3946
|
||||
private bool disposed;
|
||||
|
||||
// Token: 0x04000F6B RID: 3947
|
||||
private ChunkStream decoder;
|
||||
|
||||
// Token: 0x04000F6C RID: 3948
|
||||
private HttpListenerContext context;
|
||||
|
||||
// Token: 0x04000F6D RID: 3949
|
||||
private bool no_more_data;
|
||||
|
||||
// Token: 0x02000203 RID: 515
|
||||
private class ReadBufferState
|
||||
{
|
||||
// Token: 0x0600116D RID: 4461 RVA: 0x000333E0 File Offset: 0x000315E0
|
||||
public ReadBufferState(byte[] buffer, int offset, int count, HttpStreamAsyncResult ares)
|
||||
{
|
||||
this.Buffer = buffer;
|
||||
this.Offset = offset;
|
||||
this.Count = count;
|
||||
this.InitialCount = count;
|
||||
this.Ares = ares;
|
||||
}
|
||||
|
||||
// Token: 0x04000F6E RID: 3950
|
||||
public byte[] Buffer;
|
||||
|
||||
// Token: 0x04000F6F RID: 3951
|
||||
public int Offset;
|
||||
|
||||
// Token: 0x04000F70 RID: 3952
|
||||
public int Count;
|
||||
|
||||
// Token: 0x04000F71 RID: 3953
|
||||
public int InitialCount;
|
||||
|
||||
// Token: 0x04000F72 RID: 3954
|
||||
public HttpStreamAsyncResult Ares;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user