323 lines
8.5 KiB
C#
323 lines
8.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.Remoting.Messaging;
|
|
|
|
namespace System.Net
|
|
{
|
|
// Token: 0x0200021E RID: 542
|
|
internal class FtpDataStream : Stream, IDisposable
|
|
{
|
|
// Token: 0x0600128A RID: 4746 RVA: 0x00037F84 File Offset: 0x00036184
|
|
internal FtpDataStream(FtpWebRequest request, Stream stream, bool isRead)
|
|
{
|
|
if (request == null)
|
|
{
|
|
throw new ArgumentNullException("request");
|
|
}
|
|
this.request = request;
|
|
this.networkStream = stream;
|
|
this.isRead = isRead;
|
|
}
|
|
|
|
// Token: 0x0600128B RID: 4747 RVA: 0x00037FC0 File Offset: 0x000361C0
|
|
void IDisposable.Dispose()
|
|
{
|
|
this.Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
// Token: 0x17000607 RID: 1543
|
|
// (get) Token: 0x0600128C RID: 4748 RVA: 0x00037FD0 File Offset: 0x000361D0
|
|
public override bool CanRead
|
|
{
|
|
get
|
|
{
|
|
return this.isRead;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000608 RID: 1544
|
|
// (get) Token: 0x0600128D RID: 4749 RVA: 0x00037FD8 File Offset: 0x000361D8
|
|
public override bool CanWrite
|
|
{
|
|
get
|
|
{
|
|
return !this.isRead;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000609 RID: 1545
|
|
// (get) Token: 0x0600128E RID: 4750 RVA: 0x00037FE4 File Offset: 0x000361E4
|
|
public override bool CanSeek
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700060A RID: 1546
|
|
// (get) Token: 0x0600128F RID: 4751 RVA: 0x00037FE8 File Offset: 0x000361E8
|
|
public override long Length
|
|
{
|
|
get
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700060B RID: 1547
|
|
// (get) Token: 0x06001290 RID: 4752 RVA: 0x00037FF0 File Offset: 0x000361F0
|
|
// (set) Token: 0x06001291 RID: 4753 RVA: 0x00037FF8 File Offset: 0x000361F8
|
|
public override long Position
|
|
{
|
|
get
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
set
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700060C RID: 1548
|
|
// (get) Token: 0x06001292 RID: 4754 RVA: 0x00038000 File Offset: 0x00036200
|
|
internal Stream NetworkStream
|
|
{
|
|
get
|
|
{
|
|
this.CheckDisposed();
|
|
return this.networkStream;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001293 RID: 4755 RVA: 0x00038010 File Offset: 0x00036210
|
|
public override void Close()
|
|
{
|
|
this.Dispose(true);
|
|
}
|
|
|
|
// Token: 0x06001294 RID: 4756 RVA: 0x0003801C File Offset: 0x0003621C
|
|
public override void Flush()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06001295 RID: 4757 RVA: 0x00038020 File Offset: 0x00036220
|
|
public override long Seek(long offset, SeekOrigin origin)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001296 RID: 4758 RVA: 0x00038028 File Offset: 0x00036228
|
|
public override void SetLength(long value)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001297 RID: 4759 RVA: 0x00038030 File Offset: 0x00036230
|
|
private int ReadInternal(byte[] buffer, int offset, int size)
|
|
{
|
|
int num = 0;
|
|
this.request.CheckIfAborted();
|
|
try
|
|
{
|
|
num = this.networkStream.Read(buffer, offset, size);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
throw new ProtocolViolationException("Server commited a protocol violation");
|
|
}
|
|
this.totalRead += num;
|
|
if (num == 0)
|
|
{
|
|
this.networkStream = null;
|
|
this.request.CloseDataConnection();
|
|
this.request.SetTransferCompleted();
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x06001298 RID: 4760 RVA: 0x000380C0 File Offset: 0x000362C0
|
|
public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback cb, object state)
|
|
{
|
|
this.CheckDisposed();
|
|
if (!this.isRead)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
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("offset+size");
|
|
}
|
|
FtpDataStream.ReadDelegate readDelegate = new FtpDataStream.ReadDelegate(this.ReadInternal);
|
|
return readDelegate.BeginInvoke(buffer, offset, size, cb, state);
|
|
}
|
|
|
|
// Token: 0x06001299 RID: 4761 RVA: 0x00038148 File Offset: 0x00036348
|
|
public override int EndRead(IAsyncResult asyncResult)
|
|
{
|
|
if (asyncResult == null)
|
|
{
|
|
throw new ArgumentNullException("asyncResult");
|
|
}
|
|
AsyncResult asyncResult2 = asyncResult as AsyncResult;
|
|
if (asyncResult2 == null)
|
|
{
|
|
throw new ArgumentException("Invalid asyncResult", "asyncResult");
|
|
}
|
|
FtpDataStream.ReadDelegate readDelegate = asyncResult2.AsyncDelegate as FtpDataStream.ReadDelegate;
|
|
if (readDelegate == null)
|
|
{
|
|
throw new ArgumentException("Invalid asyncResult", "asyncResult");
|
|
}
|
|
return readDelegate.EndInvoke(asyncResult);
|
|
}
|
|
|
|
// Token: 0x0600129A RID: 4762 RVA: 0x000381AC File Offset: 0x000363AC
|
|
public override int Read(byte[] buffer, int offset, int size)
|
|
{
|
|
this.request.CheckIfAborted();
|
|
IAsyncResult asyncResult = this.BeginRead(buffer, offset, size, null, null);
|
|
if (!asyncResult.IsCompleted && !asyncResult.AsyncWaitHandle.WaitOne(this.request.ReadWriteTimeout, false))
|
|
{
|
|
throw new WebException("Read timed out.", WebExceptionStatus.Timeout);
|
|
}
|
|
return this.EndRead(asyncResult);
|
|
}
|
|
|
|
// Token: 0x0600129B RID: 4763 RVA: 0x0003820C File Offset: 0x0003640C
|
|
private void WriteInternal(byte[] buffer, int offset, int size)
|
|
{
|
|
this.request.CheckIfAborted();
|
|
try
|
|
{
|
|
this.networkStream.Write(buffer, offset, size);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
throw new ProtocolViolationException();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600129C RID: 4764 RVA: 0x00038260 File Offset: 0x00036460
|
|
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback cb, object state)
|
|
{
|
|
this.CheckDisposed();
|
|
if (this.isRead)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
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("offset+size");
|
|
}
|
|
FtpDataStream.WriteDelegate writeDelegate = new FtpDataStream.WriteDelegate(this.WriteInternal);
|
|
return writeDelegate.BeginInvoke(buffer, offset, size, cb, state);
|
|
}
|
|
|
|
// Token: 0x0600129D RID: 4765 RVA: 0x000382E8 File Offset: 0x000364E8
|
|
public override void EndWrite(IAsyncResult asyncResult)
|
|
{
|
|
if (asyncResult == null)
|
|
{
|
|
throw new ArgumentNullException("asyncResult");
|
|
}
|
|
AsyncResult asyncResult2 = asyncResult as AsyncResult;
|
|
if (asyncResult2 == null)
|
|
{
|
|
throw new ArgumentException("Invalid asyncResult.", "asyncResult");
|
|
}
|
|
FtpDataStream.WriteDelegate writeDelegate = asyncResult2.AsyncDelegate as FtpDataStream.WriteDelegate;
|
|
if (writeDelegate == null)
|
|
{
|
|
throw new ArgumentException("Invalid asyncResult.", "asyncResult");
|
|
}
|
|
writeDelegate.EndInvoke(asyncResult);
|
|
}
|
|
|
|
// Token: 0x0600129E RID: 4766 RVA: 0x0003834C File Offset: 0x0003654C
|
|
public override void Write(byte[] buffer, int offset, int size)
|
|
{
|
|
this.request.CheckIfAborted();
|
|
IAsyncResult asyncResult = this.BeginWrite(buffer, offset, size, null, null);
|
|
if (!asyncResult.IsCompleted && !asyncResult.AsyncWaitHandle.WaitOne(this.request.ReadWriteTimeout, false))
|
|
{
|
|
throw new WebException("Read timed out.", WebExceptionStatus.Timeout);
|
|
}
|
|
this.EndWrite(asyncResult);
|
|
}
|
|
|
|
// Token: 0x0600129F RID: 4767 RVA: 0x000383AC File Offset: 0x000365AC
|
|
~FtpDataStream()
|
|
{
|
|
this.Dispose(false);
|
|
}
|
|
|
|
// Token: 0x060012A0 RID: 4768 RVA: 0x000383E8 File Offset: 0x000365E8
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (this.disposed)
|
|
{
|
|
return;
|
|
}
|
|
this.disposed = true;
|
|
if (this.networkStream != null)
|
|
{
|
|
this.request.CloseDataConnection();
|
|
this.request.SetTransferCompleted();
|
|
this.request = null;
|
|
this.networkStream = null;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060012A1 RID: 4769 RVA: 0x00038438 File Offset: 0x00036638
|
|
private void CheckDisposed()
|
|
{
|
|
if (this.disposed)
|
|
{
|
|
throw new ObjectDisposedException(base.GetType().FullName);
|
|
}
|
|
}
|
|
|
|
// Token: 0x04000FDB RID: 4059
|
|
private FtpWebRequest request;
|
|
|
|
// Token: 0x04000FDC RID: 4060
|
|
private Stream networkStream;
|
|
|
|
// Token: 0x04000FDD RID: 4061
|
|
private bool disposed;
|
|
|
|
// Token: 0x04000FDE RID: 4062
|
|
private bool isRead;
|
|
|
|
// Token: 0x04000FDF RID: 4063
|
|
private int totalRead;
|
|
|
|
// Token: 0x02000317 RID: 791
|
|
// (Invoke) Token: 0x06001C35 RID: 7221
|
|
private delegate void WriteDelegate(byte[] buffer, int offset, int size);
|
|
|
|
// Token: 0x02000318 RID: 792
|
|
// (Invoke) Token: 0x06001C39 RID: 7225
|
|
private delegate int ReadDelegate(byte[] buffer, int offset, int size);
|
|
}
|
|
}
|