Browse Source

Use submodule

HMBSbige 7 years ago
parent
commit
b332a420e4
30 changed files with 33 additions and 9108 deletions
  1. 3 0
      .gitmodules
  2. 0 32
      NatTypeTester/3rd/Net/AsyncOP_State.cs
  3. 0 38
      NatTypeTester/3rd/Net/EventArgs.cs
  4. 0 28
      NatTypeTester/3rd/Net/IAsyncOP.cs
  5. 0 257
      NatTypeTester/3rd/Net/IO/Base64.cs
  6. 0 517
      NatTypeTester/3rd/Net/IO/Base64Stream.cs
  7. 0 19
      NatTypeTester/3rd/Net/IO/DataSizeExceededException.cs
  8. 0 182
      NatTypeTester/3rd/Net/IO/FifoBuffer.cs
  9. 0 28
      NatTypeTester/3rd/Net/IO/IncompleteDataException.cs
  10. 0 138
      NatTypeTester/3rd/Net/IO/JunkingStream.cs
  11. 0 19
      NatTypeTester/3rd/Net/IO/LineSizeExceededException.cs
  12. 0 296
      NatTypeTester/3rd/Net/IO/MemoryStreamEx.cs
  13. 0 280
      NatTypeTester/3rd/Net/IO/MultiStream.cs
  14. 0 271
      NatTypeTester/3rd/Net/IO/PartialStream.cs
  15. 0 311
      NatTypeTester/3rd/Net/IO/QuotedPrintableStream.cs
  16. 0 189
      NatTypeTester/3rd/Net/IO/ReadWriteControlledStream.cs
  17. 0 23
      NatTypeTester/3rd/Net/IO/SizeExceededAction.cs
  18. 0 4050
      NatTypeTester/3rd/Net/IO/SmartStream.cs
  19. 0 958
      NatTypeTester/3rd/Net/Net_Utils.cs
  20. 0 426
      NatTypeTester/3rd/Net/STUN/Client/STUN_Client.cs
  21. 0 59
      NatTypeTester/3rd/Net/STUN/Client/STUN_NetType.cs
  22. 0 49
      NatTypeTester/3rd/Net/STUN/Client/STUN_Result.cs
  23. 0 706
      NatTypeTester/3rd/Net/STUN/Message/STUN_Message.cs
  24. 0 42
      NatTypeTester/3rd/Net/STUN/Message/STUN_MessageType.cs
  25. 0 59
      NatTypeTester/3rd/Net/STUN/Message/STUN_t_ChangeRequest.cs
  26. 0 52
      NatTypeTester/3rd/Net/STUN/Message/STUN_t_ErrorCode.cs
  27. 0 27
      NatTypeTester/3rd/Net/SslMode.cs
  28. 0 19
      NatTypeTester/3rd/Net/license.txt
  29. 1 0
      NatTypeTester/Lumisoft.Net
  30. 29 33
      NatTypeTester/NatTypeTester.csproj

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "NatTypeTester/Lumisoft.Net"]
+	path = NatTypeTester/Lumisoft.Net
+	url = https://github.com/HMBSbige/Lumisoft.Net

+ 0 - 32
NatTypeTester/3rd/Net/AsyncOP_State.cs

@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net
-{
-    /// <summary>
-    /// Specifies asynchronous operation state.
-    /// </summary>
-    public enum AsyncOP_State
-    {
-        /// <summary>
-        /// Operation waits for start.
-        /// </summary>
-        WaitingForStart,
-
-        /// <summary>
-        /// Operation processing is in progress.
-        /// </summary>
-        Active,
-
-        /// <summary>
-        /// Operations is completed.
-        /// </summary>
-        Completed,
-
-        /// <summary>
-        /// Operation is disposed.
-        /// </summary>
-        Disposed,
-    }
-}

+ 0 - 38
NatTypeTester/3rd/Net/EventArgs.cs

@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net
-{
-    /// <summary>
-    /// This class universal event arguments for transporting single value.
-    /// </summary>
-    /// <typeparam name="T">Event data.</typeparam>
-    public class EventArgs<T> : EventArgs
-    {
-        private T m_pValue;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="value">Event data.</param>
-        public EventArgs(T value)
-        {
-            m_pValue = value;
-        }
-
-
-        #region Properties implementation
-
-        /// <summary>
-        /// Gets event data.
-        /// </summary>
-        public T Value
-        {
-            get{ return m_pValue; }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 28
NatTypeTester/3rd/Net/IAsyncOP.cs

@@ -1,28 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net
-{
-    /// <summary>
-    /// Represents asynchronous operation.
-    /// </summary>
-    public interface IAsyncOP
-    {
-        /// <summary>
-        /// Gets asynchronous operation state.
-        /// </summary>
-        AsyncOP_State State
-        {
-            get;
-        }
-
-        /// <summary>
-        /// Gets error happened during operation. Returns null if no error.
-        /// </summary>
-        Exception Error
-        {
-            get;
-        }
-    }
-}

+ 0 - 257
NatTypeTester/3rd/Net/IO/Base64.cs

@@ -1,257 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This class implements base64 encoder/decoder.  Defined in RFC 4648.
-    /// </summary>
-    public class Base64
-    {
-        #region BASE64_ENCODE_TABLE
-
-        private readonly static byte[] BASE64_ENCODE_TABLE = new byte[]{
-		    (byte)'A',(byte)'B',(byte)'C',(byte)'D',(byte)'E',(byte)'F',(byte)'G',(byte)'H',(byte)'I',(byte)'J',
-            (byte)'K',(byte)'L',(byte)'M',(byte)'N',(byte)'O',(byte)'P',(byte)'Q',(byte)'R',(byte)'S',(byte)'T',
-            (byte)'U',(byte)'V',(byte)'W',(byte)'X',(byte)'Y',(byte)'Z',(byte)'a',(byte)'b',(byte)'c',(byte)'d',
-            (byte)'e',(byte)'f',(byte)'g',(byte)'h',(byte)'i',(byte)'j',(byte)'k',(byte)'l',(byte)'m',(byte)'n',
-            (byte)'o',(byte)'p',(byte)'q',(byte)'r',(byte)'s',(byte)'t',(byte)'u',(byte)'v',(byte)'w',(byte)'x',
-            (byte)'y',(byte)'z',(byte)'0',(byte)'1',(byte)'2',(byte)'3',(byte)'4',(byte)'5',(byte)'6',(byte)'7',
-            (byte)'8',(byte)'9',(byte)'+',(byte)'/'
-		};
-
-        #endregion
-
-        #region BASE64_DECODE_TABLE
-
-        private readonly static short[] BASE64_DECODE_TABLE = new short[]{
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  // 0 -    9
-		    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  //10 -   19
-		    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  //20 -   29
-		    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  //30 -   39
-		    -1,-1,-1,62,-1,-1,-1,63,52,53,  //40 -   49
-		    54,55,56,57,58,59,60,61,-1,-1,  //50 -   59
-		    -1,-1,-1,-1,-1, 0, 1, 2, 3, 4,  //60 -   69
-		    5, 6, 7, 8, 9,10,11,12,13,14,   //70 -   79
-		    15,16,17,18,19,20,21,22,23,24,  //80 -   89
-		    25,-1,-1,-1,-1,-1,-1,26,27,28,  //90 -   99
-		    29,30,31,32,33,34,35,36,37,38,  //100 - 109
-		    39,40,41,42,43,44,45,46,47,48,  //110 - 119
-		    49,50,51,-1,-1,-1,-1,-1         //120 - 127
-        };
-
-        #endregion
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public Base64()
-        {
-        }
-
-
-        #region method Encode
-
-        /// <summary>
-        /// Encodes bytes.
-        /// </summary>
-        /// <param name="buffer">Data buffer.</param>
-        /// <param name="offset">Offset in the buffer.</param>
-        /// <param name="count">Number of bytes available in the buffer.</param>
-        /// <param name="last">Last data block.</param>
-        /// <returns>Returns encoded data.</returns>
-        public byte[] Encode(byte[] buffer,int offset,int count,bool last)
-        {
-            throw new NotImplementedException();
-        }
-
-        #endregion
-
-        #region method Decode
-
-        /// <summary>
-        /// Decodes specified base64 string.
-        /// </summary>
-        /// <param name="value">Base64 string.</param>
-        /// <param name="ignoreNonBase64Chars">If true all invalid base64 chars ignored. If false, FormatException is raised.</param>
-        /// <returns>Returns decoded data.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
-        /// <exception cref="FormatException">Is raised when <b>value</b> contains invalid base64 data.</exception>
-        public byte[] Decode(string value,bool ignoreNonBase64Chars)
-        {
-            if(value == null){
-                throw new ArgumentNullException("value");
-            }
-
-            byte[] encBuffer = Encoding.ASCII.GetBytes(value);
-            byte[] buffer    = new byte[encBuffer.Length];
-
-            int decodedCount = Decode(encBuffer,0,encBuffer.Length,buffer,0,ignoreNonBase64Chars);
-            byte[] retVal = new byte[decodedCount];
-            Array.Copy(buffer,retVal,decodedCount);
-
-            return retVal;
-        }
-
-        /// <summary>
-        /// Decodes specified base64 data.
-        /// </summary>
-        /// <param name="data">Base64 encoded data buffer.</param>
-        /// <param name="offset">Offset in the buffer.</param>
-        /// <param name="count">Number of bytes available in the buffer.</param>
-        /// <param name="ignoreNonBase64Chars">If true all invalid base64 chars ignored. If false, FormatException is raised.</param>
-        /// <returns>Returns decoded data.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
-        /// <exception cref="FormatException">Is raised when <b>value</b> contains invalid base64 data.</exception>
-        public byte[] Decode(byte[] data,int offset,int count,bool ignoreNonBase64Chars)
-        {
-            if(data == null){
-                throw new ArgumentNullException("data");
-            }
-
-            byte[] buffer = new byte[data.Length];
-
-            int decodedCount = Decode(data,offset,count,buffer,0,ignoreNonBase64Chars);
-            byte[] retVal = new byte[decodedCount];
-            Array.Copy(buffer,retVal,decodedCount);
-
-            return retVal;
-        }
-
-        /// <summary>
-        /// Decodes base64 encoded bytes.
-        /// </summary>
-        /// <param name="encBuffer">Base64 encoded data buffer.</param>
-        /// <param name="encOffset">Offset in the encBuffer.</param>
-        /// <param name="encCount">Number of bytes available in the encBuffer.</param>
-        /// <param name="buffer">Buffer where to decode data.</param>
-        /// <param name="offset">Offset int the buffer.</param>
-        /// <param name="ignoreNonBase64Chars">If true all invalid base64 chars ignored. If false, FormatException is raised.</param>
-        /// <returns>Returns number of bytes decoded.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>encBuffer</b> or <b>encBuffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
-        /// <exception cref="FormatException">Is raised when <b>encBuffer</b> contains invalid base64 data.</exception>
-        public int Decode(byte[] encBuffer,int encOffset,int encCount,byte[] buffer,int offset,bool ignoreNonBase64Chars)
-        {
-            if(encBuffer == null){
-                throw new ArgumentNullException("encBuffer");
-            }           
-            if(encOffset < 0){
-                throw new ArgumentOutOfRangeException("encOffset","Argument 'encOffset' value must be >= 0.");
-            }
-            if(encCount < 0){
-                throw new ArgumentOutOfRangeException("encCount","Argument 'encCount' value must be >= 0.");
-            }
-            if(encOffset + encCount > encBuffer.Length){
-                throw new ArgumentOutOfRangeException("encCount","Argument 'count' is bigger than than argument 'encBuffer'.");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0 || offset >= buffer.Length){
-                throw new ArgumentOutOfRangeException("offset");
-            }
-
-            /* RFC 4648.
-			
-				Base64 is processed from left to right by 4 6-bit byte block, 4 6-bit byte block 
-				are converted to 3 8-bit bytes.
-				If base64 4 byte block doesn't have 3 8-bit bytes, missing bytes are marked with =. 
-							
-				Value Encoding  Value Encoding  Value Encoding  Value Encoding
-					0 A            17 R            34 i            51 z
-					1 B            18 S            35 j            52 0
-					2 C            19 T            36 k            53 1
-					3 D            20 U            37 l            54 2
-					4 E            21 V            38 m            55 3
-					5 F            22 W            39 n            56 4
-					6 G            23 X            40 o            57 5
-					7 H            24 Y            41 p            58 6
-					8 I            25 Z            42 q            59 7
-					9 J            26 a            43 r            60 8
-					10 K           27 b            44 s            61 9
-					11 L           28 c            45 t            62 +
-					12 M           29 d            46 u            63 /
-					13 N           30 e            47 v
-					14 O           31 f            48 w         (pad) =
-					15 P           32 g            49 x
-					16 Q           33 h            50 y
-					
-				NOTE: 4 base64 6-bit bytes = 3 8-bit bytes				
-					// |    6-bit    |    6-bit    |    6-bit    |    6-bit    |
-					// | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 |
-					// |    8-bit         |    8-bit        |    8-bit         |
-			*/
-
-            int    decodeOffset  = encOffset;
-            int    decodedOffset = 0;
-            byte[] base64Block   = new byte[4];
-
-            // Decode while we have data.
-            while((decodeOffset - encOffset) < encCount){
-                // Read 4-byte base64 block.
-                int offsetInBlock = 0;
-                while(offsetInBlock < 4){
-                    // Check that we won't exceed buffer data.
-                    if((decodeOffset - encOffset) >= encCount){
-                        if(offsetInBlock == 0){
-                            break;
-                        }
-                        // Incomplete 4-byte base64 data block.
-                        else{
-                            throw new FormatException("Invalid incomplete base64 4-char block");
-                        }
-                    }
-
-                    // Read byte.
-                    short b = encBuffer[decodeOffset++];
-             
-                    // Pad char.
-                    if(b == '='){
-                        // Padding may appear only in last two chars of 4-char block.
-                        // ab==
-                        // abc=
-                        if(offsetInBlock < 2){
-                            throw new FormatException("Invalid base64 padding.");
-                        }
-                                                                        
-                        // Skip next padding char.
-                        if(offsetInBlock == 2){
-                            decodeOffset++;
-                        }
-                        
-                        break;
-                    }
-                    // Non-base64 char.
-                    else if(b > 127 || BASE64_DECODE_TABLE[b] == -1){
-                        if(!ignoreNonBase64Chars){
-                            throw new FormatException("Invalid base64 char '" + b + "'.");
-                        }
-                        // Igonre that char.
-                        //else{
-                    }
-                    // Base64 char.
-                    else{
-                        base64Block[offsetInBlock++] = (byte)BASE64_DECODE_TABLE[b];
-                    }
-                }
-
-                // Decode base64 block.
-                if(offsetInBlock > 1){
-                    buffer[decodedOffset++] = (byte)((base64Block[0] << 2) | (base64Block[1] >> 4));
-                }
-                if(offsetInBlock > 2){
-                    buffer[decodedOffset++] = (byte)(((base64Block[1] & 0xF) << 4) | (base64Block[2] >> 2));
-                }
-                if(offsetInBlock > 3){
-                    buffer[decodedOffset++] = (byte)(((base64Block[2] & 0x3) << 6) | base64Block[3]);
-                }
-            }
-
-            return decodedOffset;
-        }
-
-        #endregion
-    }
-}

+ 0 - 517
NatTypeTester/3rd/Net/IO/Base64Stream.cs

@@ -1,517 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This class implements base64 encoder/decoder. Defined in RFC 4648.
-    /// </summary>
-    public class Base64Stream : Stream,IDisposable
-    {
-        #region BASE64_ENCODE_TABLE
-
-        private readonly static byte[] BASE64_ENCODE_TABLE = new byte[]{
-		    (byte)'A',(byte)'B',(byte)'C',(byte)'D',(byte)'E',(byte)'F',(byte)'G',(byte)'H',(byte)'I',(byte)'J',
-            (byte)'K',(byte)'L',(byte)'M',(byte)'N',(byte)'O',(byte)'P',(byte)'Q',(byte)'R',(byte)'S',(byte)'T',
-            (byte)'U',(byte)'V',(byte)'W',(byte)'X',(byte)'Y',(byte)'Z',(byte)'a',(byte)'b',(byte)'c',(byte)'d',
-            (byte)'e',(byte)'f',(byte)'g',(byte)'h',(byte)'i',(byte)'j',(byte)'k',(byte)'l',(byte)'m',(byte)'n',
-            (byte)'o',(byte)'p',(byte)'q',(byte)'r',(byte)'s',(byte)'t',(byte)'u',(byte)'v',(byte)'w',(byte)'x',
-            (byte)'y',(byte)'z',(byte)'0',(byte)'1',(byte)'2',(byte)'3',(byte)'4',(byte)'5',(byte)'6',(byte)'7',
-            (byte)'8',(byte)'9',(byte)'+',(byte)'/'
-		};
-
-        #endregion
-
-        #region BASE64_DECODE_TABLE
-
-        private readonly static short[] BASE64_DECODE_TABLE = new short[]{
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  // 0 -    9
-		    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  //10 -   19
-		    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  //20 -   29
-		    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,  //30 -   39
-		    -1,-1,-1,62,-1,-1,-1,63,52,53,  //40 -   49
-		    54,55,56,57,58,59,60,61,-1,-1,  //50 -   59
-		    -1,-1,-1,-1,-1, 0, 1, 2, 3, 4,  //60 -   69
-		    5, 6, 7, 8, 9,10,11,12,13,14,   //70 -   79
-		    15,16,17,18,19,20,21,22,23,24,  //80 -   89
-		    25,-1,-1,-1,-1,-1,-1,26,27,28,  //90 -   99
-		    29,30,31,32,33,34,35,36,37,38,  //100 - 109
-		    39,40,41,42,43,44,45,46,47,48,  //110 - 119
-		    49,50,51,-1,-1,-1,-1,-1         //120 - 127
-        };
-
-        #endregion
-
-        private bool        m_IsDisposed             = false;
-        private bool        m_IsFinished             = false;
-        private Stream      m_pStream                = null;
-        private bool        m_IsOwner                = false;
-        private bool        m_AddLineBreaks          = true;
-        private FileAccess  m_AccessMode             = FileAccess.ReadWrite;
-        private int         m_EncodeBufferOffset     = 0;
-        private int         m_OffsetInEncode3x8Block = 0;
-        private byte[]      m_pEncode3x8Block        = new byte[3];
-        private byte[]      m_pEncodeBuffer          = new byte[78];
-        private byte[]      m_pDecodedBlock          = null;
-        private int         m_DecodedBlockOffset     = 0;
-        private int         m_DecodedBlockCount      = 0;
-        private Base64      m_pBase64                = null;
-        private bool        m_IgnoreInvalidPadding   = false;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="stream">Stream which to encode/decode.</param>
-        /// <param name="owner">Specifies if Base64Stream is owner of <b>stream</b>.</param>
-        /// <param name="addLineBreaks">Specifies if encoder inserts CRLF after each 76 bytes.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-        public Base64Stream(Stream stream,bool owner,bool addLineBreaks) : this(stream,owner,addLineBreaks,FileAccess.ReadWrite)
-        {
-        }
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="stream">Stream which to encode/decode.</param>
-        /// <param name="owner">Specifies if Base64Stream is owner of <b>stream</b>.</param>
-        /// <param name="addLineBreaks">Specifies if encoder inserts CRLF after each 76 bytes.</param>
-        /// <param name="access">This stream access mode.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-        public Base64Stream(Stream stream,bool owner,bool addLineBreaks,FileAccess access)
-        {
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            m_pStream       = stream;
-            m_IsOwner       = owner;
-            m_AddLineBreaks = addLineBreaks;
-            m_AccessMode    = access;
-
-            m_pDecodedBlock = new byte[8000];
-            m_pBase64       = new Base64();
-        }
-
-        #region method Dispose
-
-        /// <summary>
-        /// Celans up any resources being used.
-        /// </summary>
-        public new void Dispose()
-        {
-            if(m_IsDisposed){
-                return;
-            }
-            try{
-                Finish();
-            }
-            catch{
-            }
-            m_IsDisposed = true;
-
-            if(m_IsOwner){
-                m_pStream.Close();
-            }
-        }
-
-        #endregion
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("Base64Stream");
-            }
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("Base64Stream");
-            }
-
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="Seek">Is raised when this method is accessed.</exception>
-        public override void SetLength(long value)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("Base64Stream");
-            }
-
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
-        /// <exception cref="NotSupportedException">Is raised when reading not supported.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("Base64Stream");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }           
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(count < 0){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' value must be >= 0.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' is bigger than than argument 'buffer' can store.");
-            }
-            if((m_AccessMode & FileAccess.Read) == 0){
-                throw new NotSupportedException();
-            }
-
-            // We havn't any decoded data left, decode new data block.
-            if((m_DecodedBlockCount - m_DecodedBlockOffset) == 0){
-                byte[] readBuffer = new byte[m_pDecodedBlock.Length + 3];
-                int readedCount = m_pStream.Read(readBuffer,0,readBuffer.Length - 3);
-                // We reached end of stream, no more data.
-                if(readedCount == 0){
-                    return 0;
-                }
-
-                // Decode block must contain only integral 4-byte base64 blocks.
-                // Count base64 chars.
-                int base64Count = 0;
-                for(int i=0;i<readedCount;i++){
-                    byte b = readBuffer[i];
-                    if(b == '=' || BASE64_DECODE_TABLE[b] != -1){
-                        base64Count++;
-                    }
-                }
-                // Read while last block is full 4-byte base64 block.
-                while((base64Count % 4) != 0){
-                    int b = m_pStream.ReadByte();
-                    // End of stream reached.
-                    if(b == -1){
-                        // Add missing padding char(s) '='.
-                        if(m_IgnoreInvalidPadding){
-                            // Per speifiction base64 block must have 2 bytes block + 2 padding bytes.
-                            // Some x soft won't honour it, so add second block with 0-bits.
-                            if((base64Count % 4) == 1){
-                                readBuffer[readedCount++] = (byte)'A';
-                                base64Count++;
-                            }
-                            // Add missing paading char.
-                            else{
-                                readBuffer[readedCount++] = (byte)'=';
-                                base64Count++;
-                            }
-                        }
-                        else{
-                            break;
-                        }
-                    }
-                    else if(b == '=' || BASE64_DECODE_TABLE[b] != -1){
-                        readBuffer[readedCount++] = (byte)b;
-                        base64Count++;
-                    }
-                }
-
-                // Decode block.
-                m_DecodedBlockCount  = m_pBase64.Decode(readBuffer,0,readedCount,m_pDecodedBlock,0,true);
-                m_DecodedBlockOffset = 0;
-            }
-
-            int available   = m_DecodedBlockCount - m_DecodedBlockOffset;
-            int countToCopy = Math.Min(count,available);
-            Array.Copy(m_pDecodedBlock,m_DecodedBlockOffset,buffer,offset,countToCopy);
-            m_DecodedBlockOffset += countToCopy;
-
-            return countToCopy;
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Encodes a sequence of bytes, writes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="InvalidOperationException">Is raised when this.Finish has been called and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="NotSupportedException">Is raised when reading not supported.</exception>
-        public override void Write(byte[] buffer,int offset,int count)        
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(m_IsFinished){
-                throw new InvalidOperationException("Stream is marked as finished by calling Finish method.");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0 || offset > buffer.Length){
-                throw new ArgumentException("Invalid argument 'offset' value.");
-            }
-            if(count < 0 || count > (buffer.Length - offset)){
-                throw new ArgumentException("Invalid argument 'count' value.");
-            } 
-            if((m_AccessMode & FileAccess.Write) == 0){
-                throw new NotSupportedException();
-            }           
-
-            /* RFC 4648.
-			
-				Base64 is processed from left to right by 4 6-bit byte block, 4 6-bit byte block 
-				are converted to 3 8-bit bytes.
-				If base64 4 byte block doesn't have 3 8-bit bytes, missing bytes are marked with =. 
-							
-				Value Encoding  Value Encoding  Value Encoding  Value Encoding
-					0 A            17 R            34 i            51 z
-					1 B            18 S            35 j            52 0
-					2 C            19 T            36 k            53 1
-					3 D            20 U            37 l            54 2
-					4 E            21 V            38 m            55 3
-					5 F            22 W            39 n            56 4
-					6 G            23 X            40 o            57 5
-					7 H            24 Y            41 p            58 6
-					8 I            25 Z            42 q            59 7
-					9 J            26 a            43 r            60 8
-					10 K           27 b            44 s            61 9
-					11 L           28 c            45 t            62 +
-					12 M           29 d            46 u            63 /
-					13 N           30 e            47 v
-					14 O           31 f            48 w         (pad) =
-					15 P           32 g            49 x
-					16 Q           33 h            50 y
-					
-				NOTE: 4 base64 6-bit bytes = 3 8-bit bytes				
-					// |    6-bit    |    6-bit    |    6-bit    |    6-bit    |
-					// | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 |
-					// |    8-bit         |    8-bit        |    8-bit         |
-			*/
-
-            int encodeBufSize = m_pEncodeBuffer.Length;
-
-            // Process all bytes.
-            for(int i=0;i<count;i++){
-                m_pEncode3x8Block[m_OffsetInEncode3x8Block++] = buffer[offset + i];
-
-                // 3x8-bit encode block is full, encode it.
-                if(m_OffsetInEncode3x8Block == 3){
-                    m_pEncodeBuffer[m_EncodeBufferOffset++] = BASE64_ENCODE_TABLE[ m_pEncode3x8Block[0] >> 2];
-                    m_pEncodeBuffer[m_EncodeBufferOffset++] = BASE64_ENCODE_TABLE[(m_pEncode3x8Block[0] & 0x03) << 4 | m_pEncode3x8Block[1] >> 4];
-                    m_pEncodeBuffer[m_EncodeBufferOffset++] = BASE64_ENCODE_TABLE[(m_pEncode3x8Block[1] & 0x0F) << 2 | m_pEncode3x8Block[2] >> 6];
-                    m_pEncodeBuffer[m_EncodeBufferOffset++] = BASE64_ENCODE_TABLE[(m_pEncode3x8Block[2] & 0x3F)];
-                    
-                    // Encode buffer is full, write buffer to underlaying stream (we reserved 2 bytes for CRLF).
-                    if(m_EncodeBufferOffset >= (encodeBufSize - 2)){
-                        if(m_AddLineBreaks){
-                            m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)'\r';
-                            m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)'\n';
-                        }
-
-                        m_pStream.Write(m_pEncodeBuffer,0,m_EncodeBufferOffset);
-                        m_EncodeBufferOffset = 0;
-                    }
-
-                    m_OffsetInEncode3x8Block = 0;
-                }
-            }
-        }
-
-        #endregion
-
-
-        #region method Finish
-
-        /// <summary>
-        /// Completes encoding. Call this method if all data has written and no more data. 
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public void Finish()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(m_IsFinished){
-                return;
-            }
-            m_IsFinished = true;
-            
-            // PADD left-over, if any. Write encode buffer to underlaying stream.
-            if(m_OffsetInEncode3x8Block == 1){
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)BASE64_ENCODE_TABLE[m_pEncode3x8Block[0] >> 2];
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)BASE64_ENCODE_TABLE[(m_pEncode3x8Block[0] & 0x03) << 4];
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)'=';
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)'=';
-            }
-            else if(m_OffsetInEncode3x8Block == 2){
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)BASE64_ENCODE_TABLE[ m_pEncode3x8Block[0] >> 2];
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)BASE64_ENCODE_TABLE[(m_pEncode3x8Block[0] & 0x03) << 4 | m_pEncode3x8Block[1] >> 4];
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)BASE64_ENCODE_TABLE[(m_pEncode3x8Block[1] & 0x0F) << 2];
-                m_pEncodeBuffer[m_EncodeBufferOffset++] = (byte)'=';
-            }
-
-            if(m_EncodeBufferOffset > 0){
-                m_pStream.Write(m_pEncodeBuffer,0,m_EncodeBufferOffset);
-            }
-        }
-
-        #endregion
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets if this object is disposed.
-        /// </summary>
-        public bool IsDisposed
-        {
-            get{ return m_IsDisposed; }
-        }
-
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return false;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return false;
-            } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.  This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this property is accessed.</exception>
-        public override long Length
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                throw new NotSupportedException();
-            } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this property is accessed.</exception>
-        public override long Position
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                throw new NotSupportedException();
-            } 
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                throw new NotSupportedException();
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets if invalid(missing '=' chars) base64 last block padding allowed.
-        /// </summary>
-        public bool IgnoreInvalidPadding
-        {
-            get{ return m_IgnoreInvalidPadding; }
-
-            set{ m_IgnoreInvalidPadding = value; }
-        }
-
-        #endregion
-  
-    }
-}

+ 0 - 19
NatTypeTester/3rd/Net/IO/DataSizeExceededException.cs

@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// The exception that is thrown when maximum allowed data size has exceeded.
-    /// </summary>
-    public class DataSizeExceededException : Exception
-    {
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public DataSizeExceededException() : base()
-        {
-        }
-    }
-}

+ 0 - 182
NatTypeTester/3rd/Net/IO/FifoBuffer.cs

@@ -1,182 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// Implements FIFO(first in - first out) buffer.
-    /// </summary>
-    public class FifoBuffer
-    {
-        private object m_pLock       = new object();
-        private byte[] m_pBuffer     = null;
-        private int    m_ReadOffset  = 0;
-        private int    m_WriteOffset = 0;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="maxSize">Maximum number of bytes can buffer in FIFO.</param>
-        /// <exception cref="ArgumentException">Is raised when </exception>
-        public FifoBuffer(int maxSize)
-        {
-            if(maxSize < 1){
-                throw new ArgumentException("Argument 'maxSize' value must be >= 1.");
-            }
-
-            m_pBuffer = new byte[maxSize];
-        }
-
-
-        #region method Read
-
-        /// <summary>
-        /// Reads up to specified count of bytes from the FIFO buffer.
-        /// </summary>
-        /// <param name="buffer">Buffer where to store data.</param>
-        /// <param name="offset">Index in the buffer.</param>
-        /// <param name="count">Maximum number of bytes to read.</param>
-        /// <returns>Returns number of bytes readed. Returns 0 if no data in the buffer.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of allowed range.</exception>
-        public int Read(byte[] buffer,int offset,int count)
-        {
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }           
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(count < 0){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' value must be >= 0.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' is bigger than than argument 'buffer' can store.");
-            }
-
-            lock(m_pLock){
-                int countToRead = Math.Min(count,m_WriteOffset - m_ReadOffset);
-                if(countToRead > 0){
-                    Array.Copy(m_pBuffer,m_ReadOffset,buffer,offset,countToRead);
-                    m_ReadOffset += countToRead;
-                }
-
-                return countToRead;
-            }
-        }
-
-        #endregion
-
-        #region method Write
-
-        /// <summary>
-        /// Writes specified number of bytes to the FIFO buffer.
-        /// </summary>
-        /// <param name="buffer">Data buffer.</param>
-        /// <param name="offset">Index in the buffer.</param>
-        /// <param name="count">Number of bytes to wrtite.</param>
-        /// <param name="ignoreBufferFull">If true, disables excption raising when FIFO full.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of allowed range.</exception>
-        /// <exception cref="DataSizeExceededException">Is raised when ignoreBufferFull = false and FIFO buffer has no room to store data.</exception>
-        public void Write(byte[] buffer,int offset,int count,bool ignoreBufferFull)
-        {
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }        
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(count < 0 || (count + offset) > buffer.Length){
-                throw new ArgumentOutOfRangeException("count");
-            }
-
-            lock(m_pLock){
-                int freeSpace = m_pBuffer.Length - m_WriteOffset;
-
-                // We don't have enough room to store data.
-                if(freeSpace < count){
-                    TrimStart();
-
-                    // Recalculate free space.
-                    freeSpace = m_pBuffer.Length - m_WriteOffset;
-
-                    // After trim we can store data.
-                    if(freeSpace >= count){
-                        Array.Copy(buffer,offset,m_pBuffer,m_WriteOffset,count);
-                        m_WriteOffset += count;
-                    }
-                    // We have not enough space.
-                    else{
-                        if(!ignoreBufferFull){
-                            throw new DataSizeExceededException();
-                        }
-                    }
-                }
-                // Store data to buffer.
-                else{
-                    Array.Copy(buffer,offset,m_pBuffer,m_WriteOffset,count);
-                    m_WriteOffset += count;
-                }
-            }
-        }
-
-        #endregion
-
-        #region method Clear
-
-        /// <summary>
-        /// Clears buffer data.
-        /// </summary>
-        public void Clear()
-        {
-            lock(m_pLock){
-                m_ReadOffset  = 0;
-                m_WriteOffset = 0;
-            }
-        }
-
-        #endregion
-
-
-        #region method TrimStart
-
-        /// <summary>
-        /// Removes unused space from the buffer beginning.
-        /// </summary>
-        private void TrimStart()
-        {            
-            if(m_ReadOffset > 0){
-                byte[] buffer = new byte[this.Available];
-                Array.Copy(m_pBuffer,m_ReadOffset,buffer,0,buffer.Length);
-                Array.Copy(buffer,m_pBuffer,buffer.Length);
-                m_ReadOffset  = 0;
-                m_WriteOffset = buffer.Length;
-            }
-        }
-
-        #endregion
-
-
-        #region Properties implementation
-
-        /// <summary>
-        /// Gets maximum number of bytes can buffer in FIFO.
-        /// </summary>
-        public int MaxSize
-        {
-            get{ return m_pBuffer.Length; }
-        }
-
-        /// <summary>
-        /// Gets number of bytes avialable in FIFO.
-        /// </summary>
-        public int Available
-        {
-            get{ return m_WriteOffset - m_ReadOffset; }
-        }
-
-        #endregion
-    }
-}

+ 0 - 28
NatTypeTester/3rd/Net/IO/IncompleteDataException.cs

@@ -1,28 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// The exception that is thrown when incomplete data received.
-    /// For example for ReadPeriodTerminated() method reaches end of stream before getting period terminator.
-    /// </summary>
-    public class IncompleteDataException : Exception
-    {
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public IncompleteDataException() : base()
-        {
-        }
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="message">Exception message text.</param>
-        public IncompleteDataException(string message) : base(message)
-        {
-        }
-    }
-}

+ 0 - 138
NatTypeTester/3rd/Net/IO/JunkingStream.cs

@@ -1,138 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This stream just junks all written data.
-    /// </summary>
-    public class JunkingStream : Stream
-    {
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public JunkingStream()
-        {
-        }
-
-
-        #region method Flush
-
-        /// <summary>
-        /// Not used.
-        /// </summary>
-        public override void Flush()
-        {
-        }
-
-        #endregion
-
-        #region method Seek
-
-        /// <summary>
-        /// Sets the current position of the stream to the given value. This method always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="offset">This parameter is not used.</param>
-        /// <param name="origin">This parameter is not used.</param>
-        /// <returns></returns>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region method SetLength
-
-        /// <summary>
-        /// Sets the length of the stream. This method always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">This parameter is not used.</param>
-        public override void SetLength(long value)
-        {
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region method Read
-
-        /// <summary>
-        /// Reads data from the stream. This method always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="buffer">This parameter is not used.</param>
-        /// <param name="offset">This parameter is not used.</param>
-        /// <param name="size">This parameter is not used.</param>
-        /// <returns></returns>
-        public override int Read([In,Out] byte[] buffer,int offset,int size)
-        {
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region method Write
-
-        /// <summary>
-        /// Writes data to the stream.
-        /// </summary>
-        /// <param name="buffer">An array of type Byte that contains the data to write to the stream.</param>
-        /// <param name="offset">The location in buffer from which to start writing data.</param>
-        /// <param name="size">The number of bytes to write to the stream.</param>
-        public override void Write(byte[] buffer,int offset,int size)
-        {
-        }
-
-        #endregion
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets a value indicating whether the stream supports reading. This property always returns false.
-        /// </summary>
-        public override bool CanRead
-        {
-            get{ return false; }
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the stream supports seeking. This property always returns false.
-        /// </summary>
-        public override bool CanSeek
-        {
-            get{ return false; }
-        }
-
-        /// <summary>
-        /// Gets a value that indicates whether the stream supports writing.
-        /// </summary>
-        public override bool CanWrite
-        {
-            get{ return true; }
-        }
-
-        /// <summary>
-        /// Gets the length of the data available on the stream. This property always throws a NotSupportedException.
-        /// </summary>
-        public override long Length
-        {
-            get{ throw new NotSupportedException(); }
-        }
-
-        /// <summary>
-        /// Gets or sets the current position in the stream. This property always throws a NotSupportedException.
-        /// </summary>
-        public override long Position
-        {
-            get{ throw new NotSupportedException(); }
-
-            set{ throw new NotSupportedException(); }
-        }
-
-        #endregion
-    }
-}

+ 0 - 19
NatTypeTester/3rd/Net/IO/LineSizeExceededException.cs

@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// The exception that is thrown when maximum allowed line size has exceeded.
-    /// </summary>
-    public class LineSizeExceededException : Exception
-    {
-        /// <summary>
-        /// Default coonstructor.
-        /// </summary>
-        public LineSizeExceededException() : base()
-        {
-        }
-    }
-}

+ 0 - 296
NatTypeTester/3rd/Net/IO/MemoryStreamEx.cs

@@ -1,296 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This class represents auto switching memory/temp-file stream.
-    /// </summary>
-    public class MemoryStreamEx : Stream
-    {
-        private static int m_DefaultMemorySize = 64000;
-
-        private bool   m_IsDisposed = false;
-        private Stream m_pStream    = null;
-        private int    m_MaxMemSize = 64000;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public MemoryStreamEx() : this(m_DefaultMemorySize)
-        {
-        }
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="memSize">Maximum bytes store to memory, before switching over temporary file.</param>
-        public MemoryStreamEx(int memSize)
-        {
-            m_MaxMemSize = memSize;
-
-            m_pStream = new MemoryStream();
-        }
-
-        /// <summary>
-        /// Destructor - Just incase user won't call dispose.
-        /// </summary>
-        ~MemoryStreamEx()
-        {
-            Dispose();
-        }
-
-        #region method Dispose
-
-        /// <summary>
-        /// Cleans up any resources being used.
-        /// </summary>
-        public new void Dispose()
-        {
-            if(m_IsDisposed){
-                return;
-            }
-
-            m_IsDisposed = true;
-            if(m_pStream != null){
-                m_pStream.Close();
-            }
-            m_pStream = null;
-
-            base.Dispose();
-        }
-
-        #endregion
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            m_pStream.Flush();
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            return m_pStream.Seek(offset,origin);
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override void SetLength(long value)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            m_pStream.SetLength(value);
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            
-            return m_pStream.Read(buffer,offset,count);
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        public override void Write(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-
-            // We need switch to temporary file.
-            if(m_pStream is MemoryStream && (m_pStream.Position + count) > m_MaxMemSize){
-                FileStream fs = new FileStream(Path.GetTempPath() + "ls-" + Guid.NewGuid().ToString().Replace("-","") + ".tmp",FileMode.Create,FileAccess.ReadWrite,FileShare.Read,32000,FileOptions.DeleteOnClose);
-
-                m_pStream.Position = 0;
-                Net_Utils.StreamCopy(m_pStream,fs,8000);
-                m_pStream.Close();
-                m_pStream = fs;
-            }
- 
-            m_pStream.Write(buffer,offset,count);
-        }
-
-        #endregion
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets or sets default memory size in bytes, before switching to temp file.
-        /// </summary>
-        public static int DefaultMemorySize
-        {
-            get{
-                return m_DefaultMemorySize;
-            }
-
-            set{
-                if(value < 32000){
-                    throw new ArgumentException("Property 'DefaultMemorySize' value must be >= 32k.","value");
-                }
-
-                m_DefaultMemorySize = value;
-            }
-        }
-
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="Seek">Is raised when this property is accessed.</exception>
-        public override long Length
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.Length;
-            } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override long Position
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.Position;
-            } 
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-                if(value < 0 || value > this.Length){
-                    throw new ArgumentException("Property 'Position' value must be >= 0 and <= this.Length.");
-                }
-
-                m_pStream.Position = value;
-            }
-        }
-
-        #endregion
-    }
-}

+ 0 - 280
NatTypeTester/3rd/Net/IO/MultiStream.cs

@@ -1,280 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This class combines multiple stream into one stream for reading.
-    /// The most common usage for that stream is when you need to insert some data to the beginning of some stream.
-    /// </summary>
-    public class MultiStream : Stream
-    {
-        private bool          m_IsDisposed = false;
-        private Queue<Stream> m_pStreams   = null;        
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public MultiStream()
-        {
-            m_pStreams = new Queue<Stream>();
-        }
-
-        #region method Dispose
-
-        /// <summary>
-        /// Cleans up any resources being used.
-        /// </summary>
-        public new void Dispose()
-        {
-            if(m_IsDisposed){
-                return;
-            }
-
-            m_IsDisposed = true;
-            m_pStreams = null;
-
-            base.Dispose();
-        }
-
-        #endregion
-
-
-        #region method AppendStream
-
-        /// <summary>
-        /// Appends this stream to read queue.
-        /// </summary>
-        /// <param name="stream">Stream to add.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        public void AppendStream(Stream stream)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            m_pStreams.Enqueue(stream);
-        }
-
-        #endregion
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="Seek">Is raised when this method is accessed.</exception>
-        public override void SetLength(long value)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            while(true){
-                // We have readed all streams data, no data left.
-                if(m_pStreams.Count == 0){
-                    return 0;
-                }
-                else{
-                    int readedCount = m_pStreams.Peek().Read(buffer,offset,count);
-                    // We have readed all current stream data.
-                    if(readedCount == 0){
-                        // Move to next stream .
-                        m_pStreams.Dequeue();
-
-                        // Next while loop will process "read".
-                    }
-                    else{
-                        return readedCount;
-                    }
-                }
-            }
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override void Write(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
- 
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return false;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return false;
-            } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when one of the source streams won't support <b>Length</b> property.</exception>
-        public override long Length
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                long length = 0;
-                foreach(Stream stream in m_pStreams.ToArray()){
-                    length += stream.Length;
-                }
-
-                return length;
-            } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this property is accessed.</exception>
-        public override long Position
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                throw new NotSupportedException();
-            } 
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                throw new NotSupportedException();
-            }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 271
NatTypeTester/3rd/Net/IO/PartialStream.cs

@@ -1,271 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// Implements read-only stream what operates on specified range of source stream
-    /// </summary>
-    public class PartialStream : Stream
-    {
-        private bool   m_IsDisposed = false;
-        private Stream m_pStream    = null;
-        private long   m_Start      = 0;
-        private long   m_Length     = 0;
-        private long   m_Position   = 0;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="stream">Source stream.</param>
-        /// <param name="start">Zero based start positon in source stream.</param>
-        /// <param name="length">Length of stream.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        public PartialStream(Stream stream,long start,long length)
-        {
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-            if(!stream.CanSeek){
-                throw new ArgumentException("Argument 'stream' does not support seeking.");
-            }
-            if(start < 0){
-                throw new ArgumentException("Argument 'start' value must be >= 0.");
-            }
-            if((start + length) > stream.Length){
-                throw new ArgumentException("Argument 'length' value will exceed source stream length.");
-            }
-
-            m_pStream = stream;
-            m_Start   = start;
-            m_Length  = length;
-        }
-
-        #region method Dispose
-
-        /// <summary>
-        /// Cleans up any resources being used.
-        /// </summary>
-        public new void Dispose()
-        {
-            if(m_IsDisposed){
-                return;
-            }
-
-            m_IsDisposed = true;
-
-            base.Dispose();
-        }
-
-        #endregion
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            if(origin == SeekOrigin.Begin){
-                m_Position = 0;
-            }
-            else if(origin == SeekOrigin.Current){
-            }
-            else if(origin == SeekOrigin.End){
-                m_Position = m_Length;
-            } 
-
-            return m_Position;
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override void SetLength(long value)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-            
-            if(m_pStream.Position != (m_Start + m_Position)){
-                m_pStream.Position = m_Start + m_Position;
-            }
-            int readedCount = m_pStream.Read(buffer,offset,Math.Min(count,(int)(this.Length - m_Position)));
-            m_Position += readedCount;
-
-            return readedCount;
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override void Write(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
- 
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return true;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return false;
-            } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="Seek">Is raised when this property is accessed.</exception>
-        public override long Length
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_Length;
-            } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override long Position
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_Position;
-            } 
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-                if(value < 0 || value > this.Length){
-                    throw new ArgumentException("Property 'Position' value must be >= 0 and <= this.Length.");
-                }
-
-                m_Position = value;
-            }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 311
NatTypeTester/3rd/Net/IO/QuotedPrintableStream.cs

@@ -1,311 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// Implements RFC 2045 6.7. Quoted-Printable stream.
-    /// </summary>
-    public class QuotedPrintableStream : Stream
-    {
-        private SmartStream m_pStream        = null;
-        private FileAccess  m_AccessMode     = FileAccess.ReadWrite;
-        private byte[]      m_pDecodedBuffer = null;
-        private int         m_DecodedOffset  = 0;
-        private int         m_DecodedCount   = 0;
-        private byte[]      m_pEncodedBuffer = null;
-        private int         m_EncodedCount   = 0;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="stream">Source stream.</param>
-        /// <param name="access">Specifies stream access mode.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-        public QuotedPrintableStream(SmartStream stream,FileAccess access)
-        {
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            m_pStream    = stream;
-            m_AccessMode = access;
-
-            m_pDecodedBuffer = new byte[32000];
-            m_pEncodedBuffer = new byte[78];
-        }
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            if(m_EncodedCount > 0){
-                m_pStream.Write(m_pEncodedBuffer,0,m_EncodedCount);
-                m_EncodedCount = 0;
-            }
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this method is accessed.</exception>
-        public override void SetLength(long value)
-        {
-            throw new NotSupportedException();
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="NotSupportedException">Is raised when reading not supported.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0 || offset > buffer.Length){
-                throw new ArgumentException("Invalid argument 'offset' value.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentException("Invalid argument 'count' value.");
-            }
-            if((m_AccessMode & FileAccess.Read) == 0){
-                throw new NotSupportedException();
-            }
-
-            while(true){
-                // Read next quoted-printable line and decode it.
-                if(m_DecodedOffset >= m_DecodedCount){
-                    m_DecodedOffset = 0;
-                    m_DecodedCount  = 0;
-                    SmartStream.ReadLineAsyncOP readLineOP = new SmartStream.ReadLineAsyncOP(new byte[32000],SizeExceededAction.ThrowException);
-                    m_pStream.ReadLine(readLineOP,false);
-                    // IO error reading line.
-                    if(readLineOP.Error != null){
-                        throw readLineOP.Error;
-                    }
-                    // We reached end of stream.
-                    else if(readLineOP.BytesInBuffer == 0){
-                        return 0;
-                    }
-                    // Decode quoted-printable line.
-                    else{
-                        // Process bytes.
-                        bool softLineBreak = false;
-                        int lineLength     = readLineOP.LineBytesInBuffer;
-                        for(int i=0;i<readLineOP.LineBytesInBuffer;i++){
-                            byte b = readLineOP.Buffer[i];
-                            // We have soft line-break.
-                            if(b == '=' && i == (lineLength - 1)){
-                                softLineBreak = true;
-                            }
-                            // We should have =XX hex-byte.
-                            else if(b == '='){
-                                byte b1 = readLineOP.Buffer[++i];
-                                byte b2 = readLineOP.Buffer[++i];
-                        
-                                byte b3 = 0;
-                                if(byte.TryParse(new string(new char[]{(char)b1,(char)b2}),System.Globalization.NumberStyles.HexNumber,null,out b3)){
-                                    m_pDecodedBuffer[m_DecodedCount++] = b3;
-                                }
-                                // Not hex number, leave it as it is.
-                                else{
-                                    m_pDecodedBuffer[m_DecodedCount++] = (byte)'=';
-                                    m_pDecodedBuffer[m_DecodedCount++] = b1;
-                                    m_pDecodedBuffer[m_DecodedCount++] = b2;
-                                }
-                            }
-                            // Normal char.
-                            else{
-                                m_pDecodedBuffer[m_DecodedCount++] = b;
-                            }
-                        }
-
-                        // Add hard line break only if there was one in original data.
-                        if(readLineOP.LineBytesInBuffer != readLineOP.BytesInBuffer && !softLineBreak){
-                            m_pDecodedBuffer[m_DecodedCount++] = (byte)'\r';
-                            m_pDecodedBuffer[m_DecodedCount++] = (byte)'\n';
-                        }
-                    }
-                }
-
-                // We have some decoded data, return it.
-                if(m_DecodedOffset < m_DecodedCount){
-                    int countToCopy = Math.Min(count,m_DecodedCount - m_DecodedOffset);
-                    Array.Copy(m_pDecodedBuffer,m_DecodedOffset,buffer,offset,countToCopy);
-                    m_DecodedOffset += countToCopy;
-
-                    return countToCopy;
-                }
-            }
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Encodes a sequence of bytes, writes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="NotSupportedException">Is raised when reading not supported.</exception>
-        public override void Write(byte[] buffer,int offset,int count)
-        {
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0 || offset > buffer.Length){
-                throw new ArgumentException("Invalid argument 'offset' value.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentException("Invalid argument 'count' value.");
-            }
-            if((m_AccessMode & FileAccess.Write) == 0){
-                throw new NotSupportedException();
-            }
-
-            // Process bytes.
-            for(int i=0;i<count;i++){
-                byte b = buffer[offset + i];
-
-                // We don't need to encode byte.
-                if((b >= 33 && b <= 60) || (b >= 62 && b <= 126)){
-                    // Maximum allowed quoted-printable line length reached, do soft line break.
-                    if(m_EncodedCount >= 75){
-                        m_pEncodedBuffer[m_EncodedCount++] = (byte)'=';
-                        m_pEncodedBuffer[m_EncodedCount++] = (byte)'\r';
-                        m_pEncodedBuffer[m_EncodedCount++] = (byte)'\n';
-
-                        // Write encoded data to underlying stream.
-                        Flush();
-                    }
-
-                    m_pEncodedBuffer[m_EncodedCount++] = b;
-                }
-                // We need to encode byte.
-                else{
-                    // Maximum allowed quote-printable line length reached, do soft line break.
-                    if(m_EncodedCount >= 73){
-                        m_pEncodedBuffer[m_EncodedCount++] = (byte)'=';
-                        m_pEncodedBuffer[m_EncodedCount++] = (byte)'\r';
-                        m_pEncodedBuffer[m_EncodedCount++] = (byte)'\n';
-
-                        // Write encoded data to underlying stream.
-                        Flush();
-                    }
-
-                    // Encode byte.
-                    m_pEncodedBuffer[m_EncodedCount++] = (byte)'=';
-                    m_pEncodedBuffer[m_EncodedCount++] = (byte)(b >> 4).ToString("X")[0];
-                    m_pEncodedBuffer[m_EncodedCount++] = (byte)(b & 0xF).ToString("X")[0];
-                }                
-            }
-        }
-
-        #endregion
-
-
-        #region Properties implementation
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{ return (m_AccessMode & FileAccess.Read) != 0; } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{ return false; } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{ return (m_AccessMode & FileAccess.Write) != 0; } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.  This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this property is accessed.</exception>
-        public override long Length
-        { 
-            get{
-                throw new NotSupportedException();
-            } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="NotSupportedException">Is raised when this property is accessed.</exception>
-        public override long Position
-        { 
-            get{
-                throw new NotSupportedException();
-            } 
-
-            set{
-                throw new NotSupportedException();
-            }
-        }
-
-        #endregion
-    }
-}

+ 0 - 189
NatTypeTester/3rd/Net/IO/ReadWriteControlledStream.cs

@@ -1,189 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This class implements read,write or read-write access stream.
-    /// </summary>
-    public class ReadWriteControlledStream : Stream
-    {
-        private Stream     m_pStream    = null;
-        private FileAccess m_AccessMode = FileAccess.ReadWrite;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="stream">Source stream.</param>
-        /// <param name="access">This stream access mode.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-        public ReadWriteControlledStream(Stream stream,FileAccess access)
-        {
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            m_pStream    = stream;
-            m_AccessMode = access;
-        }
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            m_pStream.Flush();
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            return m_pStream.Seek(offset,origin);
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        public override void SetLength(long value)
-        {
-            m_pStream.SetLength(value);
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="NotSupportedException">Is raised when reading not supported.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0 || offset > buffer.Length){
-                throw new ArgumentException("Invalid argument 'offset' value.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentException("Invalid argument 'count' value.");
-            }
-            if((m_AccessMode & FileAccess.Read) == 0){
-                throw new NotSupportedException();
-            }
-
-            return m_pStream.Read(buffer,offset,count);
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="NotSupportedException">Is raised when reading not supported.</exception>
-        public override void Write(byte[] buffer,int offset,int count)
-        {
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0 || offset > buffer.Length){
-                throw new ArgumentException("Invalid argument 'offset' value.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentException("Invalid argument 'count' value.");
-            }
-            if((m_AccessMode & FileAccess.Write) == 0){
-                throw new NotSupportedException();
-            }
-
-            m_pStream.Write(buffer,offset,count);
-        }
-
-        #endregion
-
-
-        #region Properties implementation
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{ return (m_AccessMode & FileAccess.Read) != 0; } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{ return m_pStream.CanSeek; } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{ return (m_AccessMode & FileAccess.Write) != 0; } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.  This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override long Length
-        { 
-            get{ return m_pStream.Length; } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream. This method is not supported and always throws a NotSupportedException.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override long Position
-        { 
-            get{ return m_pStream.Position; } 
-
-            set{ m_pStream.Position = value; }
-        }
-
-        #endregion
-    }
-}

+ 0 - 23
NatTypeTester/3rd/Net/IO/SizeExceededAction.cs

@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// Specifies action what is done if requested action exceeds maximum allowed size.
-    /// </summary>
-    public enum SizeExceededAction
-    {
-        /// <summary>
-        /// Throws exception at once when maximum size exceeded.
-        /// </summary>
-        ThrowException = 1,
-
-        /// <summary>
-        /// Junks all data what exceeds maximum allowed size and after requested operation completes,
-        /// throws exception.
-        /// </summary>
-        JunkAndThrowException = 2,
-    }
-}

+ 0 - 4050
NatTypeTester/3rd/Net/IO/SmartStream.cs

@@ -1,4050 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-
-using LumiSoft.Net.Log;
-
-namespace LumiSoft.Net.IO
-{
-    /// <summary>
-    /// This class is wrapper to normal stream, provides most needed stream methods which are missing from normal stream.
-    /// </summary>
-    public class SmartStream : Stream
-    { 
-        private delegate void BufferCallback(Exception x);
-
-        #region class ReadAsyncOperation
-
-        /// <summary>
-        /// This class implements asynchronous data reader.
-        /// </summary>
-        private class ReadAsyncOperation : IAsyncResult
-        {
-            private SmartStream        m_pOwner                 = null;
-            private byte[]             m_pBuffer                = null;
-            private int                m_OffsetInBuffer         = 0;
-            private int                m_MaxSize                = 0;
-            private AsyncCallback      m_pAsyncCallback         = null;
-            private object             m_pAsyncState            = null;
-            private AutoResetEvent     m_pAsyncWaitHandle       = null;
-            private bool               m_CompletedSynchronously = false;
-            private bool               m_IsCompleted            = false;
-            private bool               m_IsEndCalled            = false;
-            private int                m_BytesStored            = 0;
-            private Exception          m_pException             = null;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="owner">Owner stream.</param>
-            /// <param name="buffer">Buffer where to store data.</param>
-            /// <param name="offset">The location in <b>buffer</b> to begin storing the data.</param>
-            /// <param name="maxSize">Maximum number of bytes to read.</param>
-            /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-            /// <param name="asyncState">User-defined object that qualifies or contains information about an asynchronous operation.</param>
-            public ReadAsyncOperation(SmartStream owner,byte[] buffer,int offset,int maxSize,AsyncCallback callback,object asyncState)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-                if(buffer == null){
-                    throw new ArgumentNullException("buffer");
-                }
-                if(offset < 0){
-                    throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-                }
-                if(offset > buffer.Length){
-                    throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be < buffer.Length.");
-                }
-                if(maxSize < 0){
-                    throw new ArgumentOutOfRangeException("maxSize","Argument 'maxSize' value must be >= 0.");
-                }
-                if(offset + maxSize > buffer.Length){
-                    throw new ArgumentOutOfRangeException("maxSize","Argument 'maxSize' is bigger than than argument 'buffer' can store.");
-                }
-
-                m_pOwner             = owner;
-                m_pBuffer            = buffer;
-                m_OffsetInBuffer     = offset;
-                m_MaxSize            = maxSize;
-                m_pAsyncCallback     = callback;
-                m_pAsyncState        = asyncState;
-
-                m_pAsyncWaitHandle = new AutoResetEvent(false);
-
-                DoRead();
-            }
-
-
-            #region method Buffering_Completed
-
-            /// <summary>
-            /// Is called when asynchronous read buffer buffering has completed.
-            /// </summary>
-            /// <param name="x">Exception that occured during async operation.</param>
-            private void Buffering_Completed(Exception x)
-            {
-                if(x != null){
-                    m_pException = x;
-                    Completed();
-                }
-                // We reached end of stream, no more data.
-                else if(m_pOwner.BytesInReadBuffer == 0){
-                    Completed();
-                }
-                // Continue data reading.
-                else{
-                    DoRead();
-                }
-            }
-
-            #endregion
-
-            #region method DoRead
-
-            /// <summary>
-            /// Does asynchronous data reading.
-            /// </summary>
-            private void DoRead()
-            {
-                try{
-                    // Read buffer empty, buff next data block.
-                    if(m_pOwner.BytesInReadBuffer == 0){
-                        // Buffering started asynchronously.
-                        if(m_pOwner.BufferRead(true,this.Buffering_Completed)){
-                            return;
-                        }
-                        // Buffering completed synchronously, continue processing.
-                        else{
-                            // We reached end of stream, no more data.
-                            if(m_pOwner.BytesInReadBuffer == 0){
-                                Completed();
-                                return;
-                            }
-                        }
-                    }
-
-                    int readedCount = Math.Min(m_MaxSize,m_pOwner.BytesInReadBuffer);
-                    Array.Copy(m_pOwner.m_pReadBuffer,m_pOwner.m_ReadBufferOffset,m_pBuffer,m_OffsetInBuffer,readedCount);
-                    m_pOwner.m_ReadBufferOffset += readedCount;
-                    m_pOwner.m_LastActivity = DateTime.Now;
-                    m_BytesStored += readedCount;
-
-                    Completed();
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    Completed();
-                }
-            }
-
-            #endregion
-
-            #region method Completed
-
-            /// <summary>
-            /// This method must be called when asynchronous operation has completed.
-            /// </summary>
-            private void Completed()
-            {
-                m_IsCompleted = true;
-                m_pAsyncWaitHandle.Set();
-                if(m_pAsyncCallback != null){
-                    m_pAsyncCallback(this);
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
-            /// </summary>
-            public object AsyncState
-            {
-                get{ return m_pAsyncState; }
-            }
-
-            /// <summary>
-            /// Gets a WaitHandle that is used to wait for an asynchronous operation to complete.
-            /// </summary>
-            public WaitHandle AsyncWaitHandle
-            {
-                get{ return m_pAsyncWaitHandle; }
-            }
-
-            /// <summary>
-            /// Gets an indication of whether the asynchronous operation completed synchronously.
-            /// </summary>
-            public bool CompletedSynchronously
-            {
-                get{ return m_CompletedSynchronously; }
-            }
-
-            /// <summary>
-            /// Gets an indication whether the asynchronous operation has completed.
-            /// </summary>
-            public bool IsCompleted
-            {
-                get{ return m_IsCompleted; }
-            }
-
-
-            /// <summary>
-            /// Gets or sets if <b>EndReadLine</b> method is called for this asynchronous operation.
-            /// </summary>
-            internal bool IsEndCalled
-            {
-                get{ return m_IsEndCalled; }
-
-                set{ m_IsEndCalled = value; }
-            }
-
-            /// <summary>
-            /// Gets store buffer.
-            /// </summary>
-            internal byte[] Buffer
-            {
-                get{ return m_pBuffer; }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored in to <b>Buffer</b>.
-            /// </summary>
-            internal int BytesStored
-            {
-                get{ return m_BytesStored; }
-            }
-
-            #endregion
-        }
-
-        #endregion
-                
-        #region class ReadLineAsyncOP
-
-        /// <summary>
-        /// This class implements read line operation.
-        /// </summary>
-        /// <remarks>This class can be reused on multiple calls of <see cref="SmartStream.ReadLine(ReadLineAsyncOP,bool)">SmartStream.ReadLine</see> method.</remarks>
-        public class ReadLineAsyncOP : IDisposable,IAsyncOP
-        {
-            private object             m_pLock           = new object(); 
-            private AsyncOP_State      m_State           = AsyncOP_State.WaitingForStart;
-            private Exception          m_pException      = null;
-            private bool               m_RiseCompleted   = false;
-            private SmartStream        m_pOwner          = null;
-            private byte[]             m_pBuffer         = null;
-            private SizeExceededAction m_ExceededAction  = SizeExceededAction.JunkAndThrowException;
-            private int                m_BytesInBuffer   = 0;
-            private int                m_LastByte        = -1;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="buffer">Line buffer.</param>
-            /// <param name="exceededAction">Specifies how line-reader behaves when maximum line size exceeded.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-            public ReadLineAsyncOP(byte[] buffer,SizeExceededAction exceededAction)
-            {
-                if(buffer == null){
-                    throw new ArgumentNullException("buffer");
-                }
-
-                m_pBuffer        = buffer;
-                m_ExceededAction = exceededAction;
-            }
-
-            /// <summary>
-            /// Destructor.
-            /// </summary>
-            ~ReadLineAsyncOP()
-            {
-                Dispose();
-            }
-
-            #region method Dispose
-
-            /// <summary>
-            /// Cleans up any resources being used.
-            /// </summary>
-            public void Dispose()
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-
-                m_State             = AsyncOP_State.Disposed;
-                m_pOwner            = null;
-                m_pBuffer           = null;
-                m_pException        = null;
-                this.CompletedAsync = null;
-                this.Completed      = null;
-            }
-
-            #endregion
-
-
-            #region method Start
-
-            /// <summary>
-            /// Starts asynchronous operation.
-            /// </summary>
-            /// <param name="async">If true then this method can complete asynchronously. If false, this method always completes syncronously.</param>
-            /// <param name="stream">Owner SmartStream.</param>
-            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-            internal bool Start(bool async,SmartStream stream)
-            {   
-                if(m_State == AsyncOP_State.Disposed){
-                    throw new ObjectDisposedException(this.GetType().Name);
-                }
-                if(m_State == AsyncOP_State.Active){
-                    throw new InvalidOperationException("There is existing active operation. There may be only one active operation at same time.");
-                }
-                if(stream == null){
-                    throw new ArgumentNullException("stream");
-                }
-                
-                m_pOwner        = stream;
-                m_State         = AsyncOP_State.Active;
-                m_RiseCompleted = false;
-                m_pException    = null;
-                m_BytesInBuffer = 0;
-                m_LastByte      = -1;
-   
-                if(DoLineReading(async)){
-                    SetState(AsyncOP_State.Completed);
-                }
-
-                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
-                // If already completed sync, that flag has no effect.
-                lock(m_pLock){
-                    m_RiseCompleted = true;
-                    
-                    return m_State == AsyncOP_State.Active;
-                }
-            }
-
-            #endregion
-
-
-            #region method Buffering_Completed
-
-            /// <summary>
-            /// Is called when asynchronous read buffer buffering has completed.
-            /// </summary>
-            /// <param name="x">Exception that occured during async operation. Value null means no errors.</param>
-            private void Buffering_Completed(Exception x)
-            {
-                bool setCompletedState = false;
-
-                try{            
-                    if(x != null){
-                        m_pException = x;
-                        
-                        setCompletedState = true;
-                    }
-                    // We reached end of stream, no more data.
-                    else if(m_pOwner.BytesInReadBuffer == 0){
-                        setCompletedState = true;
-                    }
-                    // Continue line reading.
-                    else{
-                        if(DoLineReading(true)){
-                            setCompletedState = true;
-                        }
-                    }
-                }
-                catch(Exception e){
-                    m_pException = e;
-
-                    setCompletedState = true;
-                }
-
-                // SetState may not be in try/catch. If CompletedAsync event consumer causes unhandled Exception,
-                // we may not catch it, we need to let it happen on active thread.
-                if(setCompletedState){
-                    SetState(AsyncOP_State.Completed);
-                }
-            }
-
-            #endregion
-
-            #region method DoLineReading
-
-            /// <summary>
-            /// Starts/continues line reading.
-            /// </summary>
-            /// <param name="async">If true then this method can complete asynchronously. If false, this method completes always syncronously.</param>
-            /// <returns>Returns true if line reading has completed.</returns>
-            private bool DoLineReading(bool async)
-            {
-                try{
-                    while(true){                        
-                        // Read buffer empty, buff next data block.
-                        if(m_pOwner.BytesInReadBuffer == 0){
-                            // Buffering started asynchronously.
-                            if(m_pOwner.BufferRead(async,this.Buffering_Completed)){
-                                return false;
-                            }
-                            // Buffering completed synchronously, continue processing.
-                            else{
-                                // We reached end of stream, no more data.
-                                if(m_pOwner.BytesInReadBuffer == 0){                                    
-                                    return true;
-                                }
-                            }
-                        }
-
-                        byte b = m_pOwner.m_pReadBuffer[m_pOwner.m_ReadBufferOffset++];
-                        
-                        // Line buffer full.
-                        if(m_BytesInBuffer >= m_pBuffer.Length){
-                            if(m_pException == null){
-                                m_pException = new LineSizeExceededException();
-                            }
-
-                            if(m_ExceededAction == SizeExceededAction.ThrowException){                                
-                                return true;
-                            }
-                        }
-                        // Store byte.
-                        else{
-                            m_pBuffer[m_BytesInBuffer++] = b;
-                        }
-
-                        // We have LF line.
-                        if(b == '\n'){
-                            if(!m_pOwner.CRLFLines || m_pOwner.CRLFLines  && m_LastByte == '\r'){
-                                return true;
-                            }                   
-                        }
-
-                        m_LastByte = b;
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                }
-
-                return true;
-            }
-
-            #endregion
-
-
-            #region method SetState
-
-            /// <summary>
-            /// Sets operation state.
-            /// </summary>
-            /// <param name="state">New state.</param>
-            private void SetState(AsyncOP_State state)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-            
-                // Note: Get riseCompleted in lock, otherwise we get race condition Start method m_RiseCompleted = true.
-                bool riseCompleted = m_RiseCompleted;
-                lock(m_pLock){
-                    m_State = state;
-                    riseCompleted = m_RiseCompleted;
-                }
-
-                if(m_State == AsyncOP_State.Completed && riseCompleted){
-                    OnCompletedAsync();
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets asynchronous operation state.
-            /// </summary>
-            public AsyncOP_State State
-            {
-                get{ return m_State; }
-            }
-
-            /// <summary>
-            /// Gets error occured during asynchronous operation. Value null means no error.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public Exception Error
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_pException; 
-                }
-            }
-
-            /// <summary>
-            /// Gets line size exceeded action.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public SizeExceededAction SizeExceededAction
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_ExceededAction;
-                }
-            }
-
-            /// <summary>
-            /// Gets line buffer.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public byte[] Buffer
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_pBuffer; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored in the buffer. Ending line-feed characters included.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public int BytesInBuffer
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_BytesInBuffer; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of line data bytes stored in the buffer. Ending line-feed characters not included.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public int LineBytesInBuffer
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    int retVal = m_BytesInBuffer;
-
-                    if(m_BytesInBuffer > 1){
-                        if(m_pBuffer[m_BytesInBuffer - 1] == '\n'){
-                            retVal--;
-                            if(m_pBuffer[m_BytesInBuffer - 2] == '\r'){
-                                retVal--;
-                            }
-                        }
-                    }
-                    else if(m_BytesInBuffer > 0){
-                        if(m_pBuffer[m_BytesInBuffer - 1] == '\n'){
-                            retVal--;
-                        }
-                    }
-
-                    return retVal; 
-                }
-            }
-
-            /// <summary>
-            /// Gets line as ASCII string. Returns null if EOS(end of stream) reached. Ending line-feed characters not included.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public string LineAscii
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    if(this.BytesInBuffer == 0){
-                        return null;
-                    }
-                    else{
-                        return Encoding.ASCII.GetString(m_pBuffer,0,this.LineBytesInBuffer); 
-                    }
-                }
-            }
-
-            /// <summary>
-            /// Gets line as UTF-8 string. Returns null if EOS(end of stream) reached. Ending line-feed characters not included.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public string LineUtf8
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    if(this.BytesInBuffer == 0){
-                        return null;
-                    }
-                    else{
-                        return Encoding.UTF8.GetString(m_pBuffer,0,this.LineBytesInBuffer);
-                    }
-                }
-            }
-
-            /// <summary>
-            /// Gets line as UTF-32 string. Returns null if EOS(end of stream) reached. Ending line-feed characters not included.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public string LineUtf32
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    if(this.BytesInBuffer == 0){
-                        return null;
-                    }
-                    else{
-                        return Encoding.UTF32.GetString(m_pBuffer,0,this.LineBytesInBuffer);
-                    }
-                }
-            }
-
-            #endregion
-
-            #region Events implementation
-
-            /// <summary>
-            /// Is called when asynchronous operation has completed.
-            /// </summary>
-            public event EventHandler<EventArgs<ReadLineAsyncOP>> CompletedAsync = null;
-
-            #region method OnCompletedAsync
-
-            /// <summary>
-            /// Raises <b>CompletedAsync</b> event.
-            /// </summary>
-            private void OnCompletedAsync()
-            {
-                if(this.CompletedAsync != null){
-                    this.CompletedAsync(this,new EventArgs<ReadLineAsyncOP>(this));
-                }
-
-                // For obsolete support.
-                if(this.Completed != null){
-                    this.Completed(this,new EventArgs<ReadLineAsyncOP>(this));
-                }
-            }
-
-            #endregion
-
-            #endregion
-
-
-            //---------- Obsolete stuff
-
-            #region Obsolete
-
-            /// <summary>
-            /// Is called when asynchronous operation has completed.
-            /// </summary>
-            [Obsolete("Use CompletedAsync event istead.")]
-            public event EventHandler<EventArgs<ReadLineAsyncOP>> Completed = null;
-
-            #endregion
-        }
-
-        #endregion
-
-        #region class ReadPeriodTerminatedAsyncOP
-
-        /// <summary>
-        /// This class implements read period-terminated operation.
-        /// </summary>
-        public class ReadPeriodTerminatedAsyncOP : IDisposable,IAsyncOP
-        {
-            private object             m_pLock           = new object(); 
-            private AsyncOP_State      m_State           = AsyncOP_State.WaitingForStart;
-            private Exception          m_pException      = null;
-            private bool               m_RiseCompleted   = false;
-            private SmartStream        m_pOwner          = null;
-            private Stream             m_pStream         = null;
-            private long               m_MaxCount        = 0;
-            private SizeExceededAction m_ExceededAction  = SizeExceededAction.JunkAndThrowException;
-            private ReadLineAsyncOP    m_pReadLineOP     = null;
-            private long               m_BytesStored     = 0;
-            private int                m_LinesStored     = 0;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="stream">Stream wehre to sore readed data.</param>
-            /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
-            /// <param name="exceededAction">Specifies how period-terminated reader behaves when <b>maxCount</b> exceeded.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-            public ReadPeriodTerminatedAsyncOP(Stream stream,long maxCount,SizeExceededAction exceededAction)
-            {
-                if(stream == null){
-                    throw new ArgumentNullException("stream");
-                }
-                if(maxCount < 0){
-                    throw new ArgumentException("Argument 'maxCount' must be >= 0.","maxCount");
-                }
-
-                m_pStream        = stream;
-                m_MaxCount       = maxCount;
-                m_ExceededAction = exceededAction;
-
-                m_pReadLineOP = new ReadLineAsyncOP(new byte[32000],exceededAction);
-                m_pReadLineOP.CompletedAsync += new EventHandler<EventArgs<ReadLineAsyncOP>>(m_pReadLineOP_CompletedAsync);
-            }
-
-            /// <summary>
-            /// Destructor.
-            /// </summary>
-            ~ReadPeriodTerminatedAsyncOP()
-            {
-                Dispose();
-            }
-
-            #region method Dispose
-
-            /// <summary>
-            /// Cleans up any resources being used.
-            /// </summary>
-            public void Dispose()
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-
-                m_State             = AsyncOP_State.Disposed;
-                m_pOwner            = null;
-                m_pStream           = null;
-                m_pReadLineOP.Dispose();
-                m_pReadLineOP       = null;
-                m_pException        = null;
-                this.CompletedAsync = null;
-                this.Completed      = null;
-            }
-
-            #endregion
-
-
-            #region method Start
-
-            /// <summary>
-            /// Starts asynchronous operation.
-            /// </summary>
-            /// <param name="async">If true then this method can complete asynchronously. If false, this method always completes syncronously.</param>
-            /// <param name="stream">Owner SmartStream.</param>
-            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-            /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-            internal bool Start(bool async,SmartStream stream)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    throw new ObjectDisposedException(this.GetType().Name);
-                }
-                if(m_State == AsyncOP_State.Active){
-                    throw new InvalidOperationException("There is existing active operation. There may be only one active operation at same time.");
-                }
-                if(stream == null){
-                    throw new ArgumentNullException("stream");
-                }
-
-                m_pOwner        = stream;
-                m_State         = AsyncOP_State.Active;
-                m_RiseCompleted = false;
-                m_pException    = null;
-                m_BytesStored   = 0;
-                m_LinesStored   = 0;
-
-                if(DoRead(async)){
-                    SetState(AsyncOP_State.Completed);
-                }
-   
-                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
-                // If already completed sync, that flag has no effect.
-                lock(m_pLock){
-                    m_RiseCompleted = true;
-                    
-                    return m_State == AsyncOP_State.Active;
-                }
-            }
-
-            #endregion
-
-
-            #region method m_pReadLineOP_CompletedAsync
-
-            /// <summary>
-            /// Is called when asynchronous line reading has completed.
-            /// </summary>
-            /// <param name="sender">Sender.</param>
-            /// <param name="e">Event data.</param>
-            private void m_pReadLineOP_CompletedAsync(object sender,EventArgs<ReadLineAsyncOP> e)
-            {
-                bool setCompletedState = false;
-
-                try{
-                    if(ProcessReadedLine()){
-                        setCompletedState = true;
-                    }
-                    else{
-                        if(DoRead(true)){
-                            setCompletedState = true;
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-
-                    setCompletedState = true;
-                }
-
-                // SetState may not be in try/catch. If CompletedAsync event consumer causes unhandled Exception,
-                // we may not catch it, we need to let it happen on active thread.
-                if(setCompletedState){
-                    SetState(AsyncOP_State.Completed);
-                }
-            }
-
-            #endregion
-
-            #region method DoRead
-
-            /// <summary>
-            /// Continues period-terminated reading.
-            /// </summary>
-            /// <param name="async">If true then this method can complete asynchronously. If false, this method completes always syncronously.</param>
-            /// <returns>Returns true if operation has completed synchronously, false if asynchronous operation pending.</returns>
-            private bool DoRead(bool async)
-            {
-                try{
-                    while(m_pOwner.ReadLine(m_pReadLineOP,async)){
-                        if(ProcessReadedLine()){
-                            return true;
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                }
-
-                return false;
-            }
-
-            #endregion
-
-            #region method ProcessReadedLine
-
-            /// <summary>
-            /// Processes readed line.
-            /// </summary>
-            /// <returns>Returns true if read period-terminated operation has completed.</returns>
-            private bool ProcessReadedLine()
-            {
-                if(m_pReadLineOP.Error != null){
-                    m_pException = m_pReadLineOP.Error;
-
-                    return true;
-                }
-                // We reached end of stream, no more data.
-                else if(m_pReadLineOP.BytesInBuffer == 0){
-                    m_pException = new IncompleteDataException("Data is not period-terminated.");
-
-                    return true;
-                }
-                // We have period terminator.
-                else if(m_pReadLineOP.LineBytesInBuffer == 1 && m_pReadLineOP.Buffer[0] == '.'){
-                    return true;
-                }
-                // Normal line.
-                else{
-                    if(m_MaxCount < 1 || (m_BytesStored + m_pReadLineOP.BytesInBuffer) < m_MaxCount){
-                        // Period handling: If line starts with '.', it must be removed.
-                        if(m_pReadLineOP.Buffer[0] == '.'){
-                            m_pStream.Write(m_pReadLineOP.Buffer,1,m_pReadLineOP.BytesInBuffer - 1);
-                            m_BytesStored += m_pReadLineOP.BytesInBuffer - 1;
-                            m_LinesStored++;
-                        }
-                        // Nomrmal line.
-                        else{
-                            m_pStream.Write(m_pReadLineOP.Buffer,0,m_pReadLineOP.BytesInBuffer);
-                            m_BytesStored += m_pReadLineOP.BytesInBuffer;
-                            m_LinesStored++;
-                        }                        
-                    }
-                    // Maximum allowed to store bytes exceeded.
-                    else{
-                        if(m_ExceededAction == SizeExceededAction.ThrowException){
-                            m_pException = new DataSizeExceededException();
-
-                            return true;
-                        }
-                        else if(m_pException == null){
-                            m_pException = new DataSizeExceededException();
-                        }
-                    }
-                }
-
-                return false;
-            }
-
-            #endregion
-
-
-            #region method SetState
-
-            /// <summary>
-            /// Sets operation state.
-            /// </summary>
-            /// <param name="state">New state.</param>
-            private void SetState(AsyncOP_State state)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-            
-                // Note: Get riseCompleted in lock, otherwise we get race condition Start method m_RiseCompleted = true.
-                bool riseCompleted = m_RiseCompleted;
-                lock(m_pLock){
-                    m_State = state;
-                    riseCompleted = m_RiseCompleted;
-                }
-
-                if(m_State == AsyncOP_State.Completed && riseCompleted){
-                    OnCompletedAsync();
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets asynchronous operation state.
-            /// </summary>
-            public AsyncOP_State State
-            {
-                get{ return m_State; }
-            }
-
-            /// <summary>
-            /// Gets error occured during asynchronous operation. Value null means no error.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public Exception Error
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_pException; 
-                }
-            }
-
-            /// <summary>
-            /// Gets stream where period terminated data has stored.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public Stream Stream
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_pStream; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored to <see cref="Stream">Stream</see> stream.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public long BytesStored
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_BytesStored; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of lines stored to <see cref="Stream">Stream</see> stream.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public int LinesStored
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_LinesStored; 
-                }
-            }
-
-            #endregion
-
-            #region Events implementation
-
-            /// <summary>
-            /// Is raised when asynchronous operation has completed.
-            /// </summary>
-            public event EventHandler<EventArgs<ReadPeriodTerminatedAsyncOP>> CompletedAsync = null;
-
-            #region method OnCompletedAsync
-
-            /// <summary>
-            /// Raises <b>CompletedAsync</b> event.
-            /// </summary>
-            private void OnCompletedAsync()
-            {
-                if(this.CompletedAsync != null){
-                    this.CompletedAsync(this,new EventArgs<ReadPeriodTerminatedAsyncOP>(this));
-                }
-
-                // For obsolete support.
-                if(this.Completed != null){
-                    this.Completed(this,new EventArgs<ReadPeriodTerminatedAsyncOP>(this));
-                }
-            }
-
-            #endregion
-
-            #endregion
-
-
-            //---------- Obsolete stuff
-
-            #region Obsolete
-
-            /// <summary>
-            /// Is called when asynchronous operation has completed.
-            /// </summary>
-            [Obsolete("Use CompletedAsync event istead.")]
-            public event EventHandler<EventArgs<ReadPeriodTerminatedAsyncOP>> Completed = null;
-
-            #endregion
-        }
-
-        #endregion
-
-        #region class BufferReadAsyncOP
-
-        /// <summary>
-        /// This class implements asynchronous read buffering.
-        /// </summary>
-        private class BufferReadAsyncOP : IDisposable,IAsyncOP
-        {
-            private object        m_pLock            = new object(); 
-            private AsyncOP_State m_State            = AsyncOP_State.WaitingForStart;
-            private Exception     m_pException       = null;
-            private bool          m_RiseCompleted    = false;
-            private SmartStream   m_pOwner           = null;
-            private byte[]        m_pBuffer          = null;
-            private int           m_MaxCount         = 0;
-            private int           m_BytesInBuffer    = 0;
-            private bool          m_IsCallbackCalled = false;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="owner">Owner stream.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception>
-            public BufferReadAsyncOP(SmartStream owner)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-
-                m_pOwner = owner;
-            }
-
-            /// <summary>
-            /// Destructor.
-            /// </summary>
-            ~BufferReadAsyncOP()
-            {
-                Dispose();
-            }
-
-            #region method Dispose
-
-            /// <summary>
-            /// Cleans up any resources being used.
-            /// </summary>
-            public void Dispose()
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-                
-                try{
-                    // Terminate pending asynchronous operation, if any.
-                    if(m_State == AsyncOP_State.Active){
-                        m_pException = new ObjectDisposedException("SmartStream");
-                        m_State = AsyncOP_State.Completed;
-                        OnCompletedAsync();
-                    }
-                }
-                catch{
-                }
-                    
-                m_State             = AsyncOP_State.Disposed;
-                m_pOwner            = null;
-                m_pBuffer           = null;
-                this.CompletedAsync = null;                
-            }
-
-            #endregion
-
-
-            #region method Start
-
-            /// <summary>
-            /// Starts asynchronous operation.
-            /// </summary>
-            /// <param name="async">If true then this method can complete asynchronously. If false, this method always completes syncronously.</param>
-            /// <param name="buffer">Buffer where to store readed data.</param>
-            /// <param name="count">Maximum number of bytes to read.</param>
-            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-            /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-            /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-            internal bool Start(bool async,byte[] buffer,int count)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    throw new ObjectDisposedException(this.GetType().Name);
-                }
-                if(m_State == AsyncOP_State.Active){
-                    throw new InvalidOperationException("There is existing active operation. There may be only one active operation at same time.");
-                }
-                if(buffer == null){
-                    throw new ArgumentNullException("buffer");
-                }
-                if(count < 0){
-                    throw new ArgumentException("Argument 'count' value must be >= 0.");
-                }
-                if(count > buffer.Length){
-                    throw new ArgumentException("Argument 'count' value must be <= buffer.Length.");
-                }
-
-                m_State            = AsyncOP_State.Active;
-                m_RiseCompleted    = false;
-                m_pException       = null;
-                m_pBuffer          = buffer;
-                m_MaxCount         = count;
-                m_BytesInBuffer    = 0;
-                m_IsCallbackCalled = false;
-                
-                // Operation may complete asynchronously;
-                if(async){
-                    try{
-                        m_pOwner.m_pStream.BeginRead(buffer,0,count,new AsyncCallback(delegate(IAsyncResult r){
-                            try{
-                                m_BytesInBuffer = m_pOwner.m_pStream.EndRead(r);
-                            }
-                            catch(Exception x){
-                                m_pException = x;
-                            }
-                            
-                            // SetState may not be in try/catch. If CompletedAsync event consumer causes unhandled Exception,
-                            // we may not catch it, we need to let it happen on active thread.    
-                            SetState(AsyncOP_State.Completed);                           
-
-                        }),null);
-                    }                    
-                    catch(Exception x){
-                        m_pException = x;
-
-                        SetState(AsyncOP_State.Completed);
-                    }
-                }
-                // Operation must complete synchronously.
-                else{
-                    try{
-                        m_BytesInBuffer = m_pOwner.m_pStream.Read(buffer,0,count);
-                    }
-                    catch(Exception x){
-                        m_pException = x;
-                    }
-                    
-                    SetState(AsyncOP_State.Completed);
-                }
-                                
-                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
-                // If already completed sync, that flag has no effect.
-                lock(m_pLock){
-                    m_RiseCompleted = true;
-
-                    return m_State == AsyncOP_State.Active;
-                }
-            }
-
-            #endregion
-
-            #region method ReleaseEvents
-
-            /// <summary>
-            /// Releases all events attached to this class.
-            /// </summary>
-            internal void ReleaseEvents()
-            {
-                this.CompletedAsync = null;
-            }
-
-            #endregion
-
-
-            #region method SetState
-
-            /// <summary>
-            /// Sets operation state.
-            /// </summary>
-            /// <param name="state">New state.</param>
-            private void SetState(AsyncOP_State state)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-            
-                // Note: Get riseCompleted in lock, otherwise we get race condition Start method m_RiseCompleted = true.
-                bool riseCompleted = m_RiseCompleted;
-                lock(m_pLock){
-                    m_State = state;
-                    riseCompleted = m_RiseCompleted;
-                }
-
-                if(m_State == AsyncOP_State.Completed && riseCompleted){
-                    OnCompletedAsync();
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets asynchronous operation state.
-            /// </summary>
-            public AsyncOP_State State
-            {
-                get{ return m_State; }
-            }
-
-            /// <summary>
-            /// Gets error occured during asynchronous operation. Value null means no error.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public Exception Error
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_pException; 
-                }
-            }
-
-            /// <summary>
-            /// Gets read buffer.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public byte[] Buffer
-            {
-                get{
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_pBuffer; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored in read buffer.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed in ivalid state.</exception>
-            public int BytesInBuffer
-            {
-                get{ 
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }                    
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("This property is only valid in AsyncOP_State.Completed state.");
-                    }
-
-                    return m_BytesInBuffer; 
-                }
-            }
-
-            #endregion
-
-            #region Events implementation
-
-            /// <summary>
-            /// Is called when asynchronous operation has completed.
-            /// </summary>
-            public event EventHandler<EventArgs<BufferReadAsyncOP>> CompletedAsync = null;
-
-            #region method OnCompletedAsync
-
-            /// <summary>
-            /// Raises <b>CompletedAsync</b> event.
-            /// </summary>
-            private void OnCompletedAsync()
-            {
-                if(!m_IsCallbackCalled && this.CompletedAsync != null){
-                    m_IsCallbackCalled = true;
-
-                    this.CompletedAsync(this,new EventArgs<BufferReadAsyncOP>(this));
-                }
-            }
-
-            #endregion
-
-            #endregion
-        }
-
-        #endregion
-
-        private bool              m_IsDisposed       = false;
-        private Stream            m_pStream          = null;
-        private bool              m_IsOwner          = false;
-        private DateTime          m_LastActivity;
-        private long              m_BytesReaded      = 0;
-        private long              m_BytesWritten     = 0;
-        private int               m_BufferSize       = 84000;
-        private byte[]            m_pReadBuffer      = null;
-        private int               m_ReadBufferOffset = 0;
-        private int               m_ReadBufferCount  = 0;        
-        private BufferReadAsyncOP m_pReadBufferOP    = null;
-        private Encoding          m_pEncoding        = Encoding.Default;
-        private bool              m_CRLFLines        = true;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="stream">Stream to wrap.</param>
-        /// <param name="owner">Specifies if SmartStream is owner of <b>stream</b>.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        public SmartStream(Stream stream,bool owner)
-        {
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-            
-            m_pStream = stream;
-            m_IsOwner = owner;
-            m_pReadBuffer = new byte[m_BufferSize];
-            m_pReadBufferOP = new BufferReadAsyncOP(this);
-
-            m_LastActivity = DateTime.Now;
-        }
-
-        #region method Dispose
-
-        /// <summary>
-        /// Cleans up any resources being used.
-        /// </summary>
-        public new void Dispose()
-        {
-            if(m_IsDisposed){
-                return;
-            }
-            m_IsDisposed = true;
-            
-            if(m_pReadBufferOP != null){
-                m_pReadBufferOP.Dispose();
-            }
-            m_pReadBufferOP = null;
-
-            if(m_IsOwner){
-                m_pStream.Dispose();
-            }
-        }
-
-        #endregion
-        
-                                        
-        #region method ReadLine
-
-        /// <summary>
-        /// Starts line reading.
-        /// </summary>
-        /// <param name="op">Read line opeartion.</param>
-        /// <param name="async">If true then this method can complete asynchronously. If false, this method completes always syncronously.</param>
-        /// <returns>Returns true if read line completed synchronously, false if asynchronous operation pending.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
-        public bool ReadLine(ReadLineAsyncOP op,bool async)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(op == null){
-                throw new ArgumentNullException("op");
-            }
-
-            return !op.Start(async,this);
-        }
-
-        #endregion
-
-        #region method BeginReadHeader
-
-        /// <summary>
-        /// Begins an asynchronous header reading from the source stream.
-        /// </summary>
-        /// <param name="storeStream">Stream where to store readed header.</param>
-        /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
-        /// <param name="exceededAction">Specifies action what is done if <b>maxCount</b> number of bytes has exceeded.</param>
-        /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-        /// <param name="state">An object that contains any additional user-defined data.</param>
-        /// <returns>An IAsyncResult that represents the asynchronous call.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>storeStream</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        public IAsyncResult BeginReadHeader(Stream storeStream,int maxCount,SizeExceededAction exceededAction,AsyncCallback callback,object state)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(storeStream == null){
-                throw new ArgumentNullException("storeStream");
-            }
-            if(maxCount < 0){
-                throw new ArgumentException("Argument 'maxCount' must be >= 0.");
-            }
-
-            return new ReadToTerminatorAsyncOperation(this,"",storeStream,maxCount,exceededAction,callback,state);
-        }
-
-        #endregion
-
-        #region method EndReadHeader
-
-        /// <summary>
-        /// Handles the end of an asynchronous header reading.
-        /// </summary>
-        /// <param name="asyncResult">An IAsyncResult that represents an asynchronous call.</param>
-        /// <returns>Returns number of bytes stored to <b>storeStream</b>.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>asyncResult</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when invalid <b>asyncResult</b> passed to this method.</exception>
-        /// <exception cref="InvalidOperationException">Is raised when <b>EndReadLine</b> has already been called for specified <b>asyncResult</b>.</exception>
-        /// <exception cref="LineSizeExceededException">Is raised when source stream has too big line.</exception>
-        /// <exception cref="DataSizeExceededException">Is raised when reading exceeds <b>maxCount</b> specified value.</exception>
-        /// <exception cref="IncompleteDataException">Is raised when source stream closed before header-terminator reached.</exception>
-        public int EndReadHeader(IAsyncResult asyncResult)
-        {
-            if(asyncResult == null){
-                throw new ArgumentNullException("asyncResult");
-            }
-            if(!(asyncResult is ReadToTerminatorAsyncOperation)){
-                throw new ArgumentException("Argument 'asyncResult' was not returned by a call to the BeginReadHeader method.");
-            }
-
-            ReadToTerminatorAsyncOperation ar = (ReadToTerminatorAsyncOperation)asyncResult;
-            if(ar.IsEndCalled){
-                throw new InvalidOperationException("EndReadHeader is already called for specified 'asyncResult'.");
-            }
-            ar.AsyncWaitHandle.WaitOne();
-            ar.AsyncWaitHandle.Close();
-            ar.IsEndCalled = true;
-            if(ar.Exception != null){
-                throw ar.Exception;
-            }
-
-            return (int)ar.BytesStored;
-        }
-
-        #endregion
-
-        #region method ReadHeader
-
-        /// <summary>
-        /// Reads header from stream and stores to the specified <b>storeStream</b>.
-        /// </summary>
-        /// <param name="storeStream">Stream where to store readed header.</param>
-        /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
-        /// <param name="exceededAction">Specifies action what is done if <b>maxCount</b> number of bytes has exceeded.</param>
-        /// <returns>Returns how many bytes readed from source stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>storeStream</b> is null.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="LineSizeExceededException">Is raised when source stream has too big line.</exception>
-        /// <exception cref="DataSizeExceededException">Is raised when reading exceeds <b>maxCount</b> specified value.</exception>
-        /// <exception cref="IncompleteDataException">Is raised when source stream closed before header-terminator reached.</exception>
-        public int ReadHeader(Stream storeStream,int maxCount,SizeExceededAction exceededAction)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(storeStream == null){
-                throw new ArgumentNullException("storeStream");
-            }            
-            if(maxCount < 0){
-                throw new ArgumentException("Argument 'maxCount' must be >= 0.");
-            }
-
-            IAsyncResult ar = BeginReadHeader(storeStream,maxCount,exceededAction,null,null);
-
-            return EndReadHeader(ar);
-        }
-
-        #endregion
-
-        #region method ReadPeriodTerminated
-
-        /// <summary>
-        /// Begins period-terminated data reading.
-        /// </summary>
-        /// <param name="op">Read period terminated opeartion.</param>
-        /// <param name="async">If true then this method can complete asynchronously. If false, this method completed always syncronously.</param>
-        /// <returns>Returns true if read line completed synchronously, false if asynchronous operation pending.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
-        public bool ReadPeriodTerminated(ReadPeriodTerminatedAsyncOP op,bool async)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(op == null){
-                throw new ArgumentNullException("op");
-            }
-
-            return !op.Start(async,this);
-        }
-
-        #endregion
-
-        #region method BeginReadFixedCount
-
-        /// <summary>
-        /// Begins an asynchronous data reading from the source stream.
-        /// </summary>
-        /// <param name="storeStream">Stream where to store readed header.</param>
-        /// <param name="count">Number of bytes to read.</param>
-        /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-        /// <param name="state">An object that contains any additional user-defined data.</param>
-        /// <returns>An IAsyncResult that represents the asynchronous call.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>storeStream</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        public IAsyncResult BeginReadFixedCount(Stream storeStream,long count,AsyncCallback callback,object state)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(storeStream == null){
-                throw new ArgumentNullException("storeStream");
-            }
-            if(count < 0){
-                throw new ArgumentException("Argument 'count' value must be >= 0.");
-            }
-
-            return new ReadToStreamAsyncOperation(this,storeStream,count,callback,state);
-        }
-
-        #endregion
-
-        #region method EndReadFixedCount
-
-        /// <summary>
-        /// Handles the end of an asynchronous data reading.
-        /// </summary>
-        /// <param name="asyncResult">An IAsyncResult that represents an asynchronous call.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>asyncResult</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when invalid <b>asyncResult</b> passed to this method.</exception>
-        /// <exception cref="InvalidOperationException">Is raised when <b>EndReadToStream</b> has already been called for specified <b>asyncResult</b>.</exception>
-        public void EndReadFixedCount(IAsyncResult asyncResult)
-        {
-            if(asyncResult == null){
-                throw new ArgumentNullException("asyncResult");
-            }
-            if(!(asyncResult is ReadToStreamAsyncOperation)){
-                throw new ArgumentException("Argument 'asyncResult' was not returned by a call to the BeginReadFixedCount method.");
-            }
-
-            ReadToStreamAsyncOperation ar = (ReadToStreamAsyncOperation)asyncResult;
-            if(ar.IsEndCalled){
-                throw new InvalidOperationException("EndReadFixedCount is already called for specified 'asyncResult'.");
-            }
-            ar.AsyncWaitHandle.WaitOne();
-            ar.AsyncWaitHandle.Close();
-            ar.IsEndCalled = true;
-            if(ar.Exception != null){
-                throw ar.Exception;
-            }
-        }
-
-        #endregion
-
-        #region method ReadFixedCount
-
-        /// <summary>
-        /// Reads specified number of bytes from source stream and writes to the specified stream.
-        /// </summary>
-        /// <param name="storeStream">Stream where to store readed data.</param>
-        /// <param name="count">Number of bytes to read.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>storeStream</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        public void ReadFixedCount(Stream storeStream,long count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(storeStream == null){
-                throw new ArgumentNullException("storeStream");
-            }
-            if(count < 0){
-                throw new ArgumentException("Argument 'count' value must be >= 0.");
-            }
-
-            IAsyncResult ar = BeginReadFixedCount(storeStream,count,null,null);
-
-            EndReadFixedCount(ar);
-        }
-
-        #endregion
-
-        #region method ReadFixedCountString
-
-        /// <summary>
-        /// Reads specified number of bytes from source stream and converts it to string with current encoding.
-        /// </summary>
-        /// <param name="count">Number of bytes to read.</param>
-        /// <returns>Returns readed data as string.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        public string ReadFixedCountString(int count)
-        {    
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(count < 0){
-                throw new ArgumentException("Argument 'count' value must be >= 0.");
-            }
-
-            MemoryStream ms = new MemoryStream();
-            ReadFixedCount(ms,count);
-
-            return m_pEncoding.GetString(ms.ToArray());
-        }
-
-        #endregion
-                
-        #region method ReadAll
-
-        /// <summary>
-        /// Reads all data from source stream and stores to the specified stream.
-        /// </summary>
-        /// <param name="stream">Stream where to store readed data.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        public void ReadAll(Stream stream)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            byte[] buffer = new byte[m_BufferSize];
-            while(true){
-                int readedCount = Read(buffer,0,buffer.Length);
-                // End of stream reached, we readed file sucessfully.
-                if(readedCount == 0){
-                    break;
-                }
-                else{
-                    stream.Write(buffer,0,readedCount);
-                }
-            }
-        }
-
-        #endregion
-
-        #region method Peek
-
-        /// <summary>
-        /// Returns the next available character but does not consume it.
-        /// </summary>
-        /// <returns>An integer representing the next character to be read, or -1 if no more characters are available.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public int Peek()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(this.BytesInReadBuffer == 0){
-                BufferRead(false,null);
-            }
-
-            // We are end of stream.
-            if(this.BytesInReadBuffer == 0){
-                return -1;
-            }
-            else{
-                return m_pReadBuffer[m_ReadBufferOffset];
-            }
-        }
-
-        #endregion
-
-        #region method Write
-
-        /// <summary>
-        /// Writes specified string data to stream.
-        /// </summary>
-        /// <param name="data">Data to write.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null.</exception>
-        public void Write(string data)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(data == null){
-                throw new ArgumentNullException("data");
-            }
-
-            byte[] dataBytes = Encoding.Default.GetBytes(data);
-            Write(dataBytes,0,dataBytes.Length);
-            Flush();
-        }
-
-        #endregion
-
-        #region method WriteLine
-
-        /// <summary>
-        /// Writes specified line to stream. If CRLF is missing, it will be added automatically to line data.
-        /// </summary>
-        /// <param name="line">Line to send.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>line</b> is null.</exception>
-        /// <returns>Returns number of raw bytes written.</returns>
-        public int WriteLine(string line)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(line == null){
-                throw new ArgumentNullException("line");
-            }
-
-            if(!line.EndsWith("\r\n")){
-                line += "\r\n";
-            }
-
-            byte[] dataBytes = m_pEncoding.GetBytes(line);
-            Write(dataBytes,0,dataBytes.Length);
-            Flush();
-
-            return dataBytes.Length;
-        }
-
-        #endregion
-
-        #region method WriteStream
-
-        /// <summary>
-        /// Writes all source <b>stream</b> data to stream.
-        /// </summary>
-        /// <param name="stream">Stream which data to write.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        public void WriteStream(Stream stream)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            byte[] buffer = new byte[m_BufferSize];
-            while(true){
-                int readed = stream.Read(buffer,0,buffer.Length);
-                // We readed all data.
-                if(readed == 0){
-                    break;
-                }
-                Write(buffer,0,readed);
-            }
-            Flush();
-        }
-
-        /// <summary>
-        /// Writes specified number of bytes from source <b>stream</b> to stream.
-        /// </summary>
-        /// <param name="stream">Stream which data to write.</param>
-        /// <param name="count">Number of bytes to write.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        /// <exception cref="ArgumentException">Is raised when <b>count</b> argument has invalid value.</exception>
-        public void WriteStream(Stream stream,long count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-            if(count < 0){
-                throw new ArgumentException("Argument 'count' value must be >= 0.");
-            }
-
-            byte[] buffer      = new byte[m_BufferSize];
-            long   readedCount = 0;
-            while(readedCount < count){
-                int readed = stream.Read(buffer,0,(int)Math.Min(buffer.Length,count - readedCount));
-                readedCount += readed;
-                Write(buffer,0,readed);
-            }
-            Flush();
-        }
-
-        #endregion
-
-        #region method WriteStreamAsync
-
-        #region class WriteStreamAsyncOP
-
-        /// <summary>
-        /// This class represents <see cref="SmartStream.WriteStreamAsync"/> asynchronous operation.
-        /// </summary>
-        public class WriteStreamAsyncOP : IDisposable,IAsyncOP
-        {
-            private object        m_pLock         = new object();
-            private AsyncOP_State m_State         = AsyncOP_State.WaitingForStart;
-            private Exception     m_pException    = null;
-            private bool          m_RiseCompleted = false;
-            private SmartStream   m_pOwner        = null;
-            private Stream        m_pStream       = null;
-            private long          m_Count         = 0;
-            private byte[]        m_pBuffer       = null;
-            private long          m_BytesWritten  = 0;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="stream">Stream which data to write.</param>
-            /// <param name="count">Number of bytes to write. Value -1 means all stream data will be written.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-            public WriteStreamAsyncOP(Stream stream,long count)
-            {
-                if(stream == null){
-                    throw new ArgumentNullException("stream");
-                }
-
-                m_pStream = stream;
-                m_Count   = count;
-                m_pBuffer = new byte[32000];
-            }
-
-            #region method Dispose
-
-            /// <summary>
-            /// Cleans up any resources being used.
-            /// </summary>
-            public void Dispose()
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-                SetState(AsyncOP_State.Disposed);
-                
-                m_pException = null;
-                m_pStream    = null;
-                m_pOwner     = null;
-                m_pBuffer    = null;
-
-                this.CompletedAsync = null;
-            }
-
-            #endregion
-
-
-            #region method Start
-
-            /// <summary>
-            /// Starts operation processing.
-            /// </summary>
-            /// <param name="owner">Owner SmartStream.</param>
-            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
-            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception>
-            internal bool Start(SmartStream owner)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-                
-                m_pOwner = owner;
-
-                SetState(AsyncOP_State.Active);
-                
-                BeginReadData();
-
-                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
-                // If already completed sync, that flag has no effect.
-                lock(m_pLock){
-                    m_RiseCompleted = true;
-
-                    return m_State == AsyncOP_State.Active;
-                }
-            }
-
-            #endregion
-
-
-            #region method SetState
-
-            /// <summary>
-            /// Sets operation state.
-            /// </summary>
-            /// <param name="state">New state.</param>
-            private void SetState(AsyncOP_State state)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-
-                // Note: Get riseCompleted in lock, otherwise we get race condition Start method m_RiseCompleted = true.
-                bool riseCompleted = m_RiseCompleted;
-                lock(m_pLock){
-                    m_State = state;
-                    riseCompleted = m_RiseCompleted;
-                }
-
-                if(m_State == AsyncOP_State.Completed && riseCompleted){
-                    OnCompletedAsync();
-                }
-            }
-
-            #endregion
-
-            #region method BeginReadData
-
-            /// <summary>
-            /// Starts reading data.
-            /// </summary>
-            private void BeginReadData()
-            {                
-                try{
-                    while(true){
-                        bool isBeginReadCompleted = false;
-                        bool isCompletedSync      = false;
-                        int count = m_Count == -1 ? m_pBuffer.Length : (int)Math.Min(m_pBuffer.Length,m_Count - m_BytesWritten);
-                        IAsyncResult readResult = m_pStream.BeginRead(
-                            m_pBuffer,
-                            0,
-                            count,
-                            delegate(IAsyncResult r){
-                                lock(m_pLock){
-                                    // BeginRead completed synchronously.
-                                    if(!isBeginReadCompleted){
-                                        isCompletedSync = true;
-                                        return;
-                                    }
-                                }
-
-                                ProcessReadDataResult(r);
-                            },
-                            null
-                        );
-
-                        lock(m_pLock){
-                            isBeginReadCompleted = true;
-                        }
-
-                        // Read data completed synchonously.
-                        if(isCompletedSync){
-                            // Operation completed asynchronously, it will continue processing.
-                            if(ProcessReadDataResult(readResult)){
-                                break;
-                            }
-                            // Error happened in ProcessReadDataResult method.
-                            if(this.State != AsyncOP_State.Active){
-                                break;
-                            }
-                        }
-                        // Read data completed asynchonously.
-                        else{
-                            break;
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    SetState(AsyncOP_State.Completed);
-                }
-            }
-
-            #endregion
-
-            #region method ProcessReadDataResult
-
-            /// <summary>
-            /// Processes read data result.
-            /// </summary>
-            /// <param name="readResult">Asynchronous result.</param>
-            /// <returns>Retruns true if this method completed asynchronously, otherwise false.</returns>
-            private bool ProcessReadDataResult(IAsyncResult readResult)
-            {
-                try{
-                    int countReaded = m_pStream.EndRead(readResult);
-                    if(countReaded == 0){
-                        // We readed all stream data and write count not specified, we are done.
-                        if(m_Count == -1){
-                            SetState(AsyncOP_State.Completed);
-                        }
-                        // Source stream has less data than specified by count.
-                        else{
-                            m_pException = new ArgumentException("Argument 'stream' has less data than specified in 'count'.","stream");
-                            SetState(AsyncOP_State.Completed);
-                        }
-                    }
-                    else{
-                        bool isBeginWriteCompleted = false;
-                        bool isCompletedSync       = false;
-                        IAsyncResult writeResult = m_pOwner.BeginWrite(
-                            m_pBuffer,
-                            0,
-                            countReaded,
-                            delegate(IAsyncResult r){
-                                lock(m_pLock){
-                                    // BeginWrite completed synchronously.
-                                    if(!isBeginWriteCompleted){
-                                        isCompletedSync = true;
-                                        return;
-                                    }
-                                }
-
-                                try{
-                                    m_pOwner.EndWrite(r);
-                                    m_BytesWritten += countReaded;
-
-                                    // We have read and sent all requested data.
-                                    if(m_Count == m_BytesWritten){
-                                        SetState(AsyncOP_State.Completed);
-                                    }
-                                    // Start reading next data block(s).
-                                    else{                                        
-                                        BeginReadData();
-                                    }
-                                }
-                                catch(Exception x){
-                                    m_pException = x;
-                                    SetState(AsyncOP_State.Completed);
-                                }
-                            },
-                            null
-                        );
-
-                        lock(m_pLock){
-                            isBeginWriteCompleted = true;
-                        }
-
-                        // BeginWrite completed synchronously.
-                        if(isCompletedSync){
-                            m_pOwner.EndWrite(writeResult);
-                            m_BytesWritten += countReaded;
-
-                            // We have read and sent all requested data.
-                            if(m_Count == m_BytesWritten){
-                                SetState(AsyncOP_State.Completed);
-                            }
-                        }
-                        else{
-                            return true;
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    SetState(AsyncOP_State.Completed);
-                }
-
-                return false;
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets asynchronous operation state.
-            /// </summary>
-            public AsyncOP_State State
-            {
-                get{ return m_State; }
-            }
-
-            /// <summary>
-            /// Gets error happened during operation. Returns null if no error.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed other than <b>AsyncOP_State.Completed</b> state.</exception>
-            public Exception Error
-            {
-                get{ 
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("Property 'Error' is accessible only in 'AsyncOP_State.Completed' state.");
-                    }
-
-                    return m_pException; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of bytes written.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed other than <b>AsyncOP_State.Completed</b> state.</exception>
-            public long BytesWritten
-            {
-                get{ 
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("Property 'Socket' is accessible only in 'AsyncOP_State.Completed' state.");
-                    }
-                    if(m_pException != null){
-                        throw m_pException;
-                    }
-
-                    return m_BytesWritten; 
-                }
-            }
-
-            #endregion
-
-            #region Events implementation
-
-            /// <summary>
-            /// Is called when asynchronous operation has completed.
-            /// </summary>
-            public event EventHandler<EventArgs<WriteStreamAsyncOP>> CompletedAsync = null;
-
-            #region method OnCompletedAsync
-
-            /// <summary>
-            /// Raises <b>CompletedAsync</b> event.
-            /// </summary>
-            private void OnCompletedAsync()
-            {
-                if(this.CompletedAsync != null){
-                    this.CompletedAsync(this,new EventArgs<WriteStreamAsyncOP>(this));
-                }
-            }
-
-            #endregion
-
-            #endregion
-        }
-
-        #endregion
-
-        /// <summary>
-        /// Starts writing stream data to this stream.
-        /// </summary>
-        /// <param name="op">Asynchronous operation.</param>
-        /// <returns>Returns true if aynchronous operation is pending (The <see cref="WriteStreamAsyncOP.CompletedAsync"/> event is raised upon completion of the operation).
-        /// Returns false if operation completed synchronously.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
-        public bool WriteStreamAsync(WriteStreamAsyncOP op)
-        {
-            if(this.m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(op == null){
-                throw new ArgumentNullException("op");
-            }
-            if(op.State != AsyncOP_State.WaitingForStart){
-                throw new ArgumentException("Invalid argument 'op' state, 'op' must be in 'AsyncOP_State.WaitingForStart' state.","op");
-            }
-
-            return op.Start(this);
-        }
-
-        #endregion
-
-        #region method WritePeriodTerminated
-
-        /// <summary>
-        /// Writes period handled and terminated data to this stream.
-        /// </summary>
-        /// <param name="stream">Source stream. Reading starts from stream current location.</param>
-        /// <returns>Returns number of bytes written to stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        /// <exception cref="LineSizeExceededException">Is raised when <b>stream</b> has too big line.</exception>        
-        public long WritePeriodTerminated(Stream stream)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            ManualResetEvent wait = new ManualResetEvent(false);
-            WritePeriodTerminatedAsyncOP op = new WritePeriodTerminatedAsyncOP(stream);
-            op.CompletedAsync += delegate(object s1,EventArgs<WritePeriodTerminatedAsyncOP> e1){
-                wait.Set();
-            };
-            if(!this.WritePeriodTerminatedAsync(op)){
-                wait.Set();
-            }
-            wait.WaitOne();
-            wait.Close();
-
-            if(op.Error != null){
-                throw op.Error;
-            }
-            else{
-                return op.BytesWritten;
-            }
-        }
-
-        #endregion
-        
-        #region method WritePeriodTerminatedAsync
-
-        #region class WritePeriodTerminatedAsyncOP
-
-        /// <summary>
-        /// This class represents <see cref="SmartStream.WritePeriodTerminatedAsync"/> asynchronous operation.
-        /// </summary>
-        public class WritePeriodTerminatedAsyncOP : IDisposable,IAsyncOP
-        {
-            private object          m_pLock         = new object();
-            private AsyncOP_State   m_State         = AsyncOP_State.WaitingForStart;
-            private Exception       m_pException    = null;
-            private SmartStream     m_pStream       = null;
-            private SmartStream     m_pOwner        = null;
-            private ReadLineAsyncOP m_pReadLineOP   = null;
-            private int             m_BytesWritten  = 0;
-            private bool            m_EndsCRLF      = false;
-            private bool            m_RiseCompleted = false;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="stream">Source stream. Reading starts from stream current location.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
-            public WritePeriodTerminatedAsyncOP(Stream stream)
-            {
-                if(stream == null){
-                    throw new ArgumentNullException("stream");
-                }
-
-                m_pStream = new SmartStream(stream,false);
-            }
-
-            #region method Dispose
-
-            /// <summary>
-            /// Cleans up any resources being used.
-            /// </summary>
-            public void Dispose()
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-                SetState(AsyncOP_State.Disposed);
-                
-                m_pException  = null;
-                m_pStream     = null;
-                m_pOwner      = null;
-                m_pReadLineOP = null;
-
-                this.CompletedAsync = null;
-            }
-
-            #endregion
-
-
-            #region method Start
-
-            /// <summary>
-            /// Starts operation processing.
-            /// </summary>
-            /// <param name="owner">Owner SmartStream.</param>
-            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
-            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception>
-            internal bool Start(SmartStream owner)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-
-                m_pOwner = owner;
-
-                SetState(AsyncOP_State.Active);
-
-                try{
-                    // Read line.
-                    m_pReadLineOP = new ReadLineAsyncOP(new byte[32000],SizeExceededAction.ThrowException);
-                    m_pReadLineOP.CompletedAsync += delegate(object s,EventArgs<ReadLineAsyncOP> e){
-                        ReadLineCompleted(m_pReadLineOP);
-                    };
-                    if(m_pStream.ReadLine(m_pReadLineOP,true)){
-                        ReadLineCompleted(m_pReadLineOP);
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    SetState(AsyncOP_State.Completed);
-                    m_pReadLineOP.Dispose();
-                }
-
-                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
-                // If already completed sync, that flag has no effect.
-                lock(m_pLock){
-                    m_RiseCompleted = true;
-
-                    return m_State == AsyncOP_State.Active;
-                }
-            }
-
-            #endregion
-
-
-            #region method SetState
-
-            /// <summary>
-            /// Sets operation state.
-            /// </summary>
-            /// <param name="state">New state.</param>
-            private void SetState(AsyncOP_State state)
-            {
-                if(m_State == AsyncOP_State.Disposed){
-                    return;
-                }
-
-                lock(m_pLock){
-                    m_State = state;
-
-                    if(m_State == AsyncOP_State.Completed && m_RiseCompleted){
-                        OnCompletedAsync();
-                    }
-                }
-            }
-
-            #endregion
-
-            #region method ReadLineCompleted
-
-            /// <summary>
-            /// Is called when source stream read line reading has completed.
-            /// </summary>
-            /// <param name="op">Asynchronous operation.</param>
-            private void ReadLineCompleted(ReadLineAsyncOP op)
-            {
-                try{
-                    if(op.Error != null){
-                        m_pException = op.Error;
-                        SetState(AsyncOP_State.Completed);
-                    }
-                    else{
-                        // We have readed all source stream data, we are done.
-                        if(op.BytesInBuffer == 0){
-                            // Line ends CRLF.
-                            if(m_EndsCRLF){
-                                m_BytesWritten += 3;
-                                m_pOwner.BeginWrite(new byte[]{(byte)'.',(byte)'\r',(byte)'\n'},0,3,this.SendTerminatorCompleted,null);
-                            }
-                            // Line doesn't end CRLF, we need to add it.
-                            else{
-                                m_BytesWritten += 5;
-                                m_pOwner.BeginWrite(new byte[]{(byte)'\r',(byte)'\n',(byte)'.',(byte)'\r',(byte)'\n'},0,5,this.SendTerminatorCompleted,null);
-                            }
-
-                            op.Dispose();
-                        }
-                        // Write readed line.
-                        else{
-                            m_BytesWritten += op.BytesInBuffer;
-
-                            // Check if line ends CRLF.
-                            if(op.BytesInBuffer >= 2 && op.Buffer[op.BytesInBuffer - 2] == '\r' && op.Buffer[op.BytesInBuffer - 1] == '\n'){
-                                m_EndsCRLF = true;
-                            }
-                            else{
-                                m_EndsCRLF = false;
-                            }
-
-                            // Period handling. If line starts with period(.), additional period is added.
-                            if(op.Buffer[0] == '.'){
-                                byte[] buffer = new byte[op.BytesInBuffer + 1];
-                                buffer[0] = (byte)'.';
-                                Array.Copy(op.Buffer,0,buffer,1,op.BytesInBuffer);
-
-                                m_pOwner.BeginWrite(buffer,0,buffer.Length,this.SendLineCompleted,null);
-                            }
-                            // Normal line.
-                            else{
-                                m_pOwner.BeginWrite(op.Buffer,0,op.BytesInBuffer,this.SendLineCompleted,null);
-                            }
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    SetState(AsyncOP_State.Completed);
-                    op.Dispose();
-                }
-            }
-
-            #endregion
-
-            #region method SendLineCompleted
-
-            /// <summary>
-            /// Is called when line sending has completed.
-            /// </summary>
-            /// <param name="ar">Asynchronous result.</param>
-            private void SendLineCompleted(IAsyncResult ar)
-            {
-                try{
-                    m_pOwner.EndWrite(ar);
-
-                    // Read next line.
-                    // We already have attahed m_pReadLineOP.Completed in start method, so skip it here.
-                    // m_pReadLineOP.Completed += delegate(object s,EventArgs<ReadLineAsyncOP> e){                        
-                    if(m_pStream.ReadLine(m_pReadLineOP,true)){
-                        ReadLineCompleted(m_pReadLineOP);
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    SetState(AsyncOP_State.Completed);
-                }
-            }
-
-            #endregion
-
-            #region method SendTerminatorCompleted
-
-            /// <summary>
-            /// Is called when ".CRLF" or "CRLF.CRLF" terminator sending has completed.
-            /// </summary>
-            /// <param name="ar">Asynchronous result.</param>
-            private void SendTerminatorCompleted(IAsyncResult ar)
-            {
-                try{
-                    m_pOwner.EndWrite(ar);                    
-                }
-                catch(Exception x){
-                    m_pException = x;
-                }
-
-                SetState(AsyncOP_State.Completed);
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets asynchronous operation state.
-            /// </summary>
-            public AsyncOP_State State
-            {
-                get{ return m_State; }
-            }
-
-            /// <summary>
-            /// Gets error happened during operation. Returns null if no error.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed other than <b>AsyncOP_State.Completed</b> state.</exception>
-            public Exception Error
-            {
-                get{ 
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("Property 'Error' is accessible only in 'AsyncOP_State.Completed' state.");
-                    }
-
-                    return m_pException; 
-                }
-            }
-
-            /// <summary>
-            /// Gets number of bytes written.
-            /// </summary>
-            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this property is accessed.</exception>
-            /// <exception cref="InvalidOperationException">Is raised when this property is accessed other than <b>AsyncOP_State.Completed</b> state.</exception>
-            public int BytesWritten
-            {
-                get{ 
-                    if(m_State == AsyncOP_State.Disposed){
-                        throw new ObjectDisposedException(this.GetType().Name);
-                    }
-                    if(m_State != AsyncOP_State.Completed){
-                        throw new InvalidOperationException("Property 'Socket' is accessible only in 'AsyncOP_State.Completed' state.");
-                    }
-                    if(m_pException != null){
-                        throw m_pException;
-                    }
-
-                    return m_BytesWritten; 
-                }
-            }
-
-            #endregion
-
-            #region Events implementation
-
-            /// <summary>
-            /// Is called when asynchronous operation has completed.
-            /// </summary>
-            public event EventHandler<EventArgs<WritePeriodTerminatedAsyncOP>> CompletedAsync = null;
-
-            #region method OnCompletedAsync
-
-            /// <summary>
-            /// Raises <b>CompletedAsync</b> event.
-            /// </summary>
-            private void OnCompletedAsync()
-            {
-                if(this.CompletedAsync != null){
-                    this.CompletedAsync(this,new EventArgs<WritePeriodTerminatedAsyncOP>(this));
-                }
-            }
-
-            #endregion
-
-            #endregion
-        }
-
-        #endregion
-
-        /// <summary>
-        /// Starts writing period handled and terminated data to this stream.
-        /// </summary>
-        /// <param name="op">Asynchronous operation.</param>
-        /// <returns>Returns true if aynchronous operation is pending (The <see cref="WritePeriodTerminatedAsyncOP.CompletedAsync"/> event is raised upon completion of the operation).
-        /// Returns false if operation completed synchronously.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
-        public bool WritePeriodTerminatedAsync(WritePeriodTerminatedAsyncOP op)
-        {
-            if(this.m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(op == null){
-                throw new ArgumentNullException("op");
-            }
-            if(op.State != AsyncOP_State.WaitingForStart){
-                throw new ArgumentException("Invalid argument 'op' state, 'op' must be in 'AsyncOP_State.WaitingForStart' state.","op");
-            }
-
-            return op.Start(this);
-        }
-
-        #endregion
-
-        #region method WriteHeader
-
-        /// <summary>
-        /// Reads header from source <b>stream</b> and writes it to stream.
-        /// </summary>
-        /// <param name="stream">Stream from where to read header.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception>
-        public void WriteHeader(Stream stream)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(stream == null){
-                throw new ArgumentNullException("stream");
-            }
-
-            SmartStream reader = new SmartStream(stream,false);
-            reader.ReadHeader(this,0,SizeExceededAction.ThrowException);
-        }
-
-        #endregion
-
-
-        #region override method Flush
-
-        /// <summary>
-        /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Flush()
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            m_pStream.Flush();
-        }
-
-        #endregion
-
-        #region override method Seek
-
-        /// <summary>
-        /// Sets the position within the current stream.
-        /// </summary>
-        /// <param name="offset">A byte offset relative to the <b>origin</b> parameter.</param>
-        /// <param name="origin">A value of type SeekOrigin indicating the reference point used to obtain the new position.</param>
-        /// <returns>The new position within the current stream.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override long Seek(long offset,SeekOrigin origin)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            return m_pStream.Seek(offset,origin);
-        }
-
-        #endregion
-
-        #region override method SetLength
-
-        /// <summary>
-        /// Sets the length of the current stream.
-        /// </summary>
-        /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void SetLength(long value)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-
-            m_pStream.SetLength(value);
-
-            // Clear read buffer.
-            m_ReadBufferOffset = 0;
-            m_ReadBufferCount  = 0;
-        }
-
-        #endregion
-                
-        #region override method BeginRead
-
-        /// <summary>
-        /// Begins an asynchronous read operation.
-        /// </summary>
-        /// <param name="buffer">The buffer to read the data into.</param>
-        /// <param name="offset">The byte offset in buffer at which to begin writing data read from the stream.</param>
-        /// <param name="count">The maximum number of bytes to read.</param>
-        /// <param name="callback">An optional asynchronous callback, to be called when the read is complete.</param>
-        /// <param name="state">A user-provided object that distinguishes this particular asynchronous read request from other requests.</param>
-        /// <returns>An IAsyncResult that represents the asynchronous read, which could still be pending.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
-        public override IAsyncResult BeginRead(byte[] buffer,int offset,int count,AsyncCallback callback,object state)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(offset > buffer.Length){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be < buffer.Length.");
-            }
-            if(count < 0){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' value must be >= 0.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' is bigger than than argument 'buffer' can store.");
-            }
-
-            return new ReadAsyncOperation(this,buffer,offset,count,callback,state);
-        }
-
-        #endregion
-
-        #region override method EndRead
-
-        /// <summary>
-        /// Handles the end of an asynchronous data reading.
-        /// </summary>
-        /// <param name="asyncResult">The reference to the pending asynchronous request to finish.</param>
-        /// <returns>The total number of bytes read into the <b>buffer</b>. This can be less than the number of bytes requested 
-        /// if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>asyncResult</b> is null reference.</exception>
-        public override int EndRead(IAsyncResult asyncResult)
-        {
-            if(asyncResult == null){
-                throw new ArgumentNullException("asyncResult");
-            }
-            if(!(asyncResult is ReadAsyncOperation)){
-                throw new ArgumentException("Argument 'asyncResult' was not returned by a call to the BeginRead method.");
-            }
-
-            ReadAsyncOperation ar = (ReadAsyncOperation)asyncResult;
-            if(ar.IsEndCalled){
-                throw new InvalidOperationException("EndRead is already called for specified 'asyncResult'.");
-            }
-            ar.AsyncWaitHandle.WaitOne();
-            ar.AsyncWaitHandle.Close();
-            ar.IsEndCalled = true;
-            
-            return ar.BytesStored;            
-        }
-
-        #endregion
-
-        #region override method Read
-
-        /// <summary>
-        /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
-        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
-        /// <returns>The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
-        public override int Read(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }            
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(count < 0){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' value must be >= 0.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' is bigger than than argument 'buffer' can store.");
-            }
-
-            if(this.BytesInReadBuffer == 0){
-                this.BufferRead(false,null);
-            }
-            
-            if(this.BytesInReadBuffer == 0){
-                return 0;
-            }
-            else{
-                int countToCopy = Math.Min(count,this.BytesInReadBuffer);
-                Array.Copy(m_pReadBuffer,m_ReadBufferOffset,buffer,offset,countToCopy);
-                m_ReadBufferOffset += countToCopy;
-
-                return countToCopy;
-            }
-        }
-
-        #endregion
-
-        #region override method BeginWrite
-
-        /// <summary>
-        /// Begins an asynchronous write operation.
-        /// </summary>
-        /// <param name="buffer">The buffer to write data from.</param>
-        /// <param name="offset">The byte offset in buffer from which to begin writing.</param>
-        /// <param name="count">The maximum number of bytes to write.</param>
-        /// <param name="callback">An optional asynchronous callback, to be called when the write is complete.</param>
-        /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param>
-        /// <returns>An IAsyncResult that represents the asynchronous write, which could still be pending.</returns>
-        /// /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
-        public override IAsyncResult BeginWrite(byte[] buffer,int offset,int count,AsyncCallback callback,object state)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }            
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(count < 0){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' value must be >= 0.");
-            }
-            if(offset + count > buffer.Length){
-                throw new ArgumentOutOfRangeException("count","Argument 'count' is bigger than than argument 'buffer' can store.");
-            }
-
-            m_LastActivity  = DateTime.Now;
-            m_BytesWritten += count;
-
-            return m_pStream.BeginWrite(buffer,offset,count,callback,state);
-        }
-
-        #endregion
-
-        #region override method EndWrite
-
-        /// <summary>
-        /// Ends an asynchronous write operation.
-        /// </summary>
-        /// <param name="asyncResult">A reference to the outstanding asynchronous I/O request.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>asyncResult</b> is null reference.</exception>
-        public override void EndWrite(IAsyncResult asyncResult)
-        {
-            if(asyncResult == null){
-                throw new ArgumentNullException("asyncResult");
-            }
-
-            m_pStream.EndWrite(asyncResult);
-        }
-
-        #endregion
-
-        #region override method Write
-
-        /// <summary>
-        /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
-        /// </summary>
-        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
-        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
-        /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        public override void Write(byte[] buffer,int offset,int count)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException("SmartStream");
-            }            
-
-            m_pStream.Write(buffer,offset,count);
-            
-            m_LastActivity = DateTime.Now;
-            m_BytesWritten += count;
-        }
-
-        #endregion
-
-
-        #region method BufferRead
-
-        /// <summary>
-        /// Begins buffering read-buffer.
-        /// </summary>
-        /// <param name="async">If true then this method can complete asynchronously. If false, this method completes always syncronously.</param>
-        /// <param name="asyncCallback">The callback that is executed when asynchronous operation completes. 
-        /// If operation completes synchronously, no callback called.</param>
-        /// <returns>
-        /// Returns true if asynchronous operation in progress or false if operation completed synchronously. 
-        /// </returns>
-        /// <exception cref="InvalidOperationException">Is raised when there is data in read buffer and this method is called.</exception>
-        private bool BufferRead(bool async,BufferCallback asyncCallback)
-        {
-            if(this.BytesInReadBuffer != 0){
-                throw new InvalidOperationException("There is already data in read buffer.");
-            }
-                        
-            m_ReadBufferOffset = 0;
-            m_ReadBufferCount  = 0;
-
-            #region async
-
-            if(async){
-                m_pReadBufferOP.ReleaseEvents();
-                m_pReadBufferOP.CompletedAsync += new EventHandler<EventArgs<BufferReadAsyncOP>>(delegate(object s,EventArgs<BufferReadAsyncOP> e){
-                    try{            
-                        if(e.Value.Error != null){
-                            if(asyncCallback != null){
-                                asyncCallback(e.Value.Error);
-                            }
-                        }
-                        else{
-                            m_ReadBufferOffset =  0;
-                            m_ReadBufferCount  =  e.Value.BytesInBuffer;
-                            m_BytesReaded      += e.Value.BytesInBuffer;
-                            m_LastActivity     =  DateTime.Now; 
-
-                            if(asyncCallback != null){
-                                asyncCallback(null);
-                            }
-                        }
-                    }
-                    catch(Exception x){
-                        if(asyncCallback != null){
-                            asyncCallback(x);
-                        }
-                    }
-                });
-                        
-                if(m_pReadBufferOP.Start(async,m_pReadBuffer,m_pReadBuffer.Length)){
-                    return true;
-                }
-                else{
-                    if(m_pReadBufferOP.Error != null){
-                        throw m_pReadBufferOP.Error;
-                    }
-                    else{
-                        m_ReadBufferOffset =  0;
-                        m_ReadBufferCount  =  m_pReadBufferOP.BytesInBuffer;
-                        m_BytesReaded      += m_pReadBufferOP.BytesInBuffer;
-                        m_LastActivity     =  DateTime.Now; 
-                    }
-
-                    return false;
-                }
-            }
-
-            #endregion
-
-            #region sync
-
-            else{
-                int countReaded = m_pStream.Read(m_pReadBuffer,0,m_pReadBuffer.Length);
-                m_ReadBufferCount  =  countReaded;
-                m_BytesReaded      += countReaded;
-                m_LastActivity     =  DateTime.Now;
-
-                return false;
-            }
-
-            #endregion                        
-        }
-
-        #endregion
-                
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets if this object is disposed.
-        /// </summary>
-        public bool IsDisposed
-        {
-            get{ return m_IsDisposed; }
-        }
-
-        /// <summary>
-        /// Gets line buffer size in bytes.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public int LineBufferSize
-        {
-            get{ 
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_BufferSize; 
-            }
-        }
-
-
-        /// <summary>
-        /// Gets this stream underlying stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public Stream SourceStream
-        {
-            get{ 
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream; 
-            }
-        }
-
-        /// <summary>
-        /// Gets if SmartStream is owner of source stream. This property affects like closing this stream will close SourceStream if IsOwner true.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public bool IsOwner
-        {
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_IsOwner; 
-            }
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                m_IsOwner = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets the last time when data was read or written.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public DateTime LastActivity
-        {
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_LastActivity; 
-            }
-        }
-
-        /// <summary>
-        /// Gets how many bytes are readed through this stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public long BytesReaded
-        {
-            get{ 
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_BytesReaded; 
-            }
-        }
-
-        /// <summary>
-        /// Gets how many bytes are written through this stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public long BytesWritten
-        {
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_BytesWritten;
-            }
-        }
-
-        /// <summary>
-        /// Gets number of bytes in read buffer.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public int BytesInReadBuffer
-        {
-            get{ 
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_ReadBufferCount - m_ReadBufferOffset; 
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets string related methods default encoding.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when null value is passed.</exception>
-        public Encoding Encoding
-        {
-            get{ 
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pEncoding; 
-            }
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-                if(value == null){
-                    throw new ArgumentNullException();
-                }
-
-                m_pEncoding = value;
-            }
-        }
-
-        /// <summary>
-        /// Gets or sets if only CRLF lines accepted. If false LF lines accepted. 
-        /// </summary>
-        public bool CRLFLines
-        {
-                get{ return m_CRLFLines; }
-
-                set { m_CRLFLines = value; }
-            }
-
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports reading.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanRead
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.CanRead;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports seeking.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanSeek
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.CanSeek;
-            } 
-        }
-
-        /// <summary>
-        /// Gets a value indicating whether the current stream supports writing.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override bool CanWrite
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.CanWrite;
-            } 
-        }
-
-        /// <summary>
-        /// Gets the length in bytes of the stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override long Length
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.Length;
-            } 
-        }
-
-        /// <summary>
-        /// Gets or sets the position within the current stream.
-        /// </summary>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this property is accessed.</exception>
-        public override long Position
-        { 
-            get{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                return m_pStream.Position;
-            } 
-
-            set{
-                if(m_IsDisposed){
-                    throw new ObjectDisposedException("SmartStream");
-                }
-
-                m_pStream.Position = value;
-
-                // Clear read buffer.
-                m_ReadBufferOffset = 0;
-                m_ReadBufferCount  = 0;
-            }
-        }
-
-        #endregion
-
-
-        //------- Obsolete
-
-        #region class ReadLineAsyncOperation
-
-        /// <summary>
-        /// This class implements asynchronous line reading.
-        /// </summary>
-        private class ReadLineAsyncOperation : IAsyncResult
-        {
-            private SmartStream        m_pOwner                 = null;
-            private byte[]             m_pBuffer                = null;
-            private int                m_OffsetInBuffer         = 0;
-            private int                m_MaxCount               = 0;
-            private SizeExceededAction m_SizeExceededAction     = SizeExceededAction.JunkAndThrowException;
-            private AsyncCallback      m_pAsyncCallback         = null;
-            private object             m_pAsyncState            = null;
-            private AutoResetEvent     m_pAsyncWaitHandle       = null;
-            private bool               m_CompletedSynchronously = false;
-            private bool               m_IsCompleted            = false;
-            private bool               m_IsEndCalled            = false;
-            private int                m_BytesReaded            = 0;
-            private int                m_BytesStored            = 0;
-            private Exception          m_pException             = null;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="owner">Owner stream.</param>
-            /// <param name="buffer">Buffer where to store data.</param>
-            /// <param name="offset">The location in <b>buffer</b> to begin storing the data.</param>
-            /// <param name="maxCount">Maximum number of bytes to read.</param>
-            /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
-            /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-            /// <param name="asyncState">User-defined object that qualifies or contains information about an asynchronous operation.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b>,<b>buffer</b> is null reference.</exception>
-            /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
-            public ReadLineAsyncOperation(SmartStream owner,byte[] buffer,int offset,int maxCount,SizeExceededAction exceededAction,AsyncCallback callback,object asyncState)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-                if(buffer == null){
-                    throw new ArgumentNullException("buffer");
-                }
-                if(offset < 0){
-                    throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-                }
-                if(offset > buffer.Length){
-                    throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be < buffer.Length.");
-                }
-                if(maxCount < 0){
-                    throw new ArgumentOutOfRangeException("maxCount","Argument 'maxCount' value must be >= 0.");
-                }
-                if(offset + maxCount > buffer.Length){
-                    throw new ArgumentOutOfRangeException("maxCount","Argument 'maxCount' is bigger than than argument 'buffer' can store.");
-                }
-
-                m_pOwner             = owner;
-                m_pBuffer            = buffer;
-                m_OffsetInBuffer     = offset;
-                m_MaxCount           = maxCount;
-                m_SizeExceededAction = exceededAction;
-                m_pAsyncCallback     = callback;
-                m_pAsyncState        = asyncState;
-
-                m_pAsyncWaitHandle = new AutoResetEvent(false);
-
-                DoLineReading();                                
-            }
-
-
-            #region method Buffering_Completed
-
-            /// <summary>
-            /// Is called when asynchronous read buffer buffering has completed.
-            /// </summary>
-            /// <param name="x">Exception that occured during async operation.</param>
-            private void Buffering_Completed(Exception x)
-            {
-                if(x != null){
-                    m_pException = x;
-                    Completed();
-                }
-                // We reached end of stream, no more data.
-                else if(m_pOwner.BytesInReadBuffer == 0){
-                    Completed();
-                }
-                // Continue line reading.
-                else{
-                    DoLineReading();
-                }
-            }
-
-            #endregion
-
-            #region method DoLineReading
-
-            /// <summary>
-            /// Does line reading.
-            /// </summary>
-            private void DoLineReading()
-            {           
-                try{
-                    while(true){
-                        // Read buffer empty, buff next data block.
-                        if(m_pOwner.BytesInReadBuffer == 0){
-                            // Buffering started asynchronously.
-                            if(m_pOwner.BufferRead(true,this.Buffering_Completed)){
-                                return;
-                            }
-                            // Buffering completed synchronously, continue processing.
-                            else{
-                                // We reached end of stream, no more data.
-                                if(m_pOwner.BytesInReadBuffer == 0){
-                                    Completed();
-                                    return;
-                                }
-                            }
-                        }
-
-                        byte b = m_pOwner.m_pReadBuffer[m_pOwner.m_ReadBufferOffset++];
-                        m_BytesReaded++;
-
-                        // We have LF line.
-                        if(b == '\n'){
-                            break;               
-                        }
-                        // We have CRLF line.
-                        else if(b == '\r' && m_pOwner.Peek() == '\n'){
-                            // Consume LF char.
-                            m_pOwner.ReadByte();
-                            m_BytesReaded++;
-
-                            break;
-                        }
-                        // We have CR line.
-                        else if(b == '\r'){
-                            break;
-                        }
-                        // We have normal line data char.
-                        else{
-                            // Line buffer full.
-                            if(m_BytesStored >= m_MaxCount){
-                                if(m_SizeExceededAction == SizeExceededAction.ThrowException){
-                                    throw new LineSizeExceededException();
-                                }
-                                // Just skip storing.
-                                else{
-                                }
-                            }
-                            else{
-                                m_pBuffer[m_OffsetInBuffer++] = b;
-                                m_BytesStored++;
-                            }
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;                    
-                }
-
-                Completed();
-            }
-
-            #endregion
-
-            #region method Completed
-
-            /// <summary>
-            /// This method must be called when asynchronous operation has completed.
-            /// </summary>
-            private void Completed()
-            {
-                m_IsCompleted = true;
-                m_pAsyncWaitHandle.Set();
-                if(m_pAsyncCallback != null){
-                    m_pAsyncCallback(this);
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
-            /// </summary>
-            public object AsyncState
-            {
-                get{ return m_pAsyncState; }
-            }
-
-            /// <summary>
-            /// Gets a WaitHandle that is used to wait for an asynchronous operation to complete.
-            /// </summary>
-            public WaitHandle AsyncWaitHandle
-            {
-                get{ return m_pAsyncWaitHandle; }
-            }
-
-            /// <summary>
-            /// Gets an indication of whether the asynchronous operation completed synchronously.
-            /// </summary>
-            public bool CompletedSynchronously
-            {
-                get{ return m_CompletedSynchronously; }
-            }
-
-            /// <summary>
-            /// Gets an indication whether the asynchronous operation has completed.
-            /// </summary>
-            public bool IsCompleted
-            {
-                get{ return m_IsCompleted; }
-            }
-
-
-            /// <summary>
-            /// Gets or sets if <b>EndReadLine</b> method is called for this asynchronous operation.
-            /// </summary>
-            internal bool IsEndCalled
-            {
-                get{ return m_IsEndCalled; }
-
-                set{ m_IsEndCalled = value; }
-            }
-
-            /// <summary>
-            /// Gets store buffer.
-            /// </summary>
-            internal byte[] Buffer
-            {
-                get{ return m_pBuffer; }
-            }
-
-            /// <summary>
-            /// Gets number of bytes readed from source stream.
-            /// </summary>
-            internal int BytesReaded
-            {
-                get{ return m_BytesReaded; }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored in to <b>Buffer</b>.
-            /// </summary>
-            internal int BytesStored
-            {
-                get{ return m_BytesStored; }
-            }
-
-            #endregion
-        }
-
-        #endregion
-
-        #region class ReadToTerminatorAsyncOperation
-
-        /// <summary>
-        /// This class implements asynchronous line-based terminated data reader, where terminator is on line itself.
-        /// </summary>
-        private class ReadToTerminatorAsyncOperation : IAsyncResult
-        {
-            private SmartStream        m_pOwner                 = null;
-            private string             m_Terminator             = "";
-            private byte[]             m_pTerminatorBytes       = null;
-            private Stream             m_pStoreStream           = null;
-            private long               m_MaxCount               = 0;            
-            private SizeExceededAction m_SizeExceededAction     = SizeExceededAction.JunkAndThrowException;
-            private AsyncCallback      m_pAsyncCallback         = null;
-            private object             m_pAsyncState            = null;
-            private AutoResetEvent     m_pAsyncWaitHandle       = null;
-            private bool               m_CompletedSynchronously = false;
-            private bool               m_IsCompleted            = false;
-            private bool               m_IsEndCalled            = false;
-            private byte[]             m_pLineBuffer            = null;
-            private long               m_BytesStored            = 0;
-            private Exception          m_pException             = null;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="owner">Owner stream.</param>
-            /// <param name="terminator">Data terminator.</param>
-            /// <param name="storeStream">Stream where to store readed header.</param>
-            /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
-            /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
-            /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-            /// <param name="asyncState">User-defined object that qualifies or contains information about an asynchronous operation.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b>,<b>terminator</b> or <b>storeStream</b> is null reference.</exception>
-            public ReadToTerminatorAsyncOperation(SmartStream owner,string terminator,Stream storeStream,long maxCount,SizeExceededAction exceededAction,AsyncCallback callback,object asyncState)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-                if(terminator == null){
-                    throw new ArgumentNullException("terminator");
-                }
-                if(storeStream == null){
-                    throw new ArgumentNullException("storeStream");
-                }
-                if(maxCount < 0){
-                    throw new ArgumentException("Argument 'maxCount' must be >= 0.");
-                }
-
-                m_pOwner             = owner;
-                m_Terminator         = terminator;
-                m_pTerminatorBytes   = Encoding.ASCII.GetBytes(terminator);
-                m_pStoreStream       = storeStream;
-                m_MaxCount           = maxCount;
-                m_SizeExceededAction = exceededAction;
-                m_pAsyncCallback     = callback;
-                m_pAsyncState        = asyncState;
-
-                m_pAsyncWaitHandle = new AutoResetEvent(false);
-
-                m_pLineBuffer = new byte[32000];
-
-                // Start reading data.
-                #pragma warning disable
-                m_pOwner.BeginReadLine(m_pLineBuffer,0,m_pLineBuffer.Length - 2,m_SizeExceededAction,new AsyncCallback(this.ReadLine_Completed),null);
-                #pragma warning restore
-            }
-
-
-            #region mehtod ReadLine_Completed
-
-            /// <summary>
-            /// This method is called when asyynchronous line reading has completed.
-            /// </summary>
-            /// <param name="asyncResult">An IAsyncResult that represents an asynchronous call.</param>
-            private void ReadLine_Completed(IAsyncResult asyncResult)
-            {
-                try{
-                    int storedCount = 0;                    
-                    try{
-                        #pragma warning disable
-                        storedCount = m_pOwner.EndReadLine(asyncResult);
-                        #pragma warning restore
-                    }
-                    catch(LineSizeExceededException lx){
-                        if(m_SizeExceededAction == SizeExceededAction.ThrowException){
-                            throw lx;
-                        }
-                        m_pException = new LineSizeExceededException();
-                        storedCount = 32000 - 2;
-                    }
-
-                    // Source stream closed berore we reached terminator.
-                    if(storedCount == -1){
-                        throw new IncompleteDataException();
-                    }
-
-                    // Check for terminator.
-                    if(Net_Utils.CompareArray(m_pTerminatorBytes,m_pLineBuffer,storedCount)){
-                        Completed();
-                    }
-                    else{
-                        // We have exceeded maximum allowed data count.
-                        if(m_MaxCount > 0 && (m_BytesStored + storedCount + 2) > m_MaxCount){
-                            if(m_SizeExceededAction == SizeExceededAction.ThrowException){
-                                throw new DataSizeExceededException();
-                            }
-                            // Just skip storing.
-                            else{
-                                m_pException = new DataSizeExceededException();
-                            }
-                        }
-                        else{
-                            // Store readed line.
-                            m_pLineBuffer[storedCount++] = (byte)'\r';
-                            m_pLineBuffer[storedCount++] = (byte)'\n';
-                            m_pStoreStream.Write(m_pLineBuffer,0,storedCount);
-                            m_BytesStored += storedCount;                           
-                        }
-
-                        // Strart reading new line.
-                        #pragma warning disable
-                        m_pOwner.BeginReadLine(m_pLineBuffer,0,m_pLineBuffer.Length - 2,m_SizeExceededAction,new AsyncCallback(this.ReadLine_Completed),null);
-                        #pragma warning restore
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    Completed();                
-                }
-            }
-
-            #endregion
-
-            #region method Completed
-
-            /// <summary>
-            /// This method must be called when asynchronous operation has completed.
-            /// </summary>
-            private void Completed()
-            {
-                m_IsCompleted = true;
-                m_pAsyncWaitHandle.Set();
-                if(m_pAsyncCallback != null){
-                    m_pAsyncCallback(this);
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets terminator.
-            /// </summary>
-            public string Terminator
-            {
-                get{ return m_Terminator; }
-            }
-
-            /// <summary>
-            /// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
-            /// </summary>
-            public object AsyncState
-            {
-                get{ return m_pAsyncState; }
-            }
-
-            /// <summary>
-            /// Gets a WaitHandle that is used to wait for an asynchronous operation to complete.
-            /// </summary>
-            public WaitHandle AsyncWaitHandle
-            {
-                get{ return m_pAsyncWaitHandle; }
-            }
-
-            /// <summary>
-            /// Gets an indication of whether the asynchronous operation completed synchronously.
-            /// </summary>
-            public bool CompletedSynchronously
-            {
-                get{ return m_CompletedSynchronously; }
-            }
-
-            /// <summary>
-            /// Gets an indication whether the asynchronous operation has completed.
-            /// </summary>
-            public bool IsCompleted
-            {
-                get{ return m_IsCompleted; }
-            }
-
-
-            /// <summary>
-            /// Gets or sets if <b>EndReadLine</b> method is called for this asynchronous operation.
-            /// </summary>
-            internal bool IsEndCalled
-            {
-                get{ return m_IsEndCalled; }
-
-                set{ m_IsEndCalled = value; }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored in to <b>storeStream</b>.
-            /// </summary>
-            internal long BytesStored
-            {
-                get{ return m_BytesStored; }
-            }
-
-            /// <summary>
-            /// Gets exception happened on asynchronous operation. Returns null if operation was successfull.
-            /// </summary>
-            internal Exception Exception
-            {
-                get{ return m_pException; }
-            }
-
-            #endregion
-
-        }
-
-        #endregion
-
-        #region class ReadToStreamAsyncOperation
-
-        /// <summary>
-        /// This class implements asynchronous read to stream data reader.
-        /// </summary>
-        private class ReadToStreamAsyncOperation : IAsyncResult
-        {
-            private SmartStream        m_pOwner                 = null;
-            private Stream             m_pStoreStream           = null;
-            private long               m_Count                  = 0;
-            private AsyncCallback      m_pAsyncCallback         = null;
-            private object             m_pAsyncState            = null;
-            private AutoResetEvent     m_pAsyncWaitHandle       = null;
-            private bool               m_CompletedSynchronously = false;
-            private bool               m_IsCompleted            = false;
-            private bool               m_IsEndCalled            = false;
-            private long               m_BytesStored            = 0;
-            private Exception          m_pException             = null;
-
-            /// <summary>
-            /// Default constructor.
-            /// </summary>
-            /// <param name="owner">Owner stream.</param>
-            /// <param name="storeStream">Stream where to store readed data.</param>
-            /// <param name="count">Number of bytes to read from source stream.</param>
-            /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-            /// <param name="asyncState">User-defined object that qualifies or contains information about an asynchronous operation.</param>
-            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> or <b>storeStream</b> is null reference.</exception>
-            /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-            public ReadToStreamAsyncOperation(SmartStream owner,Stream storeStream,long count,AsyncCallback callback,object asyncState)
-            {
-                if(owner == null){
-                    throw new ArgumentNullException("owner");
-                }
-                if(storeStream == null){
-                    throw new ArgumentNullException("storeStream");
-                }
-                if(count < 0){
-                    throw new ArgumentException("Argument 'count' must be >= 0.");
-                }
-
-                m_pOwner             = owner;
-                m_pStoreStream       = storeStream;
-                m_Count              = count;
-                m_pAsyncCallback     = callback;
-                m_pAsyncState        = asyncState;
-
-                m_pAsyncWaitHandle = new AutoResetEvent(false);
-
-                if(m_Count == 0){
-                    Completed();                    
-                }
-                else{
-                    DoDataReading();
-                }
-            }
-
-
-            #region method Buffering_Completed
-
-            /// <summary>
-            /// Is called when asynchronous read buffer buffering has completed.
-            /// </summary>
-            /// <param name="x">Exception that occured during async operation.</param>
-            private void Buffering_Completed(Exception x)
-            {
-                if(x != null){
-                    m_pException = x;
-                    Completed();
-                }
-                // We reached end of stream, no more data.
-                else if(m_pOwner.BytesInReadBuffer == 0){
-                    m_pException = new IncompleteDataException();
-                    Completed();
-                }
-                // Continue line reading.
-                else{
-                    DoDataReading();
-                }
-            }
-
-            #endregion
-
-            #region method DoReading
-
-            /// <summary>
-            /// Does data reading.
-            /// </summary>
-            private void DoDataReading()
-            {
-                try{
-                    while(true){
-                        // Read buffer empty, buff next data block.
-                        if(m_pOwner.BytesInReadBuffer == 0){
-                            // Buffering started asynchronously.
-                            if(m_pOwner.BufferRead(true,this.Buffering_Completed)){
-                                return;
-                            }
-                            // Buffering completed synchronously, continue processing.
-                            else{
-                                // We reached end of stream, no more data.
-                                if(m_pOwner.BytesInReadBuffer == 0){
-                                    throw new IncompleteDataException();
-                                }
-                            }
-                        }
-                                       
-                        int countToRead = (int)Math.Min(m_Count - m_BytesStored,m_pOwner.BytesInReadBuffer);                
-                        m_pStoreStream.Write(m_pOwner.m_pReadBuffer,m_pOwner.m_ReadBufferOffset,countToRead);
-                        m_BytesStored += countToRead;
-                        m_pOwner.m_ReadBufferOffset += countToRead; 
-
-                        // We have readed all data.
-                        if(m_Count == m_BytesStored){
-                            Completed();
-                            return;
-                        }
-                    }
-                }
-                catch(Exception x){
-                    m_pException = x;
-                    Completed();
-                }
-            }
-
-            #endregion
-
-            #region method Completed
-
-            /// <summary>
-            /// This method must be called when asynchronous operation has completed.
-            /// </summary>
-            private void Completed()
-            {
-                m_IsCompleted = true;
-                m_pAsyncWaitHandle.Set();
-                if(m_pAsyncCallback != null){
-                    m_pAsyncCallback(this);
-                }
-            }
-
-            #endregion
-
-
-            #region Properties implementation
-
-            /// <summary>
-            /// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
-            /// </summary>
-            public object AsyncState
-            {
-                get{ return m_pAsyncState; }
-            }
-
-            /// <summary>
-            /// Gets a WaitHandle that is used to wait for an asynchronous operation to complete.
-            /// </summary>
-            public WaitHandle AsyncWaitHandle
-            {
-                get{ return m_pAsyncWaitHandle; }
-            }
-
-            /// <summary>
-            /// Gets an indication of whether the asynchronous operation completed synchronously.
-            /// </summary>
-            public bool CompletedSynchronously
-            {
-                get{ return m_CompletedSynchronously; }
-            }
-
-            /// <summary>
-            /// Gets an indication whether the asynchronous operation has completed.
-            /// </summary>
-            public bool IsCompleted
-            {
-                get{ return m_IsCompleted; }
-            }
-
-
-            /// <summary>
-            /// Gets or sets if <b>EndReadLine</b> method is called for this asynchronous operation.
-            /// </summary>
-            internal bool IsEndCalled
-            {
-                get{ return m_IsEndCalled; }
-
-                set{ m_IsEndCalled = value; }
-            }
-
-            /// <summary>
-            /// Gets number of bytes stored in to <b>storeStream</b>.
-            /// </summary>
-            internal long BytesStored
-            {
-                get{ return m_BytesStored; }
-            }
-
-            /// <summary>
-            /// Gets exception happened on asynchronous operation. Returns null if operation was successfull.
-            /// </summary>
-            internal Exception Exception
-            {
-                get{ return m_pException; }
-            }
-
-            #endregion
-
-        }
-
-        #endregion
-
-        
-        #region method BeginReadLine
-
-        /// <summary>
-        /// Begins an asynchronous line reading from the source stream.
-        /// </summary>
-        /// <param name="buffer">Buffer where to store readed line data.</param>
-        /// <param name="offset">The location in <b>buffer</b> to begin storing the data.</param>
-        /// <param name="maxCount">Maximum number of bytes to read.</param>
-        /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
-        /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
-        /// <param name="state">An object that contains any additional user-defined data.</param>
-        /// <returns>An IAsyncResult that represents the asynchronous call.</returns>
-        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
-        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
-        /// <exception cref="ArgumentOutOfRangeException">is raised when any of the arguments has invalid value.</exception>
-        [Obsolete("Use method 'ReadLine' instead.")]
-        public IAsyncResult BeginReadLine(byte[] buffer,int offset,int maxCount,SizeExceededAction exceededAction,AsyncCallback callback,object state)
-        {
-            if(m_IsDisposed){
-                throw new ObjectDisposedException(this.GetType().Name);
-            }
-            if(buffer == null){
-                throw new ArgumentNullException("buffer");
-            }
-            if(offset < 0){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be >= 0.");
-            }
-            if(offset > buffer.Length){
-                throw new ArgumentOutOfRangeException("offset","Argument 'offset' value must be < buffer.Length.");
-            }
-            if(maxCount < 0){
-                throw new ArgumentOutOfRangeException("maxCount","Argument 'maxCount' value must be >= 0.");
-            }
-            if(offset + maxCount > buffer.Length){
-                throw new ArgumentOutOfRangeException("maxCount","Argument 'maxCount' is bigger than than argument 'buffer' can store.");
-            }
-
-            return new ReadLineAsyncOperation(this,buffer,offset,maxCount,exceededAction,callback,state);
-        }
-
-        #endregion
-
-        #region method EndReadLine
-
-        /// <summary>
-        /// Handles the end of an asynchronous line reading.
-        /// </summary>
-        /// <param name="asyncResult">An IAsyncResult that represents an asynchronous call.</param>
-        /// <returns>Returns number of bytes stored to <b>buffer</b>. Returns -1 if no more data, end of stream reached.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>asyncResult</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when invalid <b>asyncResult</b> passed to this method.</exception>
-        /// <exception cref="InvalidOperationException">Is raised when <b>EndReadLine</b> has already been called for specified <b>asyncResult</b>.</exception>
-        /// <exception cref="LineSizeExceededException">Is raised when <b>maxCount</b> value is exceeded.</exception>        
-        [Obsolete("Use method 'ReadLine' instead.")]
-        public int EndReadLine(IAsyncResult asyncResult)
-        {
-            if(asyncResult == null){
-                throw new ArgumentNullException("asyncResult");
-            }
-            if(!(asyncResult is ReadLineAsyncOperation)){
-                throw new ArgumentException("Argument 'asyncResult' was not returned by a call to the BeginReadLine method.");
-            }
-
-            ReadLineAsyncOperation ar = (ReadLineAsyncOperation)asyncResult;
-            if(ar.IsEndCalled){
-                throw new InvalidOperationException("EndReadLine is already called for specified 'asyncResult'.");
-            }
-            ar.AsyncWaitHandle.WaitOne();
-            ar.AsyncWaitHandle.Close();
-            ar.IsEndCalled = true;
-            
-            if(ar.BytesReaded == 0){
-                return -1;
-            }
-            else{
-                return ar.BytesStored;
-            }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 958
NatTypeTester/3rd/Net/Net_Utils.cs

@@ -1,958 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using System.Net;
-using System.Net.Sockets;
-
-using LumiSoft.Net.IO;
-
-namespace LumiSoft.Net
-{
-    /// <summary>
-    /// Common utility methods.
-    /// </summary>
-    public class Net_Utils
-    {
-        #region static method GetLocalHostName
-
-        /// <summary>
-        /// Gets local host name or argument <b>hostName</b> value if it's specified.
-        /// </summary>
-        /// <param name="hostName">Host name or null.</param>
-        /// <returns>Returns local host name or argument <b>hostName</b> value if it's specified.</returns>
-        public static string GetLocalHostName(string hostName)
-        {
-            if(string.IsNullOrEmpty(hostName)){
-                return System.Net.Dns.GetHostName();
-            }
-            else{
-                return hostName;
-            }
-        }
-
-        #endregion
-
-        #region static method CompareArray
-
-        /// <summary>
-        /// Compares if specified array itmes equals.
-        /// </summary>
-        /// <param name="array1">Array 1.</param>
-        /// <param name="array2">Array 2</param>
-        /// <returns>Returns true if both arrays are equal.</returns>
-        public static bool CompareArray(Array array1,Array array2)
-        {
-            return CompareArray(array1,array2,array2.Length);
-        }
-
-        /// <summary>
-        /// Compares if specified array itmes equals.
-        /// </summary>
-        /// <param name="array1">Array 1.</param>
-        /// <param name="array2">Array 2</param>
-        /// <param name="array2Count">Number of bytes in array 2 used for compare.</param>
-        /// <returns>Returns true if both arrays are equal.</returns>
-        public static bool CompareArray(Array array1,Array array2,int array2Count)
-        {
-            if(array1 == null && array2 == null){
-                return true;
-            }
-            if(array1 == null && array2 != null){
-                return false;
-            }
-            if(array1 != null && array2 == null){
-                return false;
-            }            
-            if(array1.Length != array2Count){
-                return false;
-            }
-            else{
-                for(int i=0;i<array1.Length;i++){
-                    if(!array1.GetValue(i).Equals(array2.GetValue(i))){
-                        return false;
-                    }
-                }
-            }
-
-            return true;
-        }
-
-        #endregion
-
-        #region static method ReverseArray
-
-        /// <summary>
-        /// Reverses the specified array elements.
-        /// </summary>
-        /// <param name="array">Array elements to reverse.</param>
-        /// <returns>Returns array with reversed items.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>array</b> is null.</exception>
-        public static Array ReverseArray(Array array)
-        {
-            if(array == null){
-                throw new ArgumentNullException("array");
-            }
-
-            Array.Reverse(array);
-
-            return array;
-        }
-
-        #endregion
-
-        #region static method ArrayToString
-
-        /// <summary>
-        /// Convert array elements to string.
-        /// </summary>
-        /// <param name="values">String values.</param>
-        /// <param name="delimiter">Values delimiter.</param>
-        /// <returns>Returns array elements as string.</returns>
-        public static string ArrayToString(string[] values,string delimiter)
-        {
-            if(values == null){
-                return "";
-            }
-
-            StringBuilder retVal = new StringBuilder();
-            for(int i=0;i<values.Length;i++){
-                if(i > 0){
-                    retVal.Append(delimiter);
-                }
-
-                retVal.Append(values[i]);
-            }
-
-            return retVal.ToString();
-        }
-
-        #endregion
-
-        #region static method StreamCopy
-
-        /// <summary>
-        /// Copies <b>source</b> stream data to <b>target</b> stream.
-        /// </summary>
-        /// <param name="source">Source stream. Reading starts from stream current position.</param>
-        /// <param name="target">Target stream. Writing starts from stream current position.</param>
-        /// <param name="blockSize">Specifies transfer block size in bytes.</param>
-        /// <returns>Returns number of bytes copied.</returns>
-        public static long StreamCopy(Stream source,Stream target,int blockSize)
-        {
-            if(source == null){
-                throw new ArgumentNullException("source");
-            }
-            if(target == null){
-                throw new ArgumentNullException("target");
-            }
-            if(blockSize < 1024){
-                throw new ArgumentException("Argument 'blockSize' value must be >= 1024.");
-            }
-
-            byte[] buffer      = new byte[blockSize];
-            long   totalReaded = 0;            
-            while(true){
-                int readedCount = source.Read(buffer,0,buffer.Length);
-                // We reached end of stream, we readed all data sucessfully.
-                if(readedCount == 0){
-                    return totalReaded;
-                }
-                else{
-                    target.Write(buffer,0,readedCount);
-                    totalReaded += readedCount;
-                }
-            }
-        }
-
-        #endregion
-
-
-        #region static method CompareIP
-
-        /// <summary>
-        /// Compares 2 IP addresses. Returns 0 if IPs are equal, 
-        /// returns positive value if destination IP is bigger than source IP,
-        /// returns negative value if destination IP is smaller than source IP.
-        /// </summary>
-        /// <param name="source">Source IP address.</param>
-        /// <param name="destination">Destination IP address.</param>
-        /// <returns>Returns 0 if IPs are equal, 
-        /// returns positive value if destination IP is bigger than source IP,
-        /// returns negative value if destination IP is smaller than source IP.
-        /// </returns>
-        public static int CompareIP(IPAddress source,IPAddress destination)
-        {
-            byte[] sourceIpBytes      = source.GetAddressBytes();
-            byte[] destinationIpBytes = destination.GetAddressBytes();
-
-            // IPv4 and IPv6
-            if(sourceIpBytes.Length < destinationIpBytes.Length){
-                return 1;
-            }
-            // IPv6 and IPv4
-            else if(sourceIpBytes.Length > destinationIpBytes.Length){
-                return -1;
-            }
-            // IPv4 and IPv4 OR IPv6 and IPv6
-            else{                
-                for(int i=0;i<sourceIpBytes.Length;i++){
-                    if(sourceIpBytes[i] < destinationIpBytes[i]){
-                        return 1;
-                    }
-                    else if(sourceIpBytes[i] > destinationIpBytes[i]){
-                        return -1;
-                    }
-                }
-
-                return 0;
-            }
-        }
-
-        #endregion
-
-        #region static method IsIPAddress
-
-        /// <summary>
-        /// Gets if the specified string value is IP address.
-        /// </summary>
-        /// <param name="value">Value to check.</param>
-        /// <returns>Returns true if specified value is IP address.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
-        public static bool IsIPAddress(string value)
-        {
-            if(value == null){
-                throw new ArgumentNullException("value");
-            }
-
-            IPAddress ip = null;
-
-            return IPAddress.TryParse(value,out ip);
-        }
-
-        #endregion
-
-        #region static method IsMulticastAddress
-
-        /// <summary>
-        /// Gets if the specified IP address is multicast address.
-        /// </summary>
-        /// <param name="ip">IP address.</param>
-        /// <returns>Returns true if <b>ip</b> is muticast address, otherwise false.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>ip</b> s null reference.</exception>
-        public static bool IsMulticastAddress(IPAddress ip)
-        {
-            if(ip == null){
-                throw new ArgumentNullException("ip");
-            }
-
-            // IPv4 multicast 224.0.0.0 to 239.255.255.255
-
-            if(ip.IsIPv6Multicast){
-                return true;
-            }
-            else if(ip.AddressFamily == AddressFamily.InterNetwork){
-                byte[] bytes = ip.GetAddressBytes();
-                if(bytes[0] >= 224 && bytes[0] <= 239){
-                    return true;
-                }
-            }
-
-            return false;
-        }
-
-        #endregion
-
-        #region static method IsPrivateIP
-
-        /// <summary>
-        /// Gets if specified IP address is private LAN IP address. For example 192.168.x.x is private ip.
-        /// </summary>
-        /// <param name="ip">IP address to check.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>ip</b> is null reference.</exception>
-        /// <returns>Returns true if IP is private IP.</returns>
-        public static bool IsPrivateIP(string ip)
-        {
-            if(ip == null){
-                throw new ArgumentNullException("ip");
-            }
-
-            return IsPrivateIP(IPAddress.Parse(ip));
-        }
-
-        /// <summary>
-        /// Gets if specified IP address is private LAN IP address. For example 192.168.x.x is private ip.
-        /// </summary>
-        /// <param name="ip">IP address to check.</param>
-        /// <returns>Returns true if IP is private IP.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>ip</b> is null reference.</exception>
-        public static bool IsPrivateIP(IPAddress ip)
-        {
-            if(ip == null){
-                throw new ArgumentNullException("ip");
-            }
-
-			if(ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork){
-				byte[] ipBytes = ip.GetAddressBytes();
-
-				/* Private IPs:
-					First Octet = 192 AND Second Octet = 168 (Example: 192.168.X.X) 
-					First Octet = 172 AND (Second Octet >= 16 AND Second Octet <= 31) (Example: 172.16.X.X - 172.31.X.X)
-					First Octet = 10 (Example: 10.X.X.X)
-					First Octet = 169 AND Second Octet = 254 (Example: 169.254.X.X)
-
-				*/
-
-				if(ipBytes[0] == 192 && ipBytes[1] == 168){
-					return true;
-				}
-				if(ipBytes[0] == 172 && ipBytes[1] >= 16 && ipBytes[1] <= 31){
-					return true;
-				}
-				if(ipBytes[0] == 10){
-					return true;
-				}
-				if(ipBytes[0] == 169 && ipBytes[1] == 254){
-					return true;
-				}
-			}
-
-			return false;
-        }
-
-        #endregion
-
-        #region static method ParseIPEndPoint
-
-        /// <summary>
-        /// Parses IPEndPoint from the specified string value.
-        /// </summary>
-        /// <param name="value">IPEndPoint string value.</param>
-        /// <returns>Returns parsed IPEndPoint.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        public static IPEndPoint ParseIPEndPoint(string value)
-        {
-            if(value == null){
-                throw new ArgumentNullException("value");
-            }
-
-            try{
-                string[] ip_port = value.Split(':');
-
-                return new IPEndPoint(IPAddress.Parse(ip_port[0]),Convert.ToInt32(ip_port[1]));
-            }
-            catch(Exception x){
-                throw new ArgumentException("Invalid IPEndPoint value.","value",x);
-            }
-        }
-
-        #endregion
-
-
-        #region static method IsInteger
-
-		/// <summary>
-		/// Checks if specified string is integer(int/long).
-		/// </summary>
-		/// <param name="value"></param>
-		/// <returns>Returns true if specified string is integer.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
-		public static bool IsInteger(string value)
-		{
-            if(value == null){
-                throw new ArgumentNullException("value");
-            }
-
-            long l = 0;
-
-            return long.TryParse(value,out l);
-		}
-
-		#endregion
-
-        #region static method IsAscii
-
-        /// <summary>
-        /// Gets if the specified string is ASCII string.
-        /// </summary>
-        /// <param name="value">String value.</param>
-        /// <returns>Returns true if specified string is ASCII string, otherwise false.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception>
-        public static bool IsAscii(string value)
-        {
-            if(value == null){
-                throw new ArgumentNullException("value");
-            }
-
-            foreach(char c in value){
-				if((int)c > 127){ 
-					return false;
-				}
-			}
-
-			return true;
-        }
-
-        #endregion
-
-               
-        #region static method IsSocketAsyncSupported
-
-        /// <summary>
-        /// Gets if socket async methods supported by OS.
-        /// </summary>
-        /// <returns>returns ture if supported, otherwise false.</returns>
-        public static bool IsSocketAsyncSupported()
-        {
-            try{                            
-                using(SocketAsyncEventArgs e = new SocketAsyncEventArgs()){
-                    return true;
-                }
-            }
-            catch(NotSupportedException nX){
-                string dummy = nX.Message;
-                
-                return false;
-            }
-        }
-
-        #endregion
-
-        #region static method CreateSocket
-
-        /// <summary>
-        /// Creates new socket for the specified end point.
-        /// </summary>
-        /// <param name="localEP">Local end point.</param>
-        /// <param name="protocolType">Protocol type.</param>
-        /// <returns>Retruns newly created socket.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>localEP</b> is null reference.</exception>
-        public static Socket CreateSocket(IPEndPoint localEP,ProtocolType protocolType)
-        {
-            if(localEP == null){
-                throw new ArgumentNullException("localEP");
-            }
-
-            SocketType socketType = SocketType.Stream;
-            if(protocolType == ProtocolType.Udp){
-                socketType = SocketType.Dgram;
-            }
-                        
-            if(localEP.AddressFamily == AddressFamily.InterNetwork){
-                Socket socket = new Socket(AddressFamily.InterNetwork,socketType,protocolType);
-                socket.Bind(localEP);
-
-                return socket;
-            }
-            else if(localEP.AddressFamily == AddressFamily.InterNetworkV6){
-                Socket socket = new Socket(AddressFamily.InterNetworkV6,socketType,protocolType);
-                socket.Bind(localEP);
-
-                return socket;
-            }
-            else{
-                throw new ArgumentException("Invalid IPEndPoint address family.");
-            }
-        }
-
-        #endregion
-
-
-        #region static method ToHex
-
-        /// <summary>
-		/// Converts specified data to HEX string.
-		/// </summary>
-		/// <param name="data">Data to convert.</param>
-		/// <returns>Returns hex string.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
-		public static string ToHex(byte[] data)
-		{
-            if(data == null){
-                throw new ArgumentNullException("data");
-            }
-
-			return BitConverter.ToString(data).ToLower().Replace("-","");
-		}
-
-		/// <summary>
-		/// Converts specified string to HEX string.
-		/// </summary>
-		/// <param name="text">String to convert.</param>
-		/// <returns>Returns hex string.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>text</b> is null reference.</exception>
-		public static string ToHex(string text)
-		{
-            if(text == null){
-                throw new ArgumentNullException("text");
-            }
-
-			return BitConverter.ToString(Encoding.Default.GetBytes(text)).ToLower().Replace("-","");
-		}
-
-		#endregion
-
-        #region static method FromHex
-
-		/// <summary>
-		/// Converts hex byte data to normal byte data. Hex data must be in two bytes pairs, for example: 0F,FF,A3,... .
-		/// </summary>
-		/// <param name="hexData">Hex data.</param>
-		/// <returns>Returns decoded data.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>hexData</b> is null reference.</exception>
-		public static byte[] FromHex(byte[] hexData)
-		{
-            if(hexData == null){
-                throw new ArgumentNullException("hexData");
-            }
-
-			if(hexData.Length < 2 || (hexData.Length / (double)2 != Math.Floor(hexData.Length / (double)2))){
-				throw new Exception("Illegal hex data, hex data must be in two bytes pairs, for example: 0F,FF,A3,... .");
-			}
-
-			MemoryStream retVal = new MemoryStream(hexData.Length / 2);
-			// Loop hex value pairs
-			for(int i=0;i<hexData.Length;i+=2){
-				byte[] hexPairInDecimal = new byte[2];
-				// We need to convert hex char to decimal number, for example F = 15
-				for(int h=0;h<2;h++){
-					if(((char)hexData[i + h]) == '0'){
-						hexPairInDecimal[h] = 0;
-					}
-					else if(((char)hexData[i + h]) == '1'){
-						hexPairInDecimal[h] = 1;
-					}
-					else if(((char)hexData[i + h]) == '2'){
-						hexPairInDecimal[h] = 2;
-					}
-					else if(((char)hexData[i + h]) == '3'){
-						hexPairInDecimal[h] = 3;
-					}
-					else if(((char)hexData[i + h]) == '4'){
-						hexPairInDecimal[h] = 4;
-					}
-					else if(((char)hexData[i + h]) == '5'){
-						hexPairInDecimal[h] = 5;
-					}
-					else if(((char)hexData[i + h]) == '6'){
-						hexPairInDecimal[h] = 6;
-					}
-					else if(((char)hexData[i + h]) == '7'){
-						hexPairInDecimal[h] = 7;
-					}
-					else if(((char)hexData[i + h]) == '8'){
-						hexPairInDecimal[h] = 8;
-					}
-					else if(((char)hexData[i + h]) == '9'){
-						hexPairInDecimal[h] = 9;
-					}
-					else if(((char)hexData[i + h]) == 'A' || ((char)hexData[i + h]) == 'a'){
-						hexPairInDecimal[h] = 10;
-					}
-					else if(((char)hexData[i + h]) == 'B' || ((char)hexData[i + h]) == 'b'){
-						hexPairInDecimal[h] = 11;
-					}
-					else if(((char)hexData[i + h]) == 'C' || ((char)hexData[i + h]) == 'c'){
-						hexPairInDecimal[h] = 12;
-					}
-					else if(((char)hexData[i + h]) == 'D' || ((char)hexData[i + h]) == 'd'){
-						hexPairInDecimal[h] = 13;
-					}
-					else if(((char)hexData[i + h]) == 'E' || ((char)hexData[i + h]) == 'e'){
-						hexPairInDecimal[h] = 14;
-					}
-					else if(((char)hexData[i + h]) == 'F' || ((char)hexData[i + h]) == 'f'){
-						hexPairInDecimal[h] = 15;
-					}
-				}
-
-				// Join hex 4 bit(left hex cahr) + 4bit(right hex char) in bytes 8 it
-				retVal.WriteByte((byte)((hexPairInDecimal[0] << 4) | hexPairInDecimal[1]));
-			}
-
-			return retVal.ToArray();
-		}
-
-		#endregion
-
-
-        #region static method FromBase64
-
-        /// <summary>
-        /// Decodes specified base64 data.
-        /// </summary>
-        /// <param name="data">Base64 string.</param>
-        /// <returns>Returns decoded data.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
-        public static byte[] FromBase64(string data)
-        {
-            if(data == null){
-                throw new ArgumentNullException("data");
-            }
-
-            Base64 base64 = new Base64();
-
-            return base64.Decode(data,true);
-        }
-
-        /// <summary>
-        /// Decodes specified base64 data.
-        /// </summary>
-        /// <param name="data">Base64 data.</param>
-        /// <returns>Returns decoded data.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
-        public static byte[] FromBase64(byte[] data)
-        {
-            if(data == null){
-                throw new ArgumentNullException("data");
-            }
-
-            Base64 base64 = new Base64();
-
-            return base64.Decode(data,0,data.Length,true);
-        }
-
-        #endregion
-
-        #region static method Base64Encode
-
-        /// <summary>
-		/// Encodes specified data with base64 encoding.
-		/// </summary>
-		/// <param name="data">Data to encode.</param>
-		/// <returns></returns>
-		public static byte[] Base64Encode(byte[] data)
-		{
-			return Base64EncodeEx(data,null,true);
-		}
-
-		/// <summary>
-		/// Encodes specified data with bas64 encoding.
-		/// </summary>
-		/// <param name="data">Data to to encode.</param>
-		/// <param name="base64Chars">Custom base64 chars (64 chars) or null if default chars used.</param>
-		/// <param name="padd">Padd missing block chars. Normal base64 must be 4 bytes blocks, if not 4 bytes in block, 
-		/// missing bytes must be padded with '='. Modified base64 just skips missing bytes.</param>
-		/// <returns></returns>
-		public static byte[] Base64EncodeEx(byte[] data,char[] base64Chars,bool padd)
-		{
-			/* RFC 2045 6.8.  Base64 Content-Transfer-Encoding
-			
-				Base64 is processed from left to right by 4 6-bit byte block, 4 6-bit byte block 
-				are converted to 3 8-bit bytes.
-				If base64 4 byte block doesn't have 3 8-bit bytes, missing bytes are marked with =. 
-				
-			
-				Value Encoding  Value Encoding  Value Encoding  Value Encoding
-					0 A            17 R            34 i            51 z
-					1 B            18 S            35 j            52 0
-					2 C            19 T            36 k            53 1
-					3 D            20 U            37 l            54 2
-					4 E            21 V            38 m            55 3
-					5 F            22 W            39 n            56 4
-					6 G            23 X            40 o            57 5
-					7 H            24 Y            41 p            58 6
-					8 I            25 Z            42 q            59 7
-					9 J            26 a            43 r            60 8
-					10 K           27 b            44 s            61 9
-					11 L           28 c            45 t            62 +
-					12 M           29 d            46 u            63 /
-					13 N           30 e            47 v
-					14 O           31 f            48 w         (pad) =
-					15 P           32 g            49 x
-					16 Q           33 h            50 y
-					
-				NOTE: 4 base64 6-bit bytes = 3 8-bit bytes				
-					// |    6-bit    |    6-bit    |    6-bit    |    6-bit    |
-					// | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 |
-					// |    8-bit         |    8-bit        |    8-bit         |
-			*/
-
-			if(base64Chars != null && base64Chars.Length != 64){
-				throw new Exception("There must be 64 chars in base64Chars char array !");
-			}
-
-			if(base64Chars == null){
-				base64Chars = new char[]{
-					'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
-					'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
-					'0','1','2','3','4','5','6','7','8','9','+','/'
-				};
-			}
-
-			// Convert chars to bytes
-			byte[] base64LoockUpTable = new byte[64];
-			for(int i=0;i<64;i++){
-				base64LoockUpTable[i] = (byte)base64Chars[i];
-			}
-						
-			int encodedDataLength = (int)Math.Ceiling((data.Length * 8) / (double)6);
-			// Retrun value won't be interegral 4 block, but has less. Padding requested, padd missing with '='
-			if(padd && (encodedDataLength / (double)4 != Math.Ceiling(encodedDataLength / (double)4))){
-				encodedDataLength += (int)(Math.Ceiling(encodedDataLength / (double)4) * 4) - encodedDataLength;
-			}
-
-			// See how many line brakes we need
-			int numberOfLineBreaks = 0;
-			if(encodedDataLength > 76){
-				numberOfLineBreaks = (int)Math.Ceiling(encodedDataLength / (double)76) - 1;
-			}
-
-			// Construc return valu buffer
-			byte[] retVal = new byte[encodedDataLength + (numberOfLineBreaks * 2)];  // * 2 - CRLF
-
-			int lineBytes = 0;
-			// Loop all 3 bye blocks
-			int position = 0; 
-			for(int i=0;i<data.Length;i+=3){
-				// Do line splitting
-				if(lineBytes >= 76){
-					retVal[position + 0] = (byte)'\r';
-					retVal[position + 1] = (byte)'\n';					
-					position += 2;
-					lineBytes = 0;
-				}
-
-				// Full 3 bytes data block
-				if((data.Length - i) >= 3){
-					retVal[position + 0] = base64LoockUpTable[data[i + 0] >> 2];
-					retVal[position + 1] = base64LoockUpTable[(data[i + 0] & 0x3) << 4 | data[i + 1] >> 4];
-					retVal[position + 2] = base64LoockUpTable[(data[i + 1] & 0xF) << 2 | data[i + 2] >> 6];
-					retVal[position + 3] = base64LoockUpTable[data[i + 2] & 0x3F];
-					position += 4;
-					lineBytes += 4;
-				}
-				// 2 bytes data block, left (last block)
-				else if((data.Length - i) == 2){
-					retVal[position + 0] = base64LoockUpTable[data[i + 0] >> 2];
-					retVal[position + 1] = base64LoockUpTable[(data[i + 0] & 0x3) << 4 | data[i + 1] >> 4];
-					retVal[position + 2] = base64LoockUpTable[(data[i + 1] & 0xF) << 2];					
-					if(padd){
-						retVal[position + 3] = (byte)'=';
-					}
-				}
-				// 1 bytes data block, left (last block)
-				else if((data.Length - i) == 1){
-					retVal[position + 0] = base64LoockUpTable[data[i + 0] >> 2];
-					retVal[position + 1] = base64LoockUpTable[(data[i + 0] & 0x3) << 4];					
-					if(padd){
-						retVal[position + 2] = (byte)'=';
-						retVal[position + 3] = (byte)'=';
-					}
-				}
-			}
-
-			return retVal;
-		}
-
-		#endregion
-
-		#region static method Base64Decode
-        
-		/// <summary>
-		/// Decodes base64 data. Defined in RFC 2045 6.8.  Base64 Content-Transfer-Encoding.
-		/// </summary>
-		/// <param name="base64Data">Base64 decoded data.</param>
-		/// <param name="base64Chars">Custom base64 chars (64 chars) or null if default chars used.</param>
-		/// <returns></returns>
-		public static byte[] Base64DecodeEx(byte[] base64Data,char[] base64Chars)
-		{
-			/* RFC 2045 6.8.  Base64 Content-Transfer-Encoding
-			
-				Base64 is processed from left to right by 4 6-bit byte block, 4 6-bit byte block 
-				are converted to 3 8-bit bytes.
-				If base64 4 byte block doesn't have 3 8-bit bytes, missing bytes are marked with =. 
-				
-			
-				Value Encoding  Value Encoding  Value Encoding  Value Encoding
-					0 A            17 R            34 i            51 z
-					1 B            18 S            35 j            52 0
-					2 C            19 T            36 k            53 1
-					3 D            20 U            37 l            54 2
-					4 E            21 V            38 m            55 3
-					5 F            22 W            39 n            56 4
-					6 G            23 X            40 o            57 5
-					7 H            24 Y            41 p            58 6
-					8 I            25 Z            42 q            59 7
-					9 J            26 a            43 r            60 8
-					10 K           27 b            44 s            61 9
-					11 L           28 c            45 t            62 +
-					12 M           29 d            46 u            63 /
-					13 N           30 e            47 v
-					14 O           31 f            48 w         (pad) =
-					15 P           32 g            49 x
-					16 Q           33 h            50 y
-					
-				NOTE: 4 base64 6-bit bytes = 3 8-bit bytes				
-					// |    6-bit    |    6-bit    |    6-bit    |    6-bit    |
-					// | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 | 1 2 3 4 5 6 |
-					// |    8-bit         |    8-bit        |    8-bit         |
-			*/
-			
-			if(base64Chars != null && base64Chars.Length != 64){
-				throw new Exception("There must be 64 chars in base64Chars char array !");
-			}
-
-			if(base64Chars == null){
-				base64Chars = new char[]{
-					'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
-					'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
-					'0','1','2','3','4','5','6','7','8','9','+','/'
-				};
-			}
-
-			//--- Create decode table ---------------------//
-			byte[] decodeTable = new byte[128];
-			for(int i=0;i<128;i++){
-				int mappingIndex = -1;
-				for(int bc=0;bc<base64Chars.Length;bc++){
-					if(i == base64Chars[bc]){
-						mappingIndex = bc;
-						break;
-					}
-				}
-
-				if(mappingIndex > -1){
-					decodeTable[i] = (byte)mappingIndex;
-				}
-				else{
-					decodeTable[i] = 0xFF;
-				}
-			}
-			//---------------------------------------------//
-
-			byte[] decodedDataBuffer  = new byte[((base64Data.Length * 6) / 8) + 4];
-			int    decodedBytesCount  = 0;
-			int    nByteInBase64Block = 0;
-			byte[] decodedBlock       = new byte[3];
-			byte[] base64Block        = new byte[4];
-
-			for(int i=0;i<base64Data.Length;i++){
-				byte b = base64Data[i];
-
-				// Read 4 byte base64 block and process it 			
-				// Any characters outside of the base64 alphabet are to be ignored in base64-encoded data.
-
-				// Padding char
-				if(b == '='){
-					base64Block[nByteInBase64Block] = 0xFF;
-				}
-				else{
-					byte decodeByte = decodeTable[b & 0x7F];
-					if(decodeByte != 0xFF){
-						base64Block[nByteInBase64Block] = decodeByte;
-						nByteInBase64Block++;
-					}
-				}
-
-                /* Check if we can decode some bytes. 
-                 * We must have full 4 byte base64 block or reached at the end of data.
-                 */
-                int encodedBytesCount = -1;
-                // We have full 4 byte base64 block
-                if(nByteInBase64Block == 4){
-                    encodedBytesCount = 3;
-                }
-                // We have reached at the end of base64 data, there may be some bytes left
-                else if(i == base64Data.Length - 1){
-                    // Invalid value, we can't have only 6 bit, just skip 
-                    if(nByteInBase64Block == 1){
-                        encodedBytesCount = 0;
-                    }
-                    // There is 1 byte in two base64 bytes (6 + 2 bit)
-                    else if(nByteInBase64Block == 2){
-                        encodedBytesCount = 1;
-                    }
-                    // There are 2 bytes in two base64 bytes ([6 + 2],[4 + 4] bit)
-                    else if(nByteInBase64Block == 3){
-                        encodedBytesCount = 2;
-                    }
-                }
-
-                // We have some bytes available to decode, decode them
-                if(encodedBytesCount > -1){
-                    decodedDataBuffer[decodedBytesCount + 0] = (byte)((int)base64Block[0] << 2         | (int)base64Block[1] >> 4);
-					decodedDataBuffer[decodedBytesCount + 1] = (byte)(((int)base64Block[1] & 0xF) << 4 | (int)base64Block[2] >> 2);
-					decodedDataBuffer[decodedBytesCount + 2] = (byte)(((int)base64Block[2] & 0x3) << 6 | (int)base64Block[3] >> 0);
-
-                    // Increase decoded bytes count
-					decodedBytesCount += encodedBytesCount;
-
-                    // Reset this block, reade next if there is any
-					nByteInBase64Block = 0;
-                }
-			}
-
-			// There is some decoded bytes, construct return value
-			if(decodedBytesCount > -1){
-				byte[] retVal = new byte[decodedBytesCount];
-				Array.Copy(decodedDataBuffer,0,retVal,0,decodedBytesCount);
-				return retVal;
-			}
-			// There is no decoded bytes
-			else{
-				return new byte[0];
-			}
-		}
-
-		#endregion
-
-
-        #region static method ComputeMd5
-
-        /// <summary>
-        /// Computes md5 hash.
-        /// </summary>
-        /// <param name="text">Text to hash.</param>
-        /// <param name="hex">Specifies if md5 value is returned as hex string.</param>
-        /// <returns>Returns md5 value or md5 hex value.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>text</b> is null reference.</exception>
-        public static string ComputeMd5(string text,bool hex)
-        {
-            if(text == null){
-                throw new ArgumentNullException("text");
-            }
-
-            using(System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider()) {
-                byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
-
-                if(hex){
-			        return ToHex(hash).ToLower();
-                }
-                else{
-                    return System.Text.Encoding.Default.GetString(hash);
-                }
-            }
-        }
-
-        #endregion
-
-
-        //--- Obsolete ------------------------------------------------------------------
-        
-        #region static method IsIoCompletionPortsSupported
-
-        /// <summary>
-        /// Gets if IO completion ports supported by OS.
-        /// </summary>
-        /// <returns></returns>
-        [Obsolete("Use method 'IsSocketAsyncSupported' instead.")]
-        public static bool IsIoCompletionPortsSupported()
-        {
-            try{                            
-                using(SocketAsyncEventArgs e = new SocketAsyncEventArgs()){
-                    return true;
-                }
-            }
-            catch(NotSupportedException nX){
-                string dummy = nX.Message;
-                
-                return false;
-            }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 426
NatTypeTester/3rd/Net/STUN/Client/STUN_Client.cs

@@ -1,426 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using System.Net;
-using System.Net.Sockets;
-
-using LumiSoft.Net.STUN.Message;
-
-namespace LumiSoft.Net.STUN.Client
-{
-    /// <summary>
-    /// This class implements STUN client. Defined in RFC 3489.
-    /// </summary>
-    /// <example>
-    /// <code>
-    /// // Create new socket for STUN client.
-    /// Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
-    /// socket.Bind(new IPEndPoint(IPAddress.Any,0));
-    /// 
-    /// // Query STUN server
-    /// STUN_Result result = STUN_Client.Query("stun.ekiga.net",3478,socket);
-    /// if(result.NetType != STUN_NetType.UdpBlocked){
-    ///     // UDP blocked or !!!! bad STUN server
-    /// }
-    /// else{
-    ///     IPEndPoint publicEP = result.PublicEndPoint;
-    ///     // Do your stuff
-    /// }
-    /// </code>
-    /// </example>
-    public class STUN_Client
-    {
-        #region static method Query
-
-        /// <summary>
-        /// Gets NAT info from STUN server.
-        /// </summary>
-        /// <param name="host">STUN server name or IP.</param>
-        /// <param name="port">STUN server port. Default port is 3478.</param>
-        /// <param name="localEP">Local IP end point.</param>
-        /// <returns>Returns UDP netwrok info.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>host</b> or <b>localEP</b> is null reference.</exception>
-        /// <exception cref="Exception">Throws exception if unexpected error happens.</exception>
-        public static STUN_Result Query(string host,int port,IPEndPoint localEP)
-        {
-            if(host == null){
-                throw new ArgumentNullException("host");
-            }
-            if(localEP == null){
-                throw new ArgumentNullException("localEP");
-            }
-
-            using(Socket s = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp)){
-                s.Bind(localEP);
-
-                return Query(host,port,s);
-            }
-        }
-
-        /// <summary>
-        /// Gets NAT info from STUN server.
-        /// </summary>
-        /// <param name="host">STUN server name or IP.</param>
-        /// <param name="port">STUN server port. Default port is 3478.</param>
-        /// <param name="socket">UDP socket to use.</param>
-        /// <returns>Returns UDP netwrok info.</returns>
-        /// <exception cref="Exception">Throws exception if unexpected error happens.</exception>
-        public static STUN_Result Query(string host,int port,Socket socket)
-        {
-            if(host == null){
-                throw new ArgumentNullException("host");
-            }
-            if(socket == null){
-                throw new ArgumentNullException("socket");
-            }
-            if(port < 1){
-                throw new ArgumentException("Port value must be >= 1 !");
-            }
-            if(socket.ProtocolType != ProtocolType.Udp){
-                throw new ArgumentException("Socket must be UDP socket !");
-            }
-
-            IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.Dns.GetHostAddresses(host)[0],port);
-            
-            /*
-                In test I, the client sends a STUN Binding Request to a server, without any flags set in the
-                CHANGE-REQUEST attribute, and without the RESPONSE-ADDRESS attribute. This causes the server 
-                to send the response back to the address and port that the request came from.
-            
-                In test II, the client sends a Binding Request with both the "change IP" and "change port" flags
-                from the CHANGE-REQUEST attribute set.  
-              
-                In test III, the client sends a Binding Request with only the "change port" flag set.
-                          
-                                    +--------+
-                                    |  Test  |
-                                    |   I    |
-                                    +--------+
-                                         |
-                                         |
-                                         V
-                                        /\              /\
-                                     N /  \ Y          /  \ Y             +--------+
-                      UDP     <-------/Resp\--------->/ IP \------------->|  Test  |
-                      Blocked         \ ?  /          \Same/              |   II   |
-                                       \  /            \? /               +--------+
-                                        \/              \/                    |
-                                                         | N                  |
-                                                         |                    V
-                                                         V                    /\
-                                                     +--------+  Sym.      N /  \
-                                                     |  Test  |  UDP    <---/Resp\
-                                                     |   II   |  Firewall   \ ?  /
-                                                     +--------+              \  /
-                                                         |                    \/
-                                                         V                     |Y
-                              /\                         /\                    |
-               Symmetric  N  /  \       +--------+   N  /  \                   V
-                  NAT  <--- / IP \<-----|  Test  |<--- /Resp\               Open
-                            \Same/      |   I    |     \ ?  /               Internet
-                             \? /       +--------+      \  /
-                              \/                         \/
-                              |                           |Y
-                              |                           |
-                              |                           V
-                              |                           Full
-                              |                           Cone
-                              V              /\
-                          +--------+        /  \ Y
-                          |  Test  |------>/Resp\---->Restricted
-                          |   III  |       \ ?  /
-                          +--------+        \  /
-                                             \/
-                                              |N
-                                              |       Port
-                                              +------>Restricted
-
-            */
-
-            try{
-                // Test I
-                STUN_Message test1 = new STUN_Message();
-                test1.Type = STUN_MessageType.BindingRequest;
-                STUN_Message test1response = DoTransaction(test1,socket,remoteEndPoint,1600);
-    
-                // UDP blocked.
-                if(test1response == null){
-                    return new STUN_Result(STUN_NetType.UdpBlocked,null);
-                }
-                else{
-                    // Test II
-                    STUN_Message test2 = new STUN_Message();
-                    test2.Type = STUN_MessageType.BindingRequest;
-                    test2.ChangeRequest = new STUN_t_ChangeRequest(true,true);
-
-                    // No NAT.
-                    if(socket.LocalEndPoint.Equals(test1response.MappedAddress)){
-                        STUN_Message test2Response = DoTransaction(test2,socket,remoteEndPoint,1600);
-                        // Open Internet.
-                        if(test2Response != null){
-                            return new STUN_Result(STUN_NetType.OpenInternet,test1response.MappedAddress);
-                        }
-                        // Symmetric UDP firewall.
-                        else{
-                            return new STUN_Result(STUN_NetType.SymmetricUdpFirewall,test1response.MappedAddress);
-                        }
-                    }
-                    // NAT
-                    else{
-                        STUN_Message test2Response = DoTransaction(test2,socket,remoteEndPoint,1600);
-            
-                        // Full cone NAT.
-                        if(test2Response != null){
-                            return new STUN_Result(STUN_NetType.FullCone,test1response.MappedAddress);
-                        }
-                        else{
-                            /*
-                                If no response is received, it performs test I again, but this time, does so to 
-                                the address and port from the CHANGED-ADDRESS attribute from the response to test I.
-                            */
-
-                            // Test I(II)
-                            STUN_Message test12 = new STUN_Message();
-                            test12.Type = STUN_MessageType.BindingRequest;
-
-                            STUN_Message test12Response = DoTransaction(test12,socket,test1response.ChangedAddress,1600);
-                            if(test12Response == null){
-                                throw new Exception("STUN Test I(II) dind't get resonse !");
-                            }
-                            else{
-                                // Symmetric NAT
-                                if(!test12Response.MappedAddress.Equals(test1response.MappedAddress)){
-                                    return new STUN_Result(STUN_NetType.Symmetric,test1response.MappedAddress);
-                                }
-                                else{
-                                    // Test III
-                                    STUN_Message test3 = new STUN_Message();
-                                    test3.Type = STUN_MessageType.BindingRequest;
-                                    test3.ChangeRequest = new STUN_t_ChangeRequest(false,true);
-
-                                    STUN_Message test3Response = DoTransaction(test3,socket,test1response.ChangedAddress,1600);
-                                    // Restricted
-                                    if(test3Response != null){
-                                        return new STUN_Result(STUN_NetType.RestrictedCone,test1response.MappedAddress);
-                                    }
-                                    // Port restricted
-                                    else{
-                                        return new STUN_Result(STUN_NetType.PortRestrictedCone,test1response.MappedAddress);
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            finally{
-                // Junk all late responses.
-                DateTime startTime = DateTime.Now;
-                while(startTime.AddMilliseconds(200) > DateTime.Now){
-                    // We got response.
-                    if(socket.Poll(1,SelectMode.SelectRead)){
-                        byte[] receiveBuffer = new byte[512];
-                        socket.Receive(receiveBuffer);
-                    }
-                }
-            }
-        }
-
-        #endregion
-
-        #region method GetPublicIP
-
-        /// <summary>
-        /// Resolves local IP to public IP using STUN.
-        /// </summary>
-        /// <param name="stunServer">STUN server.</param>
-        /// <param name="port">STUN server port. Default port is 3478.</param>
-        /// <param name="localIP">Local IP address.</param>
-        /// <returns>Returns public IP address.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stunServer</b> or <b>localIP</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="IOException">Is raised when no connection to STUN server.</exception>
-        public static IPAddress GetPublicIP(string stunServer,int port,IPAddress localIP)
-        {
-            if(stunServer == null){
-                throw new ArgumentNullException("stunServer");
-            }
-            if(stunServer == ""){
-                throw new ArgumentException("Argument 'stunServer' value must be specified.");
-            }
-            if(port < 1){
-                throw new ArgumentException("Invalid argument 'port' value.");
-            }
-            if(localIP == null){
-                throw new ArgumentNullException("localIP");
-            }
-
-            if(!Net_Utils.IsPrivateIP(localIP)){
-                return localIP;
-            }
-                        
-            STUN_Result result = Query(stunServer,port,Net_Utils.CreateSocket(new IPEndPoint(localIP,0),ProtocolType.Udp));
-            if(result.PublicEndPoint != null){
-                return result.PublicEndPoint.Address;
-            }
-            else{
-                throw new IOException("Failed to STUN public IP address. STUN server name is invalid or firewall blocks STUN.");
-            }
-        }
-
-        #endregion
-
-        #region method GetPublicEP
-
-        /// <summary>
-        /// Resolves socket local end point to public end point.
-        /// </summary>
-        /// <param name="stunServer">STUN server.</param>
-        /// <param name="port">STUN server port. Default port is 3478.</param>
-        /// <param name="socket">UDP socket to use.</param>
-        /// <returns>Returns public IP end point.</returns>
-        /// <exception cref="ArgumentNullException">Is raised when <b>stunServer</b> or <b>socket</b> is null reference.</exception>
-        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
-        /// <exception cref="IOException">Is raised when no connection to STUN server.</exception>
-        public static IPEndPoint GetPublicEP(string stunServer,int port,Socket socket)
-        {
-            if(stunServer == null){
-                throw new ArgumentNullException("stunServer");
-            }
-            if(stunServer == ""){
-                throw new ArgumentException("Argument 'stunServer' value must be specified.");
-            }
-            if(port < 1){
-                throw new ArgumentException("Invalid argument 'port' value.");
-            }
-            if(socket == null){
-                throw new ArgumentNullException("socket");
-            }
-            if(socket.ProtocolType != ProtocolType.Udp){
-                throw new ArgumentException("Socket must be UDP socket !");
-            }
-
-            IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.Dns.GetHostAddresses(stunServer)[0],port);
-
-            try{
-                // Test I
-                STUN_Message test1 = new STUN_Message();
-                test1.Type = STUN_MessageType.BindingRequest;
-                STUN_Message test1response = DoTransaction(test1,socket,remoteEndPoint,1000);
-    
-                // UDP blocked.
-                if(test1response == null){
-                    throw new IOException("Failed to STUN public IP address. STUN server name is invalid or firewall blocks STUN.");
-                }
-
-                return test1response.SourceAddress;
-            }
-            catch{
-                throw new IOException("Failed to STUN public IP address. STUN server name is invalid or firewall blocks STUN.");
-            }
-            finally{
-                // Junk all late responses.
-                DateTime startTime = DateTime.Now;
-                while(startTime.AddMilliseconds(200) > DateTime.Now){
-                    // We got response.
-                    if(socket.Poll(1,SelectMode.SelectRead)){
-                        byte[] receiveBuffer = new byte[512];
-                        socket.Receive(receiveBuffer);
-                    }
-                }
-            }
-        }
-
-        #endregion
-
-
-        #region method GetSharedSecret
-
-        private void GetSharedSecret()
-        {
-            /*
-                *) Open TLS connection to STUN server.
-                *) Send Shared Secret request.
-            */
-
-            /*
-            using(SocketEx socket = new SocketEx()){
-                socket.RawSocket.ReceiveTimeout = 5000;
-                socket.RawSocket.SendTimeout = 5000;
-
-                socket.Connect(host,port);
-                socket.SwitchToSSL_AsClient();                
-
-                // Send Shared Secret request.
-                STUN_Message sharedSecretRequest = new STUN_Message();
-                sharedSecretRequest.Type = STUN_MessageType.SharedSecretRequest;
-                socket.Write(sharedSecretRequest.ToByteData());
-                
-                // TODO: Parse message
-
-                // We must get  "Shared Secret" or "Shared Secret Error" response.
-
-                byte[] receiveBuffer = new byte[256];
-                socket.RawSocket.Receive(receiveBuffer);
-
-                STUN_Message sharedSecretRequestResponse = new STUN_Message();
-                if(sharedSecretRequestResponse.Type == STUN_MessageType.SharedSecretResponse){
-                }
-                // Shared Secret Error or Unknown response, just try again.
-                else{
-                    // TODO: Unknown response
-                }
-            }*/
-        }
-
-        #endregion
-
-        #region method DoTransaction
-
-        /// <summary>
-        /// Does STUN transaction. Returns transaction response or null if transaction failed.
-        /// </summary>
-        /// <param name="request">STUN message.</param>
-        /// <param name="socket">Socket to use for send/receive.</param>
-        /// <param name="remoteEndPoint">Remote end point.</param>
-        /// <param name="timeout">Timeout in milli seconds.</param>
-        /// <returns>Returns transaction response or null if transaction failed.</returns>
-        private static STUN_Message DoTransaction(STUN_Message request,Socket socket,IPEndPoint remoteEndPoint,int timeout)
-        {                        
-            byte[] requestBytes = request.ToByteData();                              
-            DateTime startTime = DateTime.Now;
-            // Retransmit with 500 ms.
-            while(startTime.AddMilliseconds(timeout) > DateTime.Now){
-                try{
-                    socket.SendTo(requestBytes,remoteEndPoint);
-
-                    // We got response.
-                    if(socket.Poll(500 * 1000,SelectMode.SelectRead)){
-                        byte[] receiveBuffer = new byte[512];
-                        socket.Receive(receiveBuffer);
-
-                        // Parse message
-                        STUN_Message response = new STUN_Message();
-                        response.Parse(receiveBuffer);
-                
-                        // Check that transaction ID matches or not response what we want.
-                        if(Net_Utils.CompareArray(request.TransactionID,response.TransactionID)){                            
-                            return response;
-                        }
-                    }
-                }
-                catch{
-                }
-            }
-
-            return null;
-        }
-
-        #endregion
-
-
-        // TODO: Update to RFC 5389
-
-    }
-}

+ 0 - 59
NatTypeTester/3rd/Net/STUN/Client/STUN_NetType.cs

@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.STUN.Client
-{
-    /// <summary>
-    /// Specifies UDP network type.
-    /// </summary>
-    public enum STUN_NetType
-    {
-        /// <summary>
-        /// UDP is always blocked.
-        /// </summary>
-        UdpBlocked,
-
-        /// <summary>
-        /// No NAT, public IP, no firewall.
-        /// </summary>
-        OpenInternet,
-
-        /// <summary>
-        /// No NAT, public IP, but symmetric UDP firewall.
-        /// </summary>
-        SymmetricUdpFirewall,
-
-        /// <summary>
-        /// A full cone NAT is one where all requests from the same internal IP address and port are 
-        /// mapped to the same external IP address and port. Furthermore, any external host can send 
-        /// a packet to the internal host, by sending a packet to the mapped external address.
-        /// </summary>
-        FullCone,
-
-        /// <summary>
-        /// A restricted cone NAT is one where all requests from the same internal IP address and 
-        /// port are mapped to the same external IP address and port. Unlike a full cone NAT, an external
-        /// host (with IP address X) can send a packet to the internal host only if the internal host 
-        /// had previously sent a packet to IP address X.
-        /// </summary>
-        RestrictedCone,
-
-        /// <summary>
-        /// A port restricted cone NAT is like a restricted cone NAT, but the restriction 
-        /// includes port numbers. Specifically, an external host can send a packet, with source IP
-        /// address X and source port P, to the internal host only if the internal host had previously 
-        /// sent a packet to IP address X and port P.
-        /// </summary>
-        PortRestrictedCone,
-
-        /// <summary>
-        /// A symmetric NAT is one where all requests from the same internal IP address and port, 
-        /// to a specific destination IP address and port, are mapped to the same external IP address and
-        /// port.  If the same host sends a packet with the same source address and port, but to 
-        /// a different destination, a different mapping is used. Furthermore, only the external host that
-        /// receives a packet can send a UDP packet back to the internal host.
-        /// </summary>
-        Symmetric
-    }
-}

+ 0 - 49
NatTypeTester/3rd/Net/STUN/Client/STUN_Result.cs

@@ -1,49 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Net;
-
-namespace LumiSoft.Net.STUN.Client
-{
-    /// <summary>
-    /// This class holds STUN_Client.Query method return data.
-    /// </summary>
-    public class STUN_Result
-    {
-        private STUN_NetType m_NetType         = STUN_NetType.OpenInternet;
-        private IPEndPoint   m_pPublicEndPoint = null;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="netType">Specifies UDP network type.</param>
-        /// <param name="publicEndPoint">Public IP end point.</param>
-        public STUN_Result(STUN_NetType netType,IPEndPoint publicEndPoint)
-        {            
-            m_NetType = netType;
-            m_pPublicEndPoint = publicEndPoint;
-        }
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets UDP network type.
-        /// </summary>
-        public STUN_NetType NetType
-        {
-            get{ return m_NetType; }
-        }
-
-        /// <summary>
-        /// Gets public IP end point. This value is null if failed to get network type.
-        /// </summary>
-        public IPEndPoint PublicEndPoint
-        {
-            get{ return m_pPublicEndPoint; }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 706
NatTypeTester/3rd/Net/STUN/Message/STUN_Message.cs

@@ -1,706 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using System.Net;
-
-namespace LumiSoft.Net.STUN.Message
-{
-    /// <summary>
-    /// Implements STUN message. Defined in RFC 3489.
-    /// </summary>
-    public class STUN_Message
-    {
-        #region enum AttributeType
-
-        /// <summary>
-        /// Specifies STUN attribute type.
-        /// </summary>
-        private enum AttributeType
-        {
-            MappedAddress    = 0x0001,
-            ResponseAddress  = 0x0002,
-            ChangeRequest    = 0x0003,
-            SourceAddress    = 0x0004,
-            ChangedAddress   = 0x0005,
-            Username         = 0x0006,
-            Password         = 0x0007,
-            MessageIntegrity = 0x0008,
-            ErrorCode        = 0x0009,
-            UnknownAttribute = 0x000A,
-            ReflectedFrom    = 0x000B,
-            XorMappedAddress = 0x8020,
-            XorOnly          = 0x0021,
-            ServerName       = 0x8022,
-        }
-
-        #endregion
-
-        #region enum IPFamily
-
-        /// <summary>
-        /// Specifies IP address family.
-        /// </summary>
-        private enum IPFamily
-        {
-            IPv4 = 0x01,
-            IPv6 = 0x02,
-        }
-
-        #endregion
-
-        private STUN_MessageType     m_Type             = STUN_MessageType.BindingRequest;
-        private int                  m_MagicCookie      = 0;
-        private byte[]               m_pTransactionID   = null;
-        private IPEndPoint           m_pMappedAddress   = null;
-        private IPEndPoint           m_pResponseAddress = null;
-        private STUN_t_ChangeRequest m_pChangeRequest   = null;
-        private IPEndPoint           m_pSourceAddress   = null;
-        private IPEndPoint           m_pChangedAddress  = null;
-        private string               m_UserName         = null;
-        private string               m_Password         = null;
-        private STUN_t_ErrorCode     m_pErrorCode       = null;
-        private IPEndPoint           m_pReflectedFrom   = null;
-        private string               m_ServerName       = null;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public STUN_Message()
-        {
-            m_pTransactionID = new byte[12];
-            new Random().NextBytes(m_pTransactionID);
-        }
-
-
-        #region method Parse
-
-        /// <summary>
-        /// Parses STUN message from raw data packet.
-        /// </summary>
-        /// <param name="data">Raw STUN message.</param>
-        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
-        public void Parse(byte[] data)
-        {
-            if(data == null){
-                throw new ArgumentNullException("data");
-            }
-
-            /* RFC 5389 6.             
-                All STUN messages MUST start with a 20-byte header followed by zero
-                or more Attributes.  The STUN header contains a STUN message type,
-                magic cookie, transaction ID, and message length.
-
-                 0                   1                   2                   3
-                 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                 |0 0|     STUN Message Type     |         Message Length        |
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                 |                         Magic Cookie                          |
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                 |                                                               |
-                 |                     Transaction ID (96 bits)                  |
-                 |                                                               |
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-              
-               The message length is the count, in bytes, of the size of the
-               message, not including the 20 byte header.
-            */
-
-            if(data.Length < 20){
-                throw new ArgumentException("Invalid STUN message value !");
-            }
-
-            int offset = 0;
-
-            //--- message header --------------------------------------------------
-
-            // STUN Message Type
-            int messageType = (data[offset++] << 8 | data[offset++]);
-            if(messageType == (int)STUN_MessageType.BindingErrorResponse){
-                m_Type = STUN_MessageType.BindingErrorResponse;
-            }
-            else if(messageType == (int)STUN_MessageType.BindingRequest){
-                m_Type = STUN_MessageType.BindingRequest;
-            }
-            else if(messageType == (int)STUN_MessageType.BindingResponse){
-                m_Type = STUN_MessageType.BindingResponse;
-            }
-            else if(messageType == (int)STUN_MessageType.SharedSecretErrorResponse){
-                m_Type = STUN_MessageType.SharedSecretErrorResponse;
-            }
-            else if(messageType == (int)STUN_MessageType.SharedSecretRequest){
-                m_Type = STUN_MessageType.SharedSecretRequest;
-            }
-            else if(messageType == (int)STUN_MessageType.SharedSecretResponse){
-                m_Type = STUN_MessageType.SharedSecretResponse;
-            }
-            else{
-                throw new ArgumentException("Invalid STUN message type value !");
-            }
-
-            // Message Length
-            int messageLength = (data[offset++] << 8 | data[offset++]);
-
-            // Magic Cookie
-            m_MagicCookie = (data[offset++] << 24 | data[offset++] << 16 | data[offset++] << 8 | data[offset++]);
-
-            // Transaction ID
-            m_pTransactionID = new byte[12];
-            Array.Copy(data,offset,m_pTransactionID,0,12);
-            offset += 12;
-
-            //--- Message attributes ---------------------------------------------
-            while((offset - 20) < messageLength){
-                ParseAttribute(data,ref offset);
-            }
-        }
-
-        #endregion
-
-        #region method ToByteData
-
-        /// <summary>
-        /// Converts this to raw STUN packet.
-        /// </summary>
-        /// <returns>Returns raw STUN packet.</returns>
-        public byte[] ToByteData()
-        {
-            /* RFC 5389 6.             
-                All STUN messages MUST start with a 20-byte header followed by zero
-                or more Attributes.  The STUN header contains a STUN message type,
-                magic cookie, transaction ID, and message length.
-
-                 0                   1                   2                   3
-                 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                 |0 0|     STUN Message Type     |         Message Length        |
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                 |                         Magic Cookie                          |
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                 |                                                               |
-                 |                     Transaction ID (96 bits)                  |
-                 |                                                               |
-                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-              
-               The message length is the count, in bytes, of the size of the
-               message, not including the 20 byte header.
-            */
-
-            // We allocate 512 for header, that should be more than enough.
-            byte[] msg = new byte[512];
-
-            int offset = 0;
-
-            //--- message header -------------------------------------
-
-            // STUN Message Type (2 bytes)
-            msg[offset++] = (byte)(((int)this.Type >> 8) & 0x3F);
-            msg[offset++] = (byte)((int)this.Type & 0xFF);
-
-            // Message Length (2 bytes) will be assigned at last.
-            msg[offset++] = 0;
-            msg[offset++] = 0;
-
-            // Magic Cookie           
-            msg[offset++] = (byte)((this.MagicCookie >> 24) & 0xFF);
-            msg[offset++] = (byte)((this.MagicCookie >> 16) & 0xFF);
-            msg[offset++] = (byte)((this.MagicCookie >> 8)  & 0xFF);
-            msg[offset++] = (byte)((this.MagicCookie >> 0)  & 0xFF);
-
-            // Transaction ID (16 bytes)
-            Array.Copy(m_pTransactionID,0,msg,offset,12);
-            offset += 12;
-
-            //--- Message attributes ------------------------------------
-      
-            /* RFC 3489 11.2.
-                After the header are 0 or more attributes.  Each attribute is TLV
-                encoded, with a 16 bit type, 16 bit length, and variable value:
-
-                0                   1                   2                   3
-                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-               |         Type                  |            Length             |
-               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-               |                             Value                             ....
-               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-            */
-            
-            if(this.MappedAddress != null){
-                StoreEndPoint(AttributeType.MappedAddress,this.MappedAddress,msg,ref offset);
-            }
-            else if(this.ResponseAddress != null){
-                StoreEndPoint(AttributeType.ResponseAddress,this.ResponseAddress,msg,ref offset);
-            }
-            else if(this.ChangeRequest != null){
-                /*
-                    The CHANGE-REQUEST attribute is used by the client to request that
-                    the server use a different address and/or port when sending the
-                    response.  The attribute is 32 bits long, although only two bits (A
-                    and B) are used:
-
-                     0                   1                   2                   3
-                     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                    |0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A B 0|
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
-                    The meaning of the flags is:
-
-                    A: This is the "change IP" flag.  If true, it requests the server
-                       to send the Binding Response with a different IP address than the
-                       one the Binding Request was received on.
-
-                    B: This is the "change port" flag.  If true, it requests the
-                       server to send the Binding Response with a different port than the
-                       one the Binding Request was received on.
-                */
-               
-                // Attribute header
-                msg[offset++] = (int)AttributeType.ChangeRequest >> 8;
-                msg[offset++] = (int)AttributeType.ChangeRequest & 0xFF;
-                msg[offset++] = 0;
-                msg[offset++] = 4;
-
-                msg[offset++] = 0;
-                msg[offset++] = 0;
-                msg[offset++] = 0;
-                msg[offset++] = (byte)(Convert.ToInt32(this.ChangeRequest.ChangeIP) << 2 | Convert.ToInt32(this.ChangeRequest.ChangePort) << 1);               
-            }
-            else if(this.SourceAddress != null){
-                StoreEndPoint(AttributeType.SourceAddress,this.SourceAddress,msg,ref offset);
-            }
-            else if(this.ChangedAddress != null){
-                StoreEndPoint(AttributeType.ChangedAddress,this.ChangedAddress,msg,ref offset);
-            }
-            else if(this.UserName != null){
-                byte[] userBytes = Encoding.ASCII.GetBytes(this.UserName);
-
-                // Attribute header
-                msg[offset++] = (int)AttributeType.Username >> 8;
-                msg[offset++] = (int)AttributeType.Username & 0xFF;
-                msg[offset++] = (byte)(userBytes.Length >> 8);
-                msg[offset++] = (byte)(userBytes.Length & 0xFF);
-
-                Array.Copy(userBytes,0,msg,offset,userBytes.Length);
-                offset += userBytes.Length;
-            }
-            else if(this.Password != null){
-                byte[] userBytes = Encoding.ASCII.GetBytes(this.UserName);
-
-                // Attribute header
-                msg[offset++] = (int)AttributeType.Password >> 8;
-                msg[offset++] = (int)AttributeType.Password & 0xFF;
-                msg[offset++] = (byte)(userBytes.Length >> 8);
-                msg[offset++] = (byte)(userBytes.Length & 0xFF);
-
-                Array.Copy(userBytes,0,msg,offset,userBytes.Length);
-                offset += userBytes.Length;
-            }
-            else if(this.ErrorCode != null){
-                /* 3489 11.2.9.
-                    0                   1                   2                   3
-                    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                    |                   0                     |Class|     Number    |
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                    |      Reason Phrase (variable)                                ..
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                */
-
-                byte[] reasonBytes = Encoding.ASCII.GetBytes(this.ErrorCode.ReasonText);
-
-                // Header
-                msg[offset++] = 0;
-                msg[offset++] = (int)AttributeType.ErrorCode;
-                msg[offset++] = 0;
-                msg[offset++] = (byte)(4 + reasonBytes.Length);
-
-                // Empty
-                msg[offset++] = 0;
-                msg[offset++] = 0;
-                // Class
-                msg[offset++] = (byte)Math.Floor((double)(this.ErrorCode.Code / 100));
-                // Number
-                msg[offset++] = (byte)(this.ErrorCode.Code & 0xFF);
-                // ReasonPhrase
-                Array.Copy(reasonBytes,msg,reasonBytes.Length);
-                offset += reasonBytes.Length;
-            }
-            else if(this.ReflectedFrom != null){
-                StoreEndPoint(AttributeType.ReflectedFrom,this.ReflectedFrom,msg,ref offset);
-            }
-
-            // Update Message Length. NOTE: 20 bytes header not included.
-            msg[2] = (byte)((offset - 20) >> 8);
-            msg[3] = (byte)((offset - 20) & 0xFF);
-
-            // Make reatval with actual size.
-            byte[] retVal = new byte[offset];
-            Array.Copy(msg,retVal,retVal.Length);
-        
-            return retVal;
-        }
-
-        #endregion
-
-
-        #region method ParseAttribute
-
-        /// <summary>
-        /// Parses attribute from data.
-        /// </summary>
-        /// <param name="data">SIP message data.</param>
-        /// <param name="offset">Offset in data.</param>
-        private void ParseAttribute(byte[] data,ref int offset)
-        {
-            /* RFC 3489 11.2.
-                Each attribute is TLV encoded, with a 16 bit type, 16 bit length, and variable value:
-
-                0                   1                   2                   3
-                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-               |         Type                  |            Length             |
-               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-               |                             Value                             ....
-               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                            
-            */
-
-            // Type
-            AttributeType type = (AttributeType)(data[offset++] << 8 | data[offset++]);
-
-            // Length
-            int length = (data[offset++] << 8 | data[offset++]);
-
-            // MAPPED-ADDRESS
-            if(type == AttributeType.MappedAddress){
-                m_pMappedAddress = ParseEndPoint(data,ref offset);
-            }
-            // RESPONSE-ADDRESS
-            else if(type == AttributeType.ResponseAddress){
-                m_pResponseAddress = ParseEndPoint(data,ref offset);
-            }
-            // CHANGE-REQUEST
-            else if(type == AttributeType.ChangeRequest){
-                /*
-                    The CHANGE-REQUEST attribute is used by the client to request that
-                    the server use a different address and/or port when sending the
-                    response.  The attribute is 32 bits long, although only two bits (A
-                    and B) are used:
-
-                     0                   1                   2                   3
-                     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                    |0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A B 0|
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
-                    The meaning of the flags is:
-
-                    A: This is the "change IP" flag.  If true, it requests the server
-                       to send the Binding Response with a different IP address than the
-                       one the Binding Request was received on.
-
-                    B: This is the "change port" flag.  If true, it requests the
-                       server to send the Binding Response with a different port than the
-                       one the Binding Request was received on.
-                */
-
-                // Skip 3 bytes
-                offset += 3;
-                                
-                m_pChangeRequest = new STUN_t_ChangeRequest((data[offset] & 4) != 0,(data[offset] & 2) != 0);
-                offset++;
-            }
-            // SOURCE-ADDRESS
-            else if(type == AttributeType.SourceAddress){
-                m_pSourceAddress = ParseEndPoint(data,ref offset);
-            }
-            // CHANGED-ADDRESS
-            else if(type == AttributeType.ChangedAddress){
-                m_pChangedAddress = ParseEndPoint(data,ref offset);
-            }
-            // USERNAME
-            else if(type == AttributeType.Username){
-                m_UserName = Encoding.Default.GetString(data,offset,length);
-                offset += length;
-            }
-            // PASSWORD
-            else if(type == AttributeType.Password){
-                m_Password = Encoding.Default.GetString(data,offset,length);
-                offset += length;
-            }
-            // MESSAGE-INTEGRITY
-            else if(type == AttributeType.MessageIntegrity){
-                offset += length;
-            }
-            // ERROR-CODE
-            else if(type == AttributeType.ErrorCode){
-                /* 3489 11.2.9.
-                    0                   1                   2                   3
-                    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                    |                   0                     |Class|     Number    |
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                    |      Reason Phrase (variable)                                ..
-                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                */
-
-                int errorCode = (data[offset + 2] & 0x7) * 100 + (data[offset + 3] & 0xFF);
-
-                m_pErrorCode = new STUN_t_ErrorCode(errorCode,Encoding.Default.GetString(data,offset + 4,length - 4));
-                offset += length;
-            }
-            // UNKNOWN-ATTRIBUTES
-            else if(type == AttributeType.UnknownAttribute){
-                offset += length;
-            }
-            // REFLECTED-FROM
-            else if(type == AttributeType.ReflectedFrom){
-                m_pReflectedFrom = ParseEndPoint(data,ref offset);
-            }
-            // XorMappedAddress
-            // XorOnly
-            // ServerName
-            else if(type == AttributeType.ServerName){
-                m_ServerName = Encoding.Default.GetString(data,offset,length);
-                offset += length;
-            }
-            // Unknown
-            else{
-                offset += length;
-            }
-        }
-
-        #endregion
-
-        #region method ParseEndPoint
-
-        /// <summary>
-        /// Pasrses IP endpoint attribute.
-        /// </summary>
-        /// <param name="data">STUN message data.</param>
-        /// <param name="offset">Offset in data.</param>
-        /// <returns>Returns parsed IP end point.</returns>
-        private IPEndPoint ParseEndPoint(byte[] data,ref int offset)
-        {
-            /*
-                It consists of an eight bit address family, and a sixteen bit
-                port, followed by a fixed length value representing the IP address.
-
-                0                   1                   2                   3
-                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                |x x x x x x x x|    Family     |           Port                |
-                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                |                             Address                           |
-                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-            */
-
-            // Skip family
-            offset++;
-            offset++;
-            
-            // Port
-            int port = (data[offset++] << 8 | data[offset++]);
-
-            // Address
-            byte[] ip = new byte[4];
-            ip[0] = data[offset++];
-            ip[1] = data[offset++];
-            ip[2] = data[offset++];
-            ip[3] = data[offset++];
-            
-            return new IPEndPoint(new IPAddress(ip),port);
-        }
-
-        #endregion
-
-        #region method StoreEndPoint
-
-        /// <summary>
-        /// Stores ip end point attribute to buffer.
-        /// </summary>
-        /// <param name="type">Attribute type.</param>
-        /// <param name="endPoint">IP end point.</param>
-        /// <param name="message">Buffer where to store.</param>
-        /// <param name="offset">Offset in buffer.</param>
-        private void StoreEndPoint(AttributeType type,IPEndPoint endPoint,byte[] message,ref int offset)
-        {
-            /*
-                It consists of an eight bit address family, and a sixteen bit
-                port, followed by a fixed length value representing the IP address.
-
-                0                   1                   2                   3
-                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                |x x x x x x x x|    Family     |           Port                |
-                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                |                             Address                           |
-                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+             
-            */
-
-            // Header
-            message[offset++] = (byte)((int)type >> 8);
-            message[offset++] = (byte)((int)type & 0xFF); 
-            message[offset++] = 0;
-            message[offset++] = 8;
-                   
-            // Unused
-            message[offset++] = 0;
-            // Family
-            message[offset++] = (byte)IPFamily.IPv4;
-            // Port
-            message[offset++] = (byte)(endPoint.Port >> 8);
-            message[offset++] = (byte)(endPoint.Port & 0xFF);
-            // Address
-            byte[] ipBytes = endPoint.Address.GetAddressBytes();
-            message[offset++] = ipBytes[0];
-            message[offset++] = ipBytes[1];
-            message[offset++] = ipBytes[2];
-            message[offset++] = ipBytes[3];
-        }
-
-        #endregion
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets STUN message type.
-        /// </summary>
-        public STUN_MessageType Type
-        {
-            get{ return m_Type; }
-
-            set{ m_Type = value; }
-        }
-
-        /// <summary>
-        /// Gets magic cookie value. This is always 0x2112A442.
-        /// </summary>
-        public int MagicCookie
-        {
-            get{ return m_MagicCookie; }
-        }
-
-        /// <summary>
-        /// Gets transaction ID.
-        /// </summary>
-        public byte[] TransactionID
-        {
-            get{ return m_pTransactionID; }
-        }
-
-        /// <summary>
-        /// Gets or sets IP end point what was actually connected to STUN server. Returns null if not specified.
-        /// </summary>
-        public IPEndPoint MappedAddress
-        {
-            get{ return m_pMappedAddress; }
-
-            set{ m_pMappedAddress = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets IP end point where to STUN client likes to receive response.
-        /// Value null means not specified.
-        /// </summary>
-        public IPEndPoint ResponseAddress
-        {
-            get{ return m_pResponseAddress; }
-
-            set{ m_pResponseAddress = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets how and where STUN server must send response back to STUN client.
-        /// Value null means not specified.
-        /// </summary>
-        public STUN_t_ChangeRequest ChangeRequest
-        {
-            get{ return m_pChangeRequest; }
-
-            set{ m_pChangeRequest = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets STUN server IP end point what sent response to STUN client. Value null
-        /// means not specified.
-        /// </summary>
-        public IPEndPoint SourceAddress
-        {
-            get{ return m_pSourceAddress; }
-
-            set{ m_pSourceAddress = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets IP end point where STUN server will send response back to STUN client 
-        /// if the "change IP" and "change port" flags had been set in the ChangeRequest.
-        /// </summary>
-        public IPEndPoint ChangedAddress
-        {
-            get{ return m_pChangedAddress; }
-
-            set{ m_pChangedAddress = value; }
-        }
-        
-        /// <summary>
-        /// Gets or sets user name. Value null means not specified.
-        /// </summary>          
-        public string UserName
-        {
-            get{ return m_UserName; }
-
-            set{ m_UserName = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets password. Value null means not specified.
-        /// </summary>
-        public string Password
-        {
-            get{ return m_Password; }
-
-            set{ m_Password = value; }
-        }
-
-        //public MessageIntegrity
-
-        /// <summary>
-        /// Gets or sets error info. Returns null if not specified.
-        /// </summary>
-        public STUN_t_ErrorCode ErrorCode
-        {
-            get{ return m_pErrorCode; }
-
-            set{ m_pErrorCode = value; }
-        }
-
-
-        /// <summary>
-        /// Gets or sets IP endpoint from which IP end point STUN server got STUN client request.
-        /// Value null means not specified.
-        /// </summary>
-        public IPEndPoint ReflectedFrom
-        {
-            get{ return m_pReflectedFrom; }
-
-            set{ m_pReflectedFrom = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets server name.
-        /// </summary>
-        public string ServerName
-        {
-            get{ return m_ServerName; }
-
-            set{ m_ServerName = value; }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 42
NatTypeTester/3rd/Net/STUN/Message/STUN_MessageType.cs

@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.STUN.Message
-{
-    /// <summary>
-    /// This enum specifies STUN message type.
-    /// </summary>
-    public enum STUN_MessageType
-    {
-        /// <summary>
-        /// STUN message is binding request.
-        /// </summary>
-        BindingRequest = 0x0001,
-
-        /// <summary>
-        /// STUN message is binding request response.
-        /// </summary>
-        BindingResponse = 0x0101,
-
-        /// <summary>
-        /// STUN message is binding requesr error response.
-        /// </summary>
-        BindingErrorResponse = 0x0111,
-
-        /// <summary>
-        /// STUN message is "shared secret" request.
-        /// </summary>
-        SharedSecretRequest = 0x0002,
-
-        /// <summary>
-        /// STUN message is "shared secret" request response.
-        /// </summary>
-        SharedSecretResponse = 0x0102,
-
-        /// <summary>
-        /// STUN message is "shared secret" request error response.
-        /// </summary>
-        SharedSecretErrorResponse = 0x0112,
-    }
-}

+ 0 - 59
NatTypeTester/3rd/Net/STUN/Message/STUN_t_ChangeRequest.cs

@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.STUN.Message
-{
-    /// <summary>
-    /// This class implements STUN CHANGE-REQUEST attribute. Defined in RFC 3489 11.2.4.
-    /// </summary>
-    public class STUN_t_ChangeRequest
-    {
-        private bool m_ChangeIP   = true;
-        private bool m_ChangePort = true;
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        public STUN_t_ChangeRequest()
-        {
-        }
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="changeIP">Specifies if STUN server must send response to different IP than request was received.</param>
-        /// <param name="changePort">Specifies if STUN server must send response to different port than request was received.</param>
-        public STUN_t_ChangeRequest(bool changeIP,bool changePort)
-        {
-            m_ChangeIP = changeIP;
-            m_ChangePort = changePort;
-        }
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets or sets if STUN server must send response to different IP than request was received.
-        /// </summary>
-        public bool ChangeIP
-        {
-            get{ return m_ChangeIP; }
-
-            set{ m_ChangeIP = value; }
-        }
-
-        /// <summary>
-        /// Gets or sets if STUN server must send response to different port than request was received.
-        /// </summary>
-        public bool ChangePort
-        {
-            get{ return m_ChangePort; }
-
-            set{ m_ChangePort = value; }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 52
NatTypeTester/3rd/Net/STUN/Message/STUN_t_ErrorCode.cs

@@ -1,52 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net.STUN.Message
-{
-    /// <summary>
-    /// This class implements STUN ERROR-CODE. Defined in RFC 3489 11.2.9.
-    /// </summary>
-    public class STUN_t_ErrorCode
-    {
-        private int    m_Code       = 0;
-        private string m_ReasonText = "";
-
-        /// <summary>
-        /// Default constructor.
-        /// </summary>
-        /// <param name="code">Error code.</param>
-        /// <param name="reasonText">Reason text.</param>
-        public STUN_t_ErrorCode(int code,string reasonText)
-        {
-            m_Code       = code;
-            m_ReasonText = reasonText;
-        }
-
-
-        #region Properties Implementation
-
-        /// <summary>
-        /// Gets or sets error code.
-        /// </summary>
-        public int Code
-        {
-            get{ return m_Code; }
-
-            set{ m_Code = value; }
-        }
-
-        /// <summary>
-        /// Gets reason text.
-        /// </summary>
-        public string ReasonText
-        {
-            get{ return m_ReasonText; }
-
-            set{ m_ReasonText = value; }
-        }
-
-        #endregion
-
-    }
-}

+ 0 - 27
NatTypeTester/3rd/Net/SslMode.cs

@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace LumiSoft.Net
-{
-    /// <summary>
-    /// This enum holds SSL modes.
-    /// </summary>
-    public enum SslMode
-    {
-        /// <summary>
-        /// No SSL is used.
-        /// </summary>
-        None,
-
-        /// <summary>
-        /// Connection is SSL.
-        /// </summary>
-        SSL,
-
-        /// <summary>
-        /// Connection will be switched to SSL with start TLS.
-        /// </summary>
-        TLS
-    }
-}

+ 0 - 19
NatTypeTester/3rd/Net/license.txt

@@ -1,19 +0,0 @@
-
-General usage terms:
-
-  *) If you use/redistribute compiled binary, there are no restrictions.
-     You can use it in any project, commercial and no-commercial.
-     Redistributing compiled binary not limited any way.
-
-  *) It's allowed to complile source code parts to your application,
-     but then you may not rename class names and namespaces.
-
-  *) Anything is possible, if special agreement between LumiSoft.
-
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
-INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
-PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
-FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-

+ 1 - 0
NatTypeTester/Lumisoft.Net

@@ -0,0 +1 @@
+Subproject commit fdfec12d4fcceb79786253575dea34fd0e8dec29

+ 29 - 33
NatTypeTester/NatTypeTester.csproj

@@ -47,36 +47,35 @@
     <Reference Include="System.Xml" />
     <Reference Include="System.Xml" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <Compile Include="3rd\Net\AsyncOP_State.cs" />
-    <Compile Include="3rd\Net\EventArgs.cs" />
-    <Compile Include="3rd\Net\IAsyncOP.cs" />
-    <Compile Include="3rd\Net\IO\Base64.cs" />
-    <Compile Include="3rd\Net\IO\Base64Stream.cs" />
-    <Compile Include="3rd\Net\IO\DataSizeExceededException.cs" />
-    <Compile Include="3rd\Net\IO\FifoBuffer.cs" />
-    <Compile Include="3rd\Net\IO\IncompleteDataException.cs" />
-    <Compile Include="3rd\Net\IO\JunkingStream.cs" />
-    <Compile Include="3rd\Net\IO\LineSizeExceededException.cs" />
-    <Compile Include="3rd\Net\IO\MemoryStreamEx.cs" />
-    <Compile Include="3rd\Net\IO\MultiStream.cs" />
-    <Compile Include="3rd\Net\IO\PartialStream.cs" />
-    <Compile Include="3rd\Net\IO\QuotedPrintableStream.cs" />
-    <Compile Include="3rd\Net\IO\ReadWriteControlledStream.cs" />
-    <Compile Include="3rd\Net\IO\SizeExceededAction.cs" />
-    <Compile Include="3rd\Net\IO\SmartStream.cs" />
-    <Compile Include="3rd\Net\Log\LogEntry.cs" />
-    <Compile Include="3rd\Net\Log\LogEntryType.cs" />
-    <Compile Include="3rd\Net\Log\Logger.cs" />
-    <Compile Include="3rd\Net\Log\WriteLogEventArgs.cs" />
-    <Compile Include="3rd\Net\Net_Utils.cs" />
-    <Compile Include="3rd\Net\SslMode.cs" />
-    <Compile Include="3rd\Net\STUN\Client\STUN_Client.cs" />
-    <Compile Include="3rd\Net\STUN\Client\STUN_NetType.cs" />
-    <Compile Include="3rd\Net\STUN\Client\STUN_Result.cs" />
-    <Compile Include="3rd\Net\STUN\Message\STUN_Message.cs" />
-    <Compile Include="3rd\Net\STUN\Message\STUN_MessageType.cs" />
-    <Compile Include="3rd\Net\STUN\Message\STUN_t_ChangeRequest.cs" />
-    <Compile Include="3rd\Net\STUN\Message\STUN_t_ErrorCode.cs" />
+    <Compile Include="Lumisoft.Net\Net\AsyncOP_State.cs" />
+    <Compile Include="Lumisoft.Net\Net\EventArgs.cs" />
+    <Compile Include="Lumisoft.Net\Net\IAsyncOP.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\Base64.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\Base64Stream.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\DataSizeExceededException.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\FifoBuffer.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\IncompleteDataException.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\JunkingStream.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\LineSizeExceededException.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\MemoryStreamEx.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\MultiStream.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\PartialStream.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\QuotedPrintableStream.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\ReadWriteControlledStream.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\SizeExceededAction.cs" />
+    <Compile Include="Lumisoft.Net\Net\IO\SmartStream.cs" />
+    <Compile Include="Lumisoft.Net\Net\Log\LogEntry.cs" />
+    <Compile Include="Lumisoft.Net\Net\Log\LogEntryType.cs" />
+    <Compile Include="Lumisoft.Net\Net\Log\Logger.cs" />
+    <Compile Include="Lumisoft.Net\Net\Log\WriteLogEventArgs.cs" />
+    <Compile Include="Lumisoft.Net\Net\Net_Utils.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Client\STUN_Client.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Client\STUN_NetType.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Client\STUN_Result.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Message\STUN_Message.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Message\STUN_MessageType.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Message\STUN_t_ChangeRequest.cs" />
+    <Compile Include="Lumisoft.Net\Net\STUN\Message\STUN_t_ErrorCode.cs" />
     <Compile Include="MainForm.cs">
     <Compile Include="MainForm.cs">
       <SubType>Form</SubType>
       <SubType>Form</SubType>
     </Compile>
     </Compile>
@@ -111,8 +110,5 @@
   <ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
     <None Include="App.config" />
   </ItemGroup>
   </ItemGroup>
-  <ItemGroup>
-    <Content Include="3rd\Net\license.txt" />
-  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>
 </Project>