using System; using System.IO; using System.Runtime.InteropServices; namespace System.Net.Sockets { /// Provides the underlying stream of data for network access. // Token: 0x020001DE RID: 478 public class NetworkStream : Stream, IDisposable { /// Creates a new instance of the class for the specified . /// The that the will use to send and receive data. /// The parameter is null. /// The parameter is not connected.-or- The property of the parameter is not .-or- The parameter is in a nonblocking state. // Token: 0x06000F6E RID: 3950 RVA: 0x0002A508 File Offset: 0x00028708 public NetworkStream(Socket socket) : this(socket, FileAccess.ReadWrite, false) { } /// Initializes a new instance of the class for the specified with the specified ownership. /// The that the will use to send and receive data. /// Set to true to indicate that the will take ownership of the ; otherwise, false. /// The parameter is null. /// The parameter is not connected.-or- the value of the property of the parameter is not .-or- the parameter is in a nonblocking state. // Token: 0x06000F6F RID: 3951 RVA: 0x0002A514 File Offset: 0x00028714 public NetworkStream(Socket socket, bool owns_socket) : this(socket, FileAccess.ReadWrite, owns_socket) { } /// Creates a new instance of the class for the specified with the specified access rights. /// The that the will use to send and receive data. /// A bitwise combination of the values that specify the type of access given to the over the provided . /// The parameter is null. /// The parameter is not connected.-or- the property of the parameter is not .-or- the parameter is in a nonblocking state. // Token: 0x06000F70 RID: 3952 RVA: 0x0002A520 File Offset: 0x00028720 public NetworkStream(Socket socket, FileAccess access) : this(socket, access, false) { } /// Creates a new instance of the class for the specified with the specified access rights and the specified ownership. /// The that the will use to send and receive data. /// A bitwise combination of the values that specifies the type of access given to the over the provided . /// Set to true to indicate that the will take ownership of the ; otherwise, false. /// The parameter is null. /// The parameter is not connected.-or- The property of the parameter is not .-or- The parameter is in a nonblocking state. // 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; } /// Releases all resources used by the . // Token: 0x06000F72 RID: 3954 RVA: 0x0002A5C8 File Offset: 0x000287C8 void IDisposable.Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } /// Gets a value that indicates whether the supports reading. /// true if data can be read from the stream; otherwise, false. The default value is true. // 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; } } /// Gets a value that indicates whether the stream supports seeking. This property is not currently supported.This property always returns false. /// false in all cases to indicate that cannot seek a specific location in the stream. // Token: 0x17000548 RID: 1352 // (get) Token: 0x06000F74 RID: 3956 RVA: 0x0002A5F4 File Offset: 0x000287F4 public override bool CanSeek { get { return false; } } /// Indicates whether timeout properties are usable for . /// true in all cases. // Token: 0x17000549 RID: 1353 // (get) Token: 0x06000F75 RID: 3957 RVA: 0x0002A5F8 File Offset: 0x000287F8 public override bool CanTimeout { get { return true; } } /// Gets a value that indicates whether the supports writing. /// true if data can be written to the ; otherwise, false. The default value is true. // 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; } } /// Gets a value that indicates whether data is available on the to be read. /// true if data is available on the stream to be read; otherwise, false. /// The is closed. /// The underlying is closed. /// Use the 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. /// /// /// /// /// // 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; } } /// Gets the length of the data available on the stream. This property is not currently supported and always throws a . /// The length of the data available on the stream. /// Any use of this property. /// /// /// // Token: 0x1700054C RID: 1356 // (get) Token: 0x06000F78 RID: 3960 RVA: 0x0002A630 File Offset: 0x00028830 public override long Length { get { throw new NotSupportedException(); } } /// Gets or sets the current position in the stream. This property is not currently supported and always throws a . /// The current position in the stream. /// Any use of this property. /// /// /// // 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(); } } /// Gets or sets a value that indicates whether the can be read. /// true to indicate that the can be read; otherwise, false. The default value is true. // 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; } } /// Gets or sets the amount of time that a read operation blocks waiting for data. /// A that specifies the amount of time, in milliseconds, that will elapse before a read operation fails. The default value, , specifies that the read operation does not time out. /// The value specified is less than or equal to zero and is not . /// /// /// /// /// // 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; } } /// Gets the underlying . /// A that represents the underlying network connection. // Token: 0x17000550 RID: 1360 // (get) Token: 0x06000F7F RID: 3967 RVA: 0x0002A6A0 File Offset: 0x000288A0 protected Socket Socket { get { return this.socket; } } /// Gets a value that indicates whether the is writable. /// true if data can be written to the stream; otherwise, false. The default value is true. // 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; } } /// Gets or sets the amount of time that a write operation blocks waiting for data. /// A that specifies the amount of time, in milliseconds, that will elapse before a write operation fails. The default value, , specifies that the write operation does not time out. /// The value specified is less than or equal to zero and is not . /// /// /// /// /// // 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; } } /// Begins an asynchronous read from the . /// An that represents the asynchronous call. /// An array of type that is the location in memory to store data read from the . /// The location in to begin storing the data. /// The number of bytes to read from the . /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// The parameter is null. /// The parameter is less than 0.-or- The parameter is greater than the length of the paramater.-or- The is less than 0.-or- The is greater than the length of minus the value of the parameter. /// The underlying 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. /// The is closed. /// /// /// /// /// // 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; } /// Begins an asynchronous write to a stream. /// An that represents the asynchronous call. /// An array of type that contains the data to write to the . /// The location in to begin sending the data. /// The number of bytes to write to the . /// The delegate that is executed when completes. /// An object that contains any additional user-defined data. /// The parameter is null. /// The parameter is less than 0.-or- The parameter is greater than the length of .-or- The parameter is less than 0.-or- The parameter is greater than the length of minus the value of the parameter. /// The underlying 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. /// The is closed. /// /// /// /// /// // 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; } /// Releases all resources used by the . // Token: 0x06000F86 RID: 3974 RVA: 0x0002A848 File Offset: 0x00028A48 ~NetworkStream() { this.Dispose(false); } /// Releases the unmanaged resources used by the and optionally releases the managed resources. /// true to release both managed and unmanaged resources; false to release only unmanaged resources. // 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; } /// Handles the end of an asynchronous read. /// The number of bytes read from the . /// An that represents an asynchronous call. /// The parameter is null. /// The underlying is closed.-or- An error occurred when accessing the socket. See the Remarks section for more information. /// The is closed. /// /// /// /// /// /// // 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; } /// Handles the end of an asynchronous write. /// The that represents the asynchronous call. /// The parameter is null. /// The underlying 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. /// The is closed. /// /// /// /// /// /// // 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); } } /// Flushes data from the stream. This method is reserved for future use. // Token: 0x06000F8A RID: 3978 RVA: 0x0002A99C File Offset: 0x00028B9C public override void Flush() { } /// Reads data from the . /// The number of bytes read from the . /// An array of type that is the location in memory to store data read from the . /// The location in to begin storing the data to. /// The number of bytes to read from the . /// The parameter is null. /// The parameter is less than 0.-or- The parameter is greater than the length of .-or- The parameter is less than 0.-or- The parameter is greater than the length of minus the value of the parameter. -or-An error occurred when accessing the socket. See the Remarks section for more information. /// The underlying is closed. /// The is closed.-or- There is a failure reading from the network. /// /// /// /// /// /// // 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; } /// Sets the current position of the stream to the given value. This method is not currently supported and always throws a . /// The position in the stream. /// This parameter is not used. /// This parameter is not used. /// Any use of this property. // Token: 0x06000F8C RID: 3980 RVA: 0x0002AA40 File Offset: 0x00028C40 public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); } /// Sets the length of the stream. This method always throws a . /// This parameter is not used. /// Any use of this property. // Token: 0x06000F8D RID: 3981 RVA: 0x0002AA48 File Offset: 0x00028C48 public override void SetLength(long value) { throw new NotSupportedException(); } /// Writes data to the . /// An array of type that contains the data to write to the . /// The location in from which to start writing data. /// The number of bytes to write to the . /// The parameter is null. /// The parameter is less than 0.-or- The parameter is greater than the length of .-or- The parameter is less than 0.-or- The parameter is greater than the length of minus the value of the parameter. /// There was a failure while writing to the network. -or-An error occurred when accessing the socket. See the Remarks section for more information. /// The is closed.-or- There was a failure reading from the network. /// /// /// /// /// /// // 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; } } }