617 lines
36 KiB
C#
617 lines
36 KiB
C#
using System;
|
||
using System.IO;
|
||
using System.Runtime.InteropServices;
|
||
|
||
namespace System.Net.Sockets
|
||
{
|
||
/// <summary>Provides the underlying stream of data for network access.</summary>
|
||
// Token: 0x020001DE RID: 478
|
||
public class NetworkStream : Stream, IDisposable
|
||
{
|
||
/// <summary>Creates a new instance of the <see cref="T:System.Net.Sockets.NetworkStream" /> class for the specified <see cref="T:System.Net.Sockets.Socket" />.</summary>
|
||
/// <param name="socket">The <see cref="T:System.Net.Sockets.Socket" /> that the <see cref="T:System.Net.Sockets.NetworkStream" /> will use to send and receive data. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="socket" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The <paramref name="socket" /> parameter is not connected.-or- The <see cref="P:System.Net.Sockets.Socket.SocketType" /> property of the <paramref name="socket" /> parameter is not <see cref="F:System.Net.Sockets.SocketType.Stream" />.-or- The <paramref name="socket" /> parameter is in a nonblocking state. </exception>
|
||
// Token: 0x06000F6E RID: 3950 RVA: 0x0002A508 File Offset: 0x00028708
|
||
public NetworkStream(Socket socket)
|
||
: this(socket, FileAccess.ReadWrite, false)
|
||
{
|
||
}
|
||
|
||
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Sockets.NetworkStream" /> class for the specified <see cref="T:System.Net.Sockets.Socket" /> with the specified <see cref="T:System.Net.Sockets.Socket" /> ownership.</summary>
|
||
/// <param name="socket">The <see cref="T:System.Net.Sockets.Socket" /> that the <see cref="T:System.Net.Sockets.NetworkStream" /> will use to send and receive data. </param>
|
||
/// <param name="ownsSocket">Set to true to indicate that the <see cref="T:System.Net.Sockets.NetworkStream" /> will take ownership of the <see cref="T:System.Net.Sockets.Socket" />; otherwise, false. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="socket" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The <paramref name="socket" /> parameter is not connected.-or- the value of the <see cref="P:System.Net.Sockets.Socket.SocketType" /> property of the <paramref name="socket" /> parameter is not <see cref="F:System.Net.Sockets.SocketType.Stream" />.-or- the <paramref name="socket" /> parameter is in a nonblocking state. </exception>
|
||
// Token: 0x06000F6F RID: 3951 RVA: 0x0002A514 File Offset: 0x00028714
|
||
public NetworkStream(Socket socket, bool owns_socket)
|
||
: this(socket, FileAccess.ReadWrite, owns_socket)
|
||
{
|
||
}
|
||
|
||
/// <summary>Creates a new instance of the <see cref="T:System.Net.Sockets.NetworkStream" /> class for the specified <see cref="T:System.Net.Sockets.Socket" /> with the specified access rights.</summary>
|
||
/// <param name="socket">The <see cref="T:System.Net.Sockets.Socket" /> that the <see cref="T:System.Net.Sockets.NetworkStream" /> will use to send and receive data. </param>
|
||
/// <param name="access">A bitwise combination of the <see cref="T:System.IO.FileAccess" /> values that specify the type of access given to the <see cref="T:System.Net.Sockets.NetworkStream" /> over the provided <see cref="T:System.Net.Sockets.Socket" />. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="socket" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The <paramref name="socket" /> parameter is not connected.-or- the <see cref="P:System.Net.Sockets.Socket.SocketType" /> property of the <paramref name="socket" /> parameter is not <see cref="F:System.Net.Sockets.SocketType.Stream" />.-or- the <paramref name="socket" /> parameter is in a nonblocking state. </exception>
|
||
// Token: 0x06000F70 RID: 3952 RVA: 0x0002A520 File Offset: 0x00028720
|
||
public NetworkStream(Socket socket, FileAccess access)
|
||
: this(socket, access, false)
|
||
{
|
||
}
|
||
|
||
/// <summary>Creates a new instance of the <see cref="T:System.Net.Sockets.NetworkStream" /> class for the specified <see cref="T:System.Net.Sockets.Socket" /> with the specified access rights and the specified <see cref="T:System.Net.Sockets.Socket" /> ownership.</summary>
|
||
/// <param name="socket">The <see cref="T:System.Net.Sockets.Socket" /> that the <see cref="T:System.Net.Sockets.NetworkStream" /> will use to send and receive data. </param>
|
||
/// <param name="access">A bitwise combination of the <see cref="T:System.IO.FileAccess" /> values that specifies the type of access given to the <see cref="T:System.Net.Sockets.NetworkStream" /> over the provided <see cref="T:System.Net.Sockets.Socket" />. </param>
|
||
/// <param name="ownsSocket">Set to true to indicate that the <see cref="T:System.Net.Sockets.NetworkStream" /> will take ownership of the <see cref="T:System.Net.Sockets.Socket" />; otherwise, false. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="socket" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The <paramref name="socket" /> parameter is not connected.-or- The <see cref="P:System.Net.Sockets.Socket.SocketType" /> property of the <paramref name="socket" /> parameter is not <see cref="F:System.Net.Sockets.SocketType.Stream" />.-or- The <paramref name="socket" /> parameter is in a nonblocking state. </exception>
|
||
// Token: 0x06000F71 RID: 3953 RVA: 0x0002A52C File Offset: 0x0002872C
|
||
public NetworkStream(Socket socket, FileAccess access, bool owns_socket)
|
||
{
|
||
if (socket == null)
|
||
{
|
||
throw new ArgumentNullException("socket is null");
|
||
}
|
||
if (socket.SocketType != SocketType.Stream)
|
||
{
|
||
throw new ArgumentException("Socket is not of type Stream", "socket");
|
||
}
|
||
if (!socket.Connected)
|
||
{
|
||
throw new IOException("Not connected");
|
||
}
|
||
if (!socket.Blocking)
|
||
{
|
||
throw new IOException("Operation not allowed on a non-blocking socket.");
|
||
}
|
||
this.socket = socket;
|
||
this.owns_socket = owns_socket;
|
||
this.access = access;
|
||
this.readable = this.CanRead;
|
||
this.writeable = this.CanWrite;
|
||
}
|
||
|
||
/// <summary>Releases all resources used by the <see cref="T:System.Net.Sockets.NetworkStream" />.</summary>
|
||
// Token: 0x06000F72 RID: 3954 RVA: 0x0002A5C8 File Offset: 0x000287C8
|
||
void IDisposable.Dispose()
|
||
{
|
||
this.Dispose(true);
|
||
GC.SuppressFinalize(this);
|
||
}
|
||
|
||
/// <summary>Gets a value that indicates whether the <see cref="T:System.Net.Sockets.NetworkStream" /> supports reading.</summary>
|
||
/// <returns>true if data can be read from the stream; otherwise, false. The default value is true.</returns>
|
||
// Token: 0x17000547 RID: 1351
|
||
// (get) Token: 0x06000F73 RID: 3955 RVA: 0x0002A5D8 File Offset: 0x000287D8
|
||
public override bool CanRead
|
||
{
|
||
get
|
||
{
|
||
return this.access == FileAccess.ReadWrite || this.access == FileAccess.Read;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets a value that indicates whether the stream supports seeking. This property is not currently supported.This property always returns false.</summary>
|
||
/// <returns>false in all cases to indicate that <see cref="T:System.Net.Sockets.NetworkStream" /> cannot seek a specific location in the stream.</returns>
|
||
// Token: 0x17000548 RID: 1352
|
||
// (get) Token: 0x06000F74 RID: 3956 RVA: 0x0002A5F4 File Offset: 0x000287F4
|
||
public override bool CanSeek
|
||
{
|
||
get
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>Indicates whether timeout properties are usable for <see cref="T:System.Net.Sockets.NetworkStream" />.</summary>
|
||
/// <returns>true in all cases.</returns>
|
||
// Token: 0x17000549 RID: 1353
|
||
// (get) Token: 0x06000F75 RID: 3957 RVA: 0x0002A5F8 File Offset: 0x000287F8
|
||
public override bool CanTimeout
|
||
{
|
||
get
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets a value that indicates whether the <see cref="T:System.Net.Sockets.NetworkStream" /> supports writing.</summary>
|
||
/// <returns>true if data can be written to the <see cref="T:System.Net.Sockets.NetworkStream" />; otherwise, false. The default value is true.</returns>
|
||
// Token: 0x1700054A RID: 1354
|
||
// (get) Token: 0x06000F76 RID: 3958 RVA: 0x0002A5FC File Offset: 0x000287FC
|
||
public override bool CanWrite
|
||
{
|
||
get
|
||
{
|
||
return this.access == FileAccess.ReadWrite || this.access == FileAccess.Write;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets a value that indicates whether data is available on the <see cref="T:System.Net.Sockets.NetworkStream" /> to be read.</summary>
|
||
/// <returns>true if data is available on the stream to be read; otherwise, false.</returns>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The underlying <see cref="T:System.Net.Sockets.Socket" /> is closed. </exception>
|
||
/// <exception cref="T:System.Net.Sockets.SocketException">Use the <see cref="P:System.Net.Sockets.SocketException.ErrorCode" /> property to obtain the specific error code, and refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x1700054B RID: 1355
|
||
// (get) Token: 0x06000F77 RID: 3959 RVA: 0x0002A618 File Offset: 0x00028818
|
||
public virtual bool DataAvailable
|
||
{
|
||
get
|
||
{
|
||
this.CheckDisposed();
|
||
return this.socket.Available > 0;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets the length of the data available on the stream. This property is not currently supported and always throws a <see cref="T:System.NotSupportedException" />.</summary>
|
||
/// <returns>The length of the data available on the stream.</returns>
|
||
/// <exception cref="T:System.NotSupportedException">Any use of this property. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x1700054C RID: 1356
|
||
// (get) Token: 0x06000F78 RID: 3960 RVA: 0x0002A630 File Offset: 0x00028830
|
||
public override long Length
|
||
{
|
||
get
|
||
{
|
||
throw new NotSupportedException();
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets or sets the current position in the stream. This property is not currently supported and always throws a <see cref="T:System.NotSupportedException" />.</summary>
|
||
/// <returns>The current position in the stream.</returns>
|
||
/// <exception cref="T:System.NotSupportedException">Any use of this property. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x1700054D RID: 1357
|
||
// (get) Token: 0x06000F79 RID: 3961 RVA: 0x0002A638 File Offset: 0x00028838
|
||
// (set) Token: 0x06000F7A RID: 3962 RVA: 0x0002A640 File Offset: 0x00028840
|
||
public override long Position
|
||
{
|
||
get
|
||
{
|
||
throw new NotSupportedException();
|
||
}
|
||
set
|
||
{
|
||
throw new NotSupportedException();
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets or sets a value that indicates whether the <see cref="T:System.Net.Sockets.NetworkStream" /> can be read.</summary>
|
||
/// <returns>true to indicate that the <see cref="T:System.Net.Sockets.NetworkStream" /> can be read; otherwise, false. The default value is true.</returns>
|
||
// Token: 0x1700054E RID: 1358
|
||
// (get) Token: 0x06000F7B RID: 3963 RVA: 0x0002A648 File Offset: 0x00028848
|
||
// (set) Token: 0x06000F7C RID: 3964 RVA: 0x0002A650 File Offset: 0x00028850
|
||
protected bool Readable
|
||
{
|
||
get
|
||
{
|
||
return this.readable;
|
||
}
|
||
set
|
||
{
|
||
this.readable = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets or sets the amount of time that a read operation blocks waiting for data. </summary>
|
||
/// <returns>A <see cref="T:System.Int32" /> that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, <see cref="F:System.Threading.Timeout.Infinite" />, specifies that the read operation does not time out.</returns>
|
||
/// <exception cref="T:System.ArgumentOutOfRangeException">The value specified is less than or equal to zero and is not <see cref="F:System.Threading.Timeout.Infinite" />. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x1700054F RID: 1359
|
||
// (get) Token: 0x06000F7D RID: 3965 RVA: 0x0002A65C File Offset: 0x0002885C
|
||
// (set) Token: 0x06000F7E RID: 3966 RVA: 0x0002A66C File Offset: 0x0002886C
|
||
public override int ReadTimeout
|
||
{
|
||
get
|
||
{
|
||
return this.socket.ReceiveTimeout;
|
||
}
|
||
set
|
||
{
|
||
if (value <= 0 && (float)value != NetworkStream.Timeout.Infinite)
|
||
{
|
||
throw new ArgumentOutOfRangeException("value", "The value specified is less than or equal to zero and is not Infinite.");
|
||
}
|
||
this.socket.ReceiveTimeout = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets the underlying <see cref="T:System.Net.Sockets.Socket" />.</summary>
|
||
/// <returns>A <see cref="T:System.Net.Sockets.Socket" /> that represents the underlying network connection.</returns>
|
||
// Token: 0x17000550 RID: 1360
|
||
// (get) Token: 0x06000F7F RID: 3967 RVA: 0x0002A6A0 File Offset: 0x000288A0
|
||
protected Socket Socket
|
||
{
|
||
get
|
||
{
|
||
return this.socket;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets a value that indicates whether the <see cref="T:System.Net.Sockets.NetworkStream" /> is writable.</summary>
|
||
/// <returns>true if data can be written to the stream; otherwise, false. The default value is true.</returns>
|
||
// Token: 0x17000551 RID: 1361
|
||
// (get) Token: 0x06000F80 RID: 3968 RVA: 0x0002A6A8 File Offset: 0x000288A8
|
||
// (set) Token: 0x06000F81 RID: 3969 RVA: 0x0002A6B0 File Offset: 0x000288B0
|
||
protected bool Writeable
|
||
{
|
||
get
|
||
{
|
||
return this.writeable;
|
||
}
|
||
set
|
||
{
|
||
this.writeable = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>Gets or sets the amount of time that a write operation blocks waiting for data. </summary>
|
||
/// <returns>A <see cref="T:System.Int32" /> that specifies the amount of time, in milliseconds, that will elapse before a write operation fails. The default value, <see cref="F:System.Threading.Timeout.Infinite" />, specifies that the write operation does not time out.</returns>
|
||
/// <exception cref="T:System.ArgumentOutOfRangeException">The value specified is less than or equal to zero and is not <see cref="F:System.Threading.Timeout.Infinite" />. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x17000552 RID: 1362
|
||
// (get) Token: 0x06000F82 RID: 3970 RVA: 0x0002A6BC File Offset: 0x000288BC
|
||
// (set) Token: 0x06000F83 RID: 3971 RVA: 0x0002A6CC File Offset: 0x000288CC
|
||
public override int WriteTimeout
|
||
{
|
||
get
|
||
{
|
||
return this.socket.SendTimeout;
|
||
}
|
||
set
|
||
{
|
||
if (value <= 0 && (float)value != NetworkStream.Timeout.Infinite)
|
||
{
|
||
throw new ArgumentOutOfRangeException("value", "The value specified is less than or equal to zero and is not Infinite");
|
||
}
|
||
this.socket.SendTimeout = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>Begins an asynchronous read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</summary>
|
||
/// <returns>An <see cref="T:System.IAsyncResult" /> that represents the asynchronous call.</returns>
|
||
/// <param name="buffer">An array of type <see cref="T:System.Byte" /> that is the location in memory to store data read from the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <param name="offset">The location in <paramref name="buffer" /> to begin storing the data. </param>
|
||
/// <param name="size">The number of bytes to read from the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate that is executed when <see cref="M:System.Net.Sockets.NetworkStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" /> completes. </param>
|
||
/// <param name="state">An object that contains any additional user-defined data. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="buffer" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="offset" /> parameter is less than 0.-or- The <paramref name="offset" /> parameter is greater than the length of the <paramref name="buffer" /> paramater.-or- The <paramref name="size" /> is less than 0.-or- The <paramref name="size" /> is greater than the length of <paramref name="buffer" /> minus the value of the <paramref name="offset" /> parameter.</exception>
|
||
/// <exception cref="T:System.IO.IOException">The underlying <see cref="T:System.Net.Sockets.Socket" /> is closed.-or- There was a failure while reading from the network. -or-An error occurred when accessing the socket. See the Remarks section for more information.</exception>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x06000F84 RID: 3972 RVA: 0x0002A700 File Offset: 0x00028900
|
||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
|
||
{
|
||
this.CheckDisposed();
|
||
if (buffer == null)
|
||
{
|
||
throw new ArgumentNullException("buffer is null");
|
||
}
|
||
int num = buffer.Length;
|
||
if (offset < 0 || offset > num)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||
}
|
||
if (size < 0 || offset + size > num)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||
}
|
||
IAsyncResult asyncResult;
|
||
try
|
||
{
|
||
asyncResult = this.socket.BeginReceive(buffer, offset, size, SocketFlags.None, callback, state);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new IOException("BeginReceive failure", ex);
|
||
}
|
||
return asyncResult;
|
||
}
|
||
|
||
/// <summary>Begins an asynchronous write to a stream.</summary>
|
||
/// <returns>An <see cref="T:System.IAsyncResult" /> that represents the asynchronous call.</returns>
|
||
/// <param name="buffer">An array of type <see cref="T:System.Byte" /> that contains the data to write to the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <param name="offset">The location in <paramref name="buffer" /> to begin sending the data. </param>
|
||
/// <param name="size">The number of bytes to write to the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate that is executed when <see cref="M:System.Net.Sockets.NetworkStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" /> completes. </param>
|
||
/// <param name="state">An object that contains any additional user-defined data. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="buffer" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="offset" /> parameter is less than 0.-or- The <paramref name="offset" /> parameter is greater than the length of <paramref name="buffer" />.-or- The <paramref name="size" /> parameter is less than 0.-or- The <paramref name="size" /> parameter is greater than the length of <paramref name="buffer" /> minus the value of the <paramref name="offset" /> parameter. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The underlying <see cref="T:System.Net.Sockets.Socket" /> is closed.-or- There was a failure while writing to the network. -or-An error occurred when accessing the socket. See the Remarks section for more information.</exception>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// </PermissionSet>
|
||
// Token: 0x06000F85 RID: 3973 RVA: 0x0002A7A4 File Offset: 0x000289A4
|
||
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
|
||
{
|
||
this.CheckDisposed();
|
||
if (buffer == null)
|
||
{
|
||
throw new ArgumentNullException("buffer is null");
|
||
}
|
||
int num = buffer.Length;
|
||
if (offset < 0 || offset > num)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||
}
|
||
if (size < 0 || offset + size > num)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||
}
|
||
IAsyncResult asyncResult;
|
||
try
|
||
{
|
||
asyncResult = this.socket.BeginSend(buffer, offset, size, SocketFlags.None, callback, state);
|
||
}
|
||
catch
|
||
{
|
||
throw new IOException("BeginWrite failure");
|
||
}
|
||
return asyncResult;
|
||
}
|
||
|
||
/// <summary>Releases all resources used by the <see cref="T:System.Net.Sockets.NetworkStream" />.</summary>
|
||
// Token: 0x06000F86 RID: 3974 RVA: 0x0002A848 File Offset: 0x00028A48
|
||
~NetworkStream()
|
||
{
|
||
this.Dispose(false);
|
||
}
|
||
|
||
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Net.Sockets.NetworkStream" /> and optionally releases the managed resources.</summary>
|
||
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources. </param>
|
||
// Token: 0x06000F87 RID: 3975 RVA: 0x0002A884 File Offset: 0x00028A84
|
||
protected override void Dispose(bool disposing)
|
||
{
|
||
if (this.disposed)
|
||
{
|
||
return;
|
||
}
|
||
this.disposed = true;
|
||
if (this.owns_socket)
|
||
{
|
||
Socket socket = this.socket;
|
||
if (socket != null)
|
||
{
|
||
socket.Close();
|
||
}
|
||
}
|
||
this.socket = null;
|
||
this.access = (FileAccess)0;
|
||
}
|
||
|
||
/// <summary>Handles the end of an asynchronous read.</summary>
|
||
/// <returns>The number of bytes read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</returns>
|
||
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> that represents an asynchronous call. </param>
|
||
/// <exception cref="T:System.ArgumentException">The <paramref name="asyncResult" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The underlying <see cref="T:System.Net.Sockets.Socket" /> is closed.-or- An error occurred when accessing the socket. See the Remarks section for more information.</exception>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// </PermissionSet>
|
||
// Token: 0x06000F88 RID: 3976 RVA: 0x0002A8D0 File Offset: 0x00028AD0
|
||
public override int EndRead(IAsyncResult ar)
|
||
{
|
||
this.CheckDisposed();
|
||
if (ar == null)
|
||
{
|
||
throw new ArgumentNullException("async result is null");
|
||
}
|
||
int num;
|
||
try
|
||
{
|
||
num = this.socket.EndReceive(ar);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new IOException("EndRead failure", ex);
|
||
}
|
||
return num;
|
||
}
|
||
|
||
/// <summary>Handles the end of an asynchronous write.</summary>
|
||
/// <param name="asyncResult">The <see cref="T:System.IAsyncResult" /> that represents the asynchronous call. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="asyncResult" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.IO.IOException">The underlying <see cref="T:System.Net.Sockets.Socket" /> is closed.-or- An error occurred while writing to the network. -or-An error occurred when accessing the socket. See the Remarks section for more information.</exception>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// </PermissionSet>
|
||
// Token: 0x06000F89 RID: 3977 RVA: 0x0002A938 File Offset: 0x00028B38
|
||
public override void EndWrite(IAsyncResult ar)
|
||
{
|
||
this.CheckDisposed();
|
||
if (ar == null)
|
||
{
|
||
throw new ArgumentNullException("async result is null");
|
||
}
|
||
try
|
||
{
|
||
this.socket.EndSend(ar);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new IOException("EndWrite failure", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>Flushes data from the stream. This method is reserved for future use.</summary>
|
||
// Token: 0x06000F8A RID: 3978 RVA: 0x0002A99C File Offset: 0x00028B9C
|
||
public override void Flush()
|
||
{
|
||
}
|
||
|
||
/// <summary>Reads data from the <see cref="T:System.Net.Sockets.NetworkStream" />.</summary>
|
||
/// <returns>The number of bytes read from the <see cref="T:System.Net.Sockets.NetworkStream" />.</returns>
|
||
/// <param name="buffer">An array of type <see cref="T:System.Byte" /> that is the location in memory to store data read from the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <param name="offset">The location in <paramref name="buffer" /> to begin storing the data to. </param>
|
||
/// <param name="size">The number of bytes to read from the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="buffer" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="offset" /> parameter is less than 0.-or- The <paramref name="offset" /> parameter is greater than the length of <paramref name="buffer" />.-or- The <paramref name="size" /> parameter is less than 0.-or- The <paramref name="size" /> parameter is greater than the length of <paramref name="buffer" /> minus the value of the <paramref name="offset" /> parameter. -or-An error occurred when accessing the socket. See the Remarks section for more information.</exception>
|
||
/// <exception cref="T:System.IO.IOException">The underlying <see cref="T:System.Net.Sockets.Socket" /> is closed. </exception>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed.-or- There is a failure reading from the network. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// </PermissionSet>
|
||
// Token: 0x06000F8B RID: 3979 RVA: 0x0002A9A0 File Offset: 0x00028BA0
|
||
public override int Read([In] [Out] byte[] buffer, int offset, int size)
|
||
{
|
||
this.CheckDisposed();
|
||
if (buffer == null)
|
||
{
|
||
throw new ArgumentNullException("buffer is null");
|
||
}
|
||
if (offset < 0 || offset > buffer.Length)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||
}
|
||
if (size < 0 || offset + size > buffer.Length)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||
}
|
||
int num;
|
||
try
|
||
{
|
||
num = this.socket.Receive(buffer, offset, size, SocketFlags.None);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new IOException("Read failure", ex);
|
||
}
|
||
return num;
|
||
}
|
||
|
||
/// <summary>Sets the current position of the stream to the given value. This method is not currently supported and always throws a <see cref="T:System.NotSupportedException" />.</summary>
|
||
/// <returns>The position in the stream.</returns>
|
||
/// <param name="offset">This parameter is not used. </param>
|
||
/// <param name="origin">This parameter is not used. </param>
|
||
/// <exception cref="T:System.NotSupportedException">Any use of this property. </exception>
|
||
// Token: 0x06000F8C RID: 3980 RVA: 0x0002AA40 File Offset: 0x00028C40
|
||
public override long Seek(long offset, SeekOrigin origin)
|
||
{
|
||
throw new NotSupportedException();
|
||
}
|
||
|
||
/// <summary>Sets the length of the stream. This method always throws a <see cref="T:System.NotSupportedException" />.</summary>
|
||
/// <param name="value">This parameter is not used. </param>
|
||
/// <exception cref="T:System.NotSupportedException">Any use of this property. </exception>
|
||
// Token: 0x06000F8D RID: 3981 RVA: 0x0002AA48 File Offset: 0x00028C48
|
||
public override void SetLength(long value)
|
||
{
|
||
throw new NotSupportedException();
|
||
}
|
||
|
||
/// <summary>Writes data to the <see cref="T:System.Net.Sockets.NetworkStream" />.</summary>
|
||
/// <param name="buffer">An array of type <see cref="T:System.Byte" /> that contains the data to write to the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <param name="offset">The location in <paramref name="buffer" /> from which to start writing data. </param>
|
||
/// <param name="size">The number of bytes to write to the <see cref="T:System.Net.Sockets.NetworkStream" />. </param>
|
||
/// <exception cref="T:System.ArgumentNullException">The <paramref name="buffer" /> parameter is null. </exception>
|
||
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="offset" /> parameter is less than 0.-or- The <paramref name="offset" /> parameter is greater than the length of <paramref name="buffer" />.-or- The <paramref name="size" /> parameter is less than 0.-or- The <paramref name="size" /> parameter is greater than the length of <paramref name="buffer" /> minus the value of the <paramref name="offset" /> parameter. </exception>
|
||
/// <exception cref="T:System.IO.IOException">There was a failure while writing to the network. -or-An error occurred when accessing the socket. See the Remarks section for more information.</exception>
|
||
/// <exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.NetworkStream" /> is closed.-or- There was a failure reading from the network. </exception>
|
||
/// <PermissionSet>
|
||
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
|
||
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
||
/// </PermissionSet>
|
||
// Token: 0x06000F8E RID: 3982 RVA: 0x0002AA50 File Offset: 0x00028C50
|
||
public override void Write(byte[] buffer, int offset, int size)
|
||
{
|
||
this.CheckDisposed();
|
||
if (buffer == null)
|
||
{
|
||
throw new ArgumentNullException("buffer");
|
||
}
|
||
if (offset < 0 || offset > buffer.Length)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||
}
|
||
if (size < 0 || size > buffer.Length - offset)
|
||
{
|
||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||
}
|
||
try
|
||
{
|
||
int num = 0;
|
||
while (size - num > 0)
|
||
{
|
||
num += this.socket.Send(buffer, offset + num, size - num, SocketFlags.None);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new IOException("Write failure", ex);
|
||
}
|
||
}
|
||
|
||
// Token: 0x06000F8F RID: 3983 RVA: 0x0002AB08 File Offset: 0x00028D08
|
||
private void CheckDisposed()
|
||
{
|
||
if (this.disposed)
|
||
{
|
||
throw new ObjectDisposedException(base.GetType().FullName);
|
||
}
|
||
}
|
||
|
||
// Token: 0x04000DFD RID: 3581
|
||
private FileAccess access;
|
||
|
||
// Token: 0x04000DFE RID: 3582
|
||
private Socket socket;
|
||
|
||
// Token: 0x04000DFF RID: 3583
|
||
private bool owns_socket;
|
||
|
||
// Token: 0x04000E00 RID: 3584
|
||
private bool readable;
|
||
|
||
// Token: 0x04000E01 RID: 3585
|
||
private bool writeable;
|
||
|
||
// Token: 0x04000E02 RID: 3586
|
||
private bool disposed;
|
||
|
||
// Token: 0x020001DF RID: 479
|
||
public static class Timeout
|
||
{
|
||
// Token: 0x04000E03 RID: 3587
|
||
public static readonly float Infinite = -1f;
|
||
}
|
||
}
|
||
}
|