List:Commits« Previous MessageNext Message »
From:rburnett Date:July 30 2006 3:31am
Subject:Connector/NET commit: r279 - in trunk/mysqlclient: . Types common
View as plain text  
Removed:
   trunk/mysqlclient/MySqlStreamReader.cs
   trunk/mysqlclient/MySqlStreamWriter.cs
   trunk/mysqlclient/common/SocketStream.cs
Modified:
   trunk/mysqlclient/Driver.cs
   trunk/mysqlclient/MySql.Data.2005.csproj
   trunk/mysqlclient/MySqlStream.cs
   trunk/mysqlclient/NativeDriver.cs
   trunk/mysqlclient/PreparedStatement.cs
   trunk/mysqlclient/Resources.Designer.cs
   trunk/mysqlclient/Resources.resx
   trunk/mysqlclient/Statement.cs
   trunk/mysqlclient/Types/MySqlBinary.cs
   trunk/mysqlclient/Types/MySqlBit.cs
   trunk/mysqlclient/Types/MySqlByte.cs
   trunk/mysqlclient/Types/MySqlDateTime.cs
   trunk/mysqlclient/Types/MySqlDecimal.cs
   trunk/mysqlclient/Types/MySqlDouble.cs
   trunk/mysqlclient/Types/MySqlInt16.cs
   trunk/mysqlclient/Types/MySqlInt32.cs
   trunk/mysqlclient/Types/MySqlInt64.cs
   trunk/mysqlclient/Types/MySqlSingle.cs
   trunk/mysqlclient/Types/MySqlString.cs
   trunk/mysqlclient/Types/MySqlTime.cs
   trunk/mysqlclient/Types/MySqlUByte.cs
   trunk/mysqlclient/Types/MySqlUInt16.cs
   trunk/mysqlclient/Types/MySqlUInt32.cs
   trunk/mysqlclient/Types/MySqlUInt64.cs
   trunk/mysqlclient/Types/MySqlValue.cs
   trunk/mysqlclient/common/StreamCreator.cs
   trunk/mysqlclient/parameter.cs
Log:
All changes except for the changes to StreamCreator are a result of moving all functionality previously found in MySqlStreamReader and MySqlStreamWriter into the MySqlStream class. 

For StreamCreator, we are again using BeginConnect and EndConnect methods to support ConnectTimeout.  We will test this during the alpha and beta phases to determine if we are going to stay with this or move back to the previous code that used NativeMethods.


Modified: trunk/mysqlclient/Driver.cs
===================================================================
--- trunk/mysqlclient/Driver.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Driver.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -159,8 +159,12 @@
 			try 
 			{
 				MySqlDataReader reader = cmd.ExecuteReader();
-				while (reader.Read()) 
-					serverProps[reader.GetValue(0)] = reader.GetString(1);
+                while (reader.Read())
+                {
+                    string key = reader.GetString(0);
+                    string value = reader.GetString(1);
+                    serverProps[key] = value;
+                }
 				reader.Close();
 			}
 			catch (Exception ex)

Modified: trunk/mysqlclient/MySql.Data.2005.csproj
===================================================================
--- trunk/mysqlclient/MySql.Data.2005.csproj	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/MySql.Data.2005.csproj	2006-07-30 03:31:34 UTC (rev 279)
@@ -110,7 +110,6 @@
     <Compile Include="common\Resources.cs" />
     <Compile Include="common\SHA1.cs" />
     <Compile Include="common\SharedMemoryStream.cs" />
-    <Compile Include="common\SocketStream.cs" />
     <Compile Include="common\StreamCreator.cs" />
     <Compile Include="common\Version.cs" />
     <Compile Include="common\WinCE.cs" />
@@ -136,8 +135,6 @@
     <Compile Include="MySqlPool.cs" />
     <Compile Include="MySqlPoolManager.cs" />
     <Compile Include="MySqlStream.cs" />
-    <Compile Include="MySqlStreamReader.cs" />
-    <Compile Include="MySqlStreamWriter.cs" />
     <Compile Include="NativeDriver.cs" />
     <Compile Include="parameter.cs" />
     <Compile Include="parameter_collection.cs" />

Modified: trunk/mysqlclient/MySqlStream.cs
===================================================================
--- trunk/mysqlclient/MySqlStream.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/MySqlStream.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -20,39 +20,86 @@
 
 using System;
 using System.IO;
+using System.Diagnostics;
+using System.Text;
+using MySql.Data.Common;
 
 namespace MySql.Data.MySqlClient
 {
 	/// <summary>
 	/// Summary description for MySqlStream.
 	/// </summary>
-	internal class MySqlStream : Stream
+	internal class MySqlStream
 	{
-		private Stream	baseStream;
-		private long	maxSinglePacket;
-		private long	readLength;
-		private long	readPos;
-		private long	writePos;
-		private long	writeLength;
 		private	byte	sequenceByte;
 		private int		peekByte;
-		private int		leftInChunk;
-		private byte[]	buffer;
-		private int		bufferPos;
-		private int		bufferLength;
+        private Encoding encoding;
+        private DBVersion version;
 
-		public MySqlStream(Stream baseStr)
+        private MemoryStream bufferStream;
+
+        private int maxBlockSize;
+
+        private BufferedStream inStream;
+        private ulong inLength;
+        private ulong inPos;
+
+        private Stream outStream;
+        private ulong outLength;
+        private ulong outPos;
+        private bool isLastPacket;
+        private byte[] byteBuffer;
+
+        public MySqlStream(Encoding encoding)
+        {
+            this.encoding = encoding;
+            bufferStream = new MemoryStream();
+            byteBuffer = new byte[1];
+            peekByte = -1;
+        }
+
+		public MySqlStream(Stream baseStr, Encoding encoding) : this(encoding)
 		{
-			baseStream = baseStr;
-			maxSinglePacket = 255*255*255;
-			leftInChunk = 0;
-			peekByte = -1;
-			bufferLength = 0x1000;
-			buffer = new byte[bufferLength];
+            outStream = new BufferedStream(baseStr);
+            inStream = new BufferedStream(baseStr);
 		}
 
+        public void Close()
+        {
+            inStream.Close();
+            outStream.Close();
+        }
+
 		#region Properties
 
+        public bool IsLastPacket
+        {
+            get { return isLastPacket; }
+        }
+
+        public int MaxBlockLength
+        {
+            get { return maxBlockSize; }
+            set { maxBlockSize = value; }
+        }
+
+        public DBVersion Version
+        {
+            get { return version; }
+            set { version = value; }
+        }
+
+        public Encoding Encoding
+        {
+            get { return encoding; }
+            set { encoding = value; }
+        }
+
+        public MemoryStream InternalBuffer
+        {
+            get { return bufferStream; }
+        }
+
 		public byte SequenceByte 
 		{
 			get { return sequenceByte; }
@@ -61,180 +108,420 @@
 
 		public bool HasMoreData 
 		{
-			get { return (readLength == maxSinglePacket || readPos < readLength); }
+			get 
+            { 
+                return inLength > 0 &&
+                       (inLength == (ulong)maxBlockSize || inPos < inLength); 
+            }
 		}
 
-		public long MaxSinglePacket 
+		public int MaxSinglePacket 
 		{
-			get { return maxSinglePacket; }
-			set { maxSinglePacket = value; }
+			get { return maxBlockSize; }
+			set { maxBlockSize = value; }
 		}
 
-		public override bool CanRead
-		{
-			get	{ return true; }
-		}
+		#endregion
 
-		public override bool CanWrite
-		{
-			get	{ return true;	}
-		}
+        #region Packet methods
 
-		public override bool CanSeek
-		{
-			get	{ return false;	}
-		}
+        /// <summary>
+        /// OpenPacket is called by NativeDriver to start reading the next
+        /// packet on the stream.
+        /// </summary>
+        public void OpenPacket()
+        {
+            // make sure we have read all the data from the previous packet
+            Debug.Assert(HasMoreData == false, "HasMoreData is true in OpenPacket");
 
-		public override long Length
-		{
-			get	{ return readLength;	}
-		}
+            LoadPacket();
 
-		public override long Position
-		{
-			get	{ return readPos;	}
-			set	{	}
-		}
+            int peek = PeekByte();
+            if (peek == 0xff)
+            {
+                int code = ReadInteger(2);
+                string msg = ReadString();
+                throw new MySqlException(msg, code);
+            }
+            isLastPacket = (peek == 0xfe && (inLength < 9));
+        }
 
-		#endregion
+        /// <summary>
+        /// LoadPacket loads up and decodes the header of the incoming packet.
+        /// </summary>
+        public void LoadPacket()
+        {
+            int b1 = inStream.ReadByte();
+            int b2 = inStream.ReadByte();
+            int b3 = inStream.ReadByte();
+            int seqByte = inStream.ReadByte();
 
-		public override void Flush()
-		{
-			FlushWrite();
-			baseStream.Flush();
-		}
+            if (b1 == -1 || b2 == -1 || b3 == -1 || seqByte == -1)
+                throw new MySqlException(
+                    Resources.ConnectionBroken, true, null);
 
-		public int PeekByte() 
+            sequenceByte = (byte)++seqByte;
+            inLength = (ulong)(b1 + (b2 << 8) + (b3 << 16));
+            inPos = 0;
+        }
+
+        /// <summary>
+        /// SkipPacket will read the remaining bytes of a packet into a small
+        /// local buffer and discard them.
+        /// </summary>
+        public void SkipPacket()
+        {
+            byte[] tempBuf = new byte[1024];
+            while (inPos < inLength)
+            {
+                int toRead = (int)Math.Min((ulong)tempBuf.Length, inLength);
+                Read(tempBuf, 0, toRead);
+                inPos += (ulong)toRead;
+            }
+        }
+
+        /// <summary>
+        /// StartOutput is used to reset the write state of the stream.
+        /// </summary>
+        public void StartOutput(ulong length, bool resetSequence)
+        {
+            outLength = outPos = 0;
+            if (length > 0)
+                outLength = length;
+
+            if (resetSequence)
+                sequenceByte = 0;
+        }
+
+        /// <summary>
+        /// Writes out the header that is used at the start of a transmission
+        /// and at the beginning of every packet when multipacket is used.
+        /// </summary>
+        private void WriteHeader()
+        {
+            int len = (int)Math.Min((outLength - outPos), (ulong)maxBlockSize);
+
+            outStream.WriteByte((byte)(len & 0xff));
+            outStream.WriteByte((byte)((len >> 8) & 0xff));
+            outStream.WriteByte((byte)((len >> 16) & 0xff));
+            outStream.WriteByte((byte)sequenceByte++);
+        }
+
+        #endregion
+
+        #region Byte methods
+
+        public int ReadNBytes()
+        {
+            byte c = (byte)ReadByte();
+            if (c < 1 || c > 4) 
+                throw new MySqlException(Resources.IncorrectTransmission);
+            return ReadInteger((int)c);
+        }
+
+        public void SkipBytes(int len)
+        {
+            while (len-- > 0)
+                ReadByte();
+        }
+
+        /// <summary>
+        /// Reads the next byte from the incoming stream
+        /// </summary>
+        /// <returns></returns>
+		public int ReadByte()
 		{
-			if (peekByte == -1)  
-			{
-				peekByte = ReadByte();
-				readPos--;
-			}
-			return peekByte;
+            int b;
+            if (peekByte != -1)
+            {
+                b = PeekByte();
+                peekByte = -1;
+                inPos++;   // we only do this here since Read will also do it
+            }
+            else
+            {
+                // we read the byte this way because we might cross over a 
+                // multipacket boundary
+                Read(byteBuffer, 0, 1);
+                b = byteBuffer[0];
+            }
+            return b;
 		}
 
-		public override int ReadByte()
+        /// <summary>
+        /// Reads a block of bytes from the input stream into the given buffer.
+        /// </summary>
+        /// <returns>The number of bytes read.</returns>
+		public int Read(byte[] buffer, int offset, int count)
 		{
-			byte[] buf = new byte[1];
-			int cnt = Read(buf, 0, 1);
-			if (cnt == 0) return -1;
-			return (int)buf[0];
-		}
+            // we use asserts here because this is internal code
+            // and we should be calling it correctly in all cases
+            Debug.Assert(buffer != null);
+            Debug.Assert(offset >= 0 && offset < buffer.Length);
+            Debug.Assert(count >= 0);
+            Debug.Assert((offset + count) <= buffer.Length);
 
-
-		public override int Read(byte[] buffer, int offset, int count)
-		{
 			int totalRead = 0;
 
 			while (count > 0) 
 			{
-				int read = 0;
+                // if we have peeked at a byte, then read it off first.
+                if (peekByte != -1)
+                {
+                    buffer[offset] = (byte)ReadByte();
+                    count--;
+                    continue;
+                }
 
-				if (peekByte != -1) 
+                // check if we are reading multipacket and are done with the
+                // last packet
+				if (inPos == inLength) 
 				{
-					buffer[offset] = (byte)peekByte;
-					peekByte = -1;
-					read++;
+                    // at this point, we better be reading multipacket
+                    Debug.Assert(inLength == (ulong)maxBlockSize);
+					LoadPacket();
 				}
-				else 
-				{
-					if (readPos == readLength) 
-					{
-						if (readPos == MaxSinglePacket)
-							LoadPacket();
-						else
-							break;
-					}
 
-					int lenToRead = Math.Min(count, (int)(readLength-readPos));
-					read = baseStream.Read(buffer, offset, lenToRead);
-				}
+				int lenToRead = Math.Min(count, (int)(inLength - inPos));
+				int read = inStream.Read(buffer, offset, lenToRead);
 
-				if (read == 0) break;
+                // we don't throw an exception here even though this probably
+                // indicates a broken connection.  We leave that to the 
+                // caller.
+                if (read == 0)
+                    break;
+
 				count -= read;
 				offset += read;
 				totalRead += read;
-				readPos += read;
+				inPos += (ulong)read;
 			}
 
 			return totalRead;
-		}
+        }
 
-		public override long Seek(long offset, SeekOrigin origin)
-		{
-			return 0;
-		}
+        /// <summary>
+        /// Peek at the next byte off the stream
+        /// </summary>
+        /// <returns>The next byte off the stream</returns>
+        public int PeekByte()
+        {
+            if (peekByte == -1)
+            {
+                peekByte = ReadByte();
+                // ReadByte will advance inPos so we need to back it up since
+                // we are not really reading the byte
+                inPos--;
+            }
+            return peekByte;
+        }
 
-		public override void SetLength(long value)
-		{
-			writeLength = value;
-			writePos = 0;
-			WriteHeader();
-		}
+        /// <summary>
+        /// Writes a single byte to the output stream.
+        /// </summary>
+        public void WriteByte(byte value)
+        {
+            byteBuffer[0] = value;
+            Write(byteBuffer, 0, 1);
+        }
 
-		private void WriteHeader() 
-		{
-			int tempLeft = (int)Math.Min((long)maxSinglePacket, writeLength);
-			WriteByte((byte)(tempLeft & 0xff));
-			WriteByte((byte)((tempLeft >> 8) & 0xff));
-			WriteByte((byte)((tempLeft >> 16) & 0xff));
-			WriteByte((byte)sequenceByte++);
-			leftInChunk = tempLeft;
-		}
+        public void Write(byte[] buffer, int offset, int count)
+        {
+            Debug.Assert(buffer != null && offset >= 0 && count >= 0);
 
-		private void FlushWrite() 
-		{
-			baseStream.Write(buffer, 0, bufferPos);
-			bufferPos = 0;
-		}
+            // if we are buffering, then just write it to the buffer
+            if (outLength == 0)
+            {
+                bufferStream.Write(buffer, offset, count);
+                return;
+            }
 
-		public override void WriteByte(byte value)
-		{
-			if (bufferPos == bufferLength)
-				FlushWrite();
-			buffer[bufferPos++] = value;
-			leftInChunk--;
-			writePos++;
-		}
+            // make sure the inputs to the method make sense
+            Debug.Assert(outLength > 0 && (outPos + (ulong)count) <= outLength);
 
-		public override void Write(byte[] src, int offset, int count)
-		{
-			while (count > 0)
-			{
-				if (bufferPos == bufferLength)
-					FlushWrite();
+            int pos = 0;
+            // if we get here, we are not buffering.  
+            // outLength is the total amount of data we are going to send
+            // This means that multiple calls to write could be combined.
+            while (count > 0)
+            {
+                int cntToWrite = (int)Math.Min((outLength - outPos), (ulong)count);
+                cntToWrite = (int)Math.Min(
+                    maxBlockSize - (int)(outPos % (ulong)maxBlockSize), cntToWrite);
 
-				System.Diagnostics.Debug.Assert(leftInChunk > 0 || writeLength > 0);
-				if (leftInChunk == 0 && writeLength > 0)
-					WriteHeader();
+                // if we are at a block border, then we need to send a new header
+                if ((outPos % (ulong)maxBlockSize) == 0)
+                    WriteHeader();
 
-				int toWrite = Math.Min(count, leftInChunk);
-				toWrite = Math.Min(toWrite, bufferLength-bufferPos);
-				Buffer.BlockCopy(src, offset, buffer, bufferPos, toWrite);
-				offset += toWrite;
-				bufferPos += toWrite;
-				count -= toWrite;
-				leftInChunk -= toWrite;
-				writePos += toWrite;
-			}
+                outStream.Write(buffer, pos, cntToWrite);
 
-		}
+                outPos += (ulong)cntToWrite;
+                pos += cntToWrite;
+                count -= cntToWrite;
+            }
+        }
 
-		public void LoadPacket() 
-		{
-			int b1 = baseStream.ReadByte();
-			int b2 = baseStream.ReadByte();
-			int b3 = baseStream.ReadByte();
-			int seqByte = baseStream.ReadByte();
+        public void Write(byte[] buffer)
+        {
+            Write(buffer, 0, buffer.Length);
+        }
 
-			if (b1 == -1 || b2 == -1 || b3 == -1 || seqByte == -1)
-				throw new MySqlException( "Connection unexpectedly terminated", true, null );
+        public void Flush()
+        {
+            if (outLength == 0)
+            {
+                if (bufferStream.Length > 0)
+                {
+                    byte[] bytes = bufferStream.GetBuffer();
+                    StartOutput((ulong)bufferStream.Length, false);
+                    Write(bytes, 0, (int)bufferStream.Length);
+                }
+                bufferStream.SetLength(0);
+                bufferStream.Position = 0;
+            }
+            outStream.Flush();
+        }
 
-			sequenceByte = (byte)++seqByte;
-			readLength = b1 + (b2 << 8) + (b3 << 16);
-			readPos = 0;
-		}
+        #endregion
 
-	}
+        #region Integer methods
+
+        public long ReadFieldLength()
+        {
+            byte c = (byte)ReadByte();
+
+            switch (c)
+            {
+                case 251: return (long)-1;
+                case 252: return (long)ReadInteger(2);
+                case 253: return (long)ReadInteger(3);
+                case 254: return (long)ReadInteger(8);
+                default: return c;
+            }
+        }
+
+        public ulong ReadLong(int numbytes)
+        {
+            ulong val = 0;
+            int raise = 1;
+            for (int x = 0; x < numbytes; x++)
+            {
+                int b = ReadByte();
+                val += (ulong)(b * raise);
+                raise *= 256;
+            }
+            return val;
+        }
+
+        public int ReadInteger(int numbytes)
+        {
+            return (int)ReadLong(numbytes);
+        }
+
+        /// <summary>
+        /// WriteInteger
+        /// </summary>
+        /// <param name="v"></param>
+        /// <param name="numbytes"></param>
+        public void WriteInteger(long v, int numbytes)
+        {
+            long val = v;
+
+            Debug.Assert(numbytes > 0 && numbytes < 5);
+
+            for (int x = 0; x < numbytes; x++)
+            {
+                WriteByte((byte)(val & 0xff));
+                val >>= 8;
+            }
+        }
+
+        public int ReadPackedInteger()
+        {
+            byte c = (byte)ReadByte();
+
+            switch (c)
+            {
+                case 251: return -1;
+                case 252: return ReadInteger(2);
+                case 253: return ReadInteger(3);
+                case 254: return ReadInteger(4);
+                default: return c;
+            }
+        }
+
+        public void WriteLength(long length)
+        {
+            if (length < 251)
+                WriteByte((byte)length);
+            else if (length < 65536L)
+            {
+                WriteByte(252);
+                WriteInteger(length, 2);
+            }
+            else if (length < 16777216L)
+            {
+                WriteByte(253);
+                WriteInteger(length, 3);
+            }
+            else
+            {
+                WriteByte(254);
+                WriteInteger(length, 4);
+            }
+        }
+
+        #endregion
+
+        #region String methods
+
+        public void WriteLenString(string s)
+        {
+            byte[] bytes = encoding.GetBytes(s);
+            WriteLength(bytes.Length);
+            Write(bytes, 0, bytes.Length);
+        }
+
+        public void WriteStringNoNull(string v)
+        {
+            byte[] bytes = encoding.GetBytes(v);
+            Write(bytes, 0, bytes.Length);
+        }
+
+        public void WriteString(string v)
+        {
+            WriteStringNoNull(v);
+            WriteByte(0);
+        }
+
+        public string ReadLenString()
+        {
+            long len = ReadPackedInteger();
+            return ReadString(len);
+        }
+
+        public string ReadString(long length)
+        {
+            byte[] buf = new byte[length];
+            Read(buf, 0, (int)length);
+            return encoding.GetString(buf, 0, buf.Length);
+        }
+
+        public string ReadString()
+        {
+            MemoryStream ms = new MemoryStream();
+
+            int b = ReadByte();
+            while (b != 0 && b != -1)
+            {
+                ms.WriteByte((byte)b);
+                b = ReadByte();
+            }
+
+            return encoding.GetString(ms.GetBuffer(), 0, (int)ms.Length);
+        }
+
+        #endregion
+
+    }
 }

Deleted: trunk/mysqlclient/MySqlStreamReader.cs
===================================================================
--- trunk/mysqlclient/MySqlStreamReader.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/MySqlStreamReader.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -1,261 +0,0 @@
-// Copyright (C) 2004-2006 MySQL AB
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation
-//
-// There are special exceptions to the terms and conditions of the GPL 
-// as it is applied to this software. View the full text of the 
-// exception in file EXCEPTIONS in the directory of this software 
-// distribution.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
-
-using System;
-using System.Diagnostics;
-using System.Text;
-using System.IO;
-using MySql.Data.Common;
-
-namespace MySql.Data.MySqlClient
-{
-	/// <summary>
-	/// Summary description for MySqlStreamReader.
-	/// </summary>
-	internal class MySqlStreamReader
-	{
-		private Stream		stream;
-		private Encoding	encoding;
-		private DBVersion	version;
-		private bool		isLastPacket;
-
-		public MySqlStreamReader(Stream str, Encoding enc)
-		{
-			stream = str;
-			encoding = enc;
-		}
-
-		#region Properties
-
-		public DBVersion Version 
-		{
-			get { return version; }
-			set { version = value; }
-		}
-
-		public Stream Stream 
-		{
-			get { return stream; }
-		}
-
-		public Encoding Encoding 
-		{
-			get { return encoding; }
-			set { encoding = value; }
-		}
-
-		public bool HasMoreData
-		{
-			get 
-			{ 
-				if (stream is MySqlStream)
-					return ((MySqlStream)stream).HasMoreData;
-				return stream.Length > stream.Position; 
-			}
-		}
-
-		public bool IsLastPacket
-		{
-			get { return isLastPacket; }
-		}
-
-		#endregion
-
-		public void Close() 
-		{
-			stream.Close();
-		}
-
-		#region Byte Reading Methods
-
-		public byte ReadByte() 
-		{
-			int b = stream.ReadByte();
-
-			if (b == -1)
-				throw new MySqlException("Lost connection to server");
-			return (byte)b;
-		}
-
-		public int Read(byte[] buf, int offset, int len)
-		{
-			try 
-			{
-				int totalRead = 0;
-				while (len > 0) 
-				{
-					int bytesRead = stream.Read(buf, offset, len);
-
-					if (bytesRead == 0)
-						throw new MySqlException( "Connection unexpectedly terminated", true, null );
-
-					offset += bytesRead;
-					len -= bytesRead;
-					totalRead += bytesRead;
-				}
-
-				return totalRead;
-			}
-			catch (IOException ioe) 
-			{
-				Logger.LogException( ioe ) ;
-				throw new MySqlException( "Connection unexpectedly terminated", true, ioe );
-			}		
-		}
-
-		public int ReadNBytes()
-		{
-			byte c = (byte)ReadByte();
-			if (c < 1 || c > 4) throw new MySqlException("Unexpected byte count received");
-			return ReadInteger((int)c);
-		}
-
-		public void SkipBytes(int len)
-		{
-			while (len-- > 0)
-				stream.ReadByte();
-		}
-
-		#endregion
-
-		#region String Functions
-
-		public string ReadString(long length) 
-		{
-			byte[] buf = new byte[length];
-			stream.Read(buf, 0, (int)length);
-			return encoding.GetString(buf, 0, buf.Length);
-		}
-
-		public string ReadString() 
-		{
-			MemoryStream ms = new MemoryStream();
-
-			int b = stream.ReadByte();
-			while (b != 0 && b != -1)
-			{
-				ms.WriteByte((byte)b);
-				b = stream.ReadByte();
-			}
-
-			return encoding.GetString(ms.GetBuffer(), 0, (int)ms.Length);
-		}
-
-		public string ReadLenString()
-		{
-			long len = ReadPackedInteger();
-			return ReadString(len);
-		}
-
-		#endregion
-
-		#region Numeric Functions
-
-		public long GetFieldLength() 
-		{
-			byte c  = (byte)ReadByte();
-
-			switch(c) 
-			{
-				case 251 : return (long)-1;
-				case 252 : return (long)ReadInteger(2);
-				case 253 : return (long)ReadInteger(3);
-				case 254 : return (long)ReadInteger(8);
-				default  : return c;
-			}
-		}
-
-		public ulong ReadLong(int numbytes) 
-		{
-			ulong val = 0;
-			int raise = 1;
-			for (int x=0; x < numbytes; x++)
-			{
-				int b = ReadByte();
-				val += (ulong)(b*raise);
-				raise *= 256;
-			}
-			return val;
-		}
-
-		public int ReadInteger(int numbytes)
-		{
-			return (int)ReadLong(numbytes);
-		}
-
-		public int ReadPackedInteger()
-		{
-			byte c  = (byte)ReadByte();
-
-			switch(c) 
-			{
-				case 251 : return -1;
-				case 252 : return ReadInteger(2);
-				case 253 : return ReadInteger(3);
-				case 254 : return ReadInteger(4);
-				default  : return c;
-			}
-		}
-
-		#endregion
-
-		#region Packet methods
-
-		public void OpenPacket() 
-		{
-			MySqlStream ms = (stream as MySqlStream);
-			if (ms == null)
-				Debug.Assert(ms != null);
-
-			// make sure we have read all the data from the previous packet
-			Debug.Assert(HasMoreData == false, "HasMoreData is true in OpenPacket");
-
-			ms.LoadPacket();
-
-			int peek = ms.PeekByte();
-			if (peek == 0xff) 
-			{
-				int code = ReadInteger(2);
-				string msg = ReadString();
-				throw new MySqlException(msg, code);
-			}
-			isLastPacket = (peek == 0xfe && (stream.Length < 9));
-		}
-
-		public void SkipPacket() 
-		{
-			MySqlStream ms = (stream as MySqlStream);
-			if (ms == null)
-				System.Diagnostics.Debug.Assert(ms != null);
-
-			byte[] tempBuf = new byte[1024];
-            long left = ms.Length - ms.Position;
-            while (left > 0)
-            {
-                long toRead = Math.Min(left, tempBuf.LongLength);
-                ms.Read(tempBuf, 0, (int)toRead);
-                left -= toRead;
-            }
-		}
-
-		#endregion
-
-	}
-}

Deleted: trunk/mysqlclient/MySqlStreamWriter.cs
===================================================================
--- trunk/mysqlclient/MySqlStreamWriter.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/MySqlStreamWriter.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -1,173 +0,0 @@
-// Copyright (C) 2004-2006 MySQL AB
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation
-//
-// There are special exceptions to the terms and conditions of the GPL 
-// as it is applied to this software. View the full text of the 
-// exception in file EXCEPTIONS in the directory of this software 
-// distribution.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
-
-using System;
-using System.IO;
-using System.Text;
-using MySql.Data.Common;
-
-namespace MySql.Data.MySqlClient
-{
-	internal class MySqlStreamWriter
-	{
-		private MemoryStream	memStream;
-		private Stream			realStream;
-		private	Stream			stream;
-		private Encoding		encoding;
-		private DBVersion		version;
-
-		public MySqlStreamWriter(Stream stream, Encoding enc)
-		{
-			this.realStream = stream;
-			memStream = new MemoryStream();
-			this.stream = realStream;
-			encoding = enc;
-		}
-
-		#region Properties
-
-		public Encoding Encoding 
-		{ 
-			get { return encoding; }
-			set { encoding = value; }
-		}
-
-		public Stream Stream 
-		{
-			get { return stream; }
-		}
-
-		public DBVersion Version 
-		{
-			get { return version; }
-			set { version = value; }
-		}
-
-		#endregion
-
-		public void StartPacket(long len, bool resetSeq) 
-		{
-			if (len == 0) 
-				stream = memStream;
-			if (resetSeq)
-				((MySqlStream)realStream).SequenceByte = 0;
-			stream.SetLength(len);
-		}
-
-		public void Flush() 
-		{
-			if (stream is MemoryStream) 
-			{
-				realStream.SetLength(memStream.Length);
-				realStream.Write(memStream.GetBuffer(), 0, (int)memStream.Length);
-				stream = realStream;
-			}
-			stream.Flush();
-		}
-
-
-		#region Bytes Methods
-
-		public void WriteByte(byte b) 
-		{
-			stream.WriteByte(b);
-		}
-
-		public void Write(byte[] buffer) 
-		{
-			stream.Write(buffer, 0, buffer.Length);
-		}
-
-		public void Write(byte[] buffer, int offset, int count) 
-		{
-			stream.Write(buffer, offset, count);
-		}
-
-		#endregion
-
-		#region Numeric Methods
-
-		public void WriteLength( long length ) 
-		{
-			if (length < 251)
-				WriteByte( (byte)length );
-			else if ( length < 65536L )
-			{
-				WriteByte( 252 );
-				WriteInteger( length, 2 );
-			}
-			else if ( length < 16777216L )
-			{
-				WriteByte( 253 );
-				WriteInteger( length, 3 );
-			}
-			else 
-			{
-				WriteByte( 254 );
-				WriteInteger( length, 4 );
-			}
-		}
-
-		/// <summary>
-		/// WriteInteger
-		/// </summary>
-		/// <param name="v"></param>
-		/// <param name="numbytes"></param>
-		public void WriteInteger( long v, int numbytes )
-		{
-			long val = v;
-
-			if (numbytes < 1 || numbytes > 4) 
-				throw new ArgumentOutOfRangeException("Wrong byte count for WriteInteger");
-
-			for (int x=0; x < numbytes; x++)
-			{
-				stream.WriteByte( (byte)(val&0xff) );
-				val >>= 8;
-			}
-		}
-
-		#endregion
-
-		#region String methods
-
-		public void WriteLenString( string s )
-		{
-			byte[] bytes = encoding.GetBytes(s);
-			WriteLength( bytes.Length );
-			stream.Write( bytes, 0,bytes.Length );
-		}
-
-		public void WriteString(string v )
-		{
-			WriteStringNoNull( v );
-			stream.WriteByte(0);
-		}
- 
-		public void WriteStringNoNull(string v )
-		{
-			byte[] bytes = encoding.GetBytes(v);
-			stream.Write(bytes, 0, bytes.Length);
-		}
-
-		#endregion
-
-	}
-}

Modified: trunk/mysqlclient/NativeDriver.cs
===================================================================
--- trunk/mysqlclient/NativeDriver.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/NativeDriver.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -29,6 +29,7 @@
 using System.Collections;
 using System.Text;
 using MySql.Data.Types;
+using System.Diagnostics;
 
 namespace MySql.Data.MySqlClient
 {
@@ -44,8 +45,7 @@
 		protected String				encryptionSeed;
 		protected ClientFlags			connectionFlags;
 
-		protected MySqlStreamReader		reader;
-		protected MySqlStreamWriter		writer;
+		protected MySqlStream		stream;
 		private   BitArray				nullMap;
 
         private int warningCount;
@@ -93,33 +93,32 @@
         /// <param name="length">The number of bytes to send</param>
 		private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length) 
 		{
-			int len = 1;
-			if (bytes != null)
-				len += length;
-			writer.StartPacket(len, true);
-			writer.WriteByte((byte)cmd);
-			if (bytes != null)
-				writer.Write(bytes, 0, length);
-			writer.Flush();
+            Debug.Assert(length == 0 || bytes != null);
+
+            stream.StartOutput((ulong)length + 1, true);
+            stream.WriteByte((byte)cmd);
+            if (length > 0)
+                stream.Write(bytes, 0, length);
+            stream.Flush();
 		}
 
 		private void ReadOk(bool read) 
 		{
 			if (read)
-				reader.OpenPacket();
-			byte marker = reader.ReadByte();
+				stream.OpenPacket();
+			byte marker = (byte)stream.ReadByte();
 			if (marker != 0)
 				throw new MySqlException("Out of sync with server", true, null);
 
-			long affectedRows = reader.GetFieldLength();
-			long lastInsertId = reader.GetFieldLength();
-			if (reader.HasMoreData)
+			long affectedRows = stream.ReadFieldLength();
+			long lastInsertId = stream.ReadFieldLength();
+			if (stream.HasMoreData)
 			{
-				serverStatus = (ServerStatusFlags)reader.ReadInteger(2);
-				int warningCount = reader.ReadInteger(2);
-				if (reader.HasMoreData)
+				serverStatus = (ServerStatusFlags)stream.ReadInteger(2);
+				int warningCount = stream.ReadInteger(2);
+				if (stream.HasMoreData)
 				{
-					string msg = reader.ReadLenString();
+					string msg = stream.ReadLenString();
 				}
 			}
 		}
@@ -151,7 +150,7 @@
 			base.Open();
 
 			// connect to one of our specified hosts
-			Stream stream;
+			Stream baseStream;
 			try 
 			{
 #if !CF
@@ -159,7 +158,7 @@
 				{
 					SharedMemoryStream str = new SharedMemoryStream(Settings.SharedMemoryName);
 					str.Open(Settings.ConnectionTimeout);
-					stream = str;
+					baseStream = str;
 				}
 				else 
 				{
@@ -168,7 +167,7 @@
 					if (Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe)
 						pipeName = null;
 					StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName);
-					stream = sc.GetStream(Settings.ConnectionTimeout);
+					baseStream = sc.GetStream(Settings.ConnectionTimeout);
 #if !CF
 				}
 #endif
@@ -179,20 +178,18 @@
 			}
 
 
-			if (stream == null) 
+			if (baseStream == null) 
 				throw new MySqlException("Unable to connect to any of the specified MySQL hosts");
-			MySqlStream myStream = new MySqlStream(stream);
 
-			reader = new MySqlStreamReader(myStream, encoding);
-			writer = new MySqlStreamWriter(myStream, encoding);
-
+            stream = new MySqlStream(baseStream, encoding);
+            
 			// read off the welcome packet and parse out it's values
-			reader.OpenPacket();
-			protocol = reader.ReadByte();
-			string versionString = reader.ReadString();
+			stream.OpenPacket();
+			protocol = stream.ReadByte();
+			string versionString = stream.ReadString();
 			version = DBVersion.Parse(versionString);
-			threadId = (int)reader.ReadInteger(4);
-			encryptionSeed = reader.ReadString();
+			threadId = (int)stream.ReadInteger(4);
+			encryptionSeed = stream.ReadString();
 
 			// starting with 4.0.8, maxSinglePacket should be 0xffffff
 			if ( version.isAtLeast(4,0,8))
@@ -200,55 +197,51 @@
 
 			// read in Server capabilities if they are provided
 			serverCaps = 0;
-			if (reader.HasMoreData)
-				serverCaps = (ClientFlags)reader.ReadInteger(2);
+			if (stream.HasMoreData)
+				serverCaps = (ClientFlags)stream.ReadInteger(2);
 
 			// based on our settings, set our connection flags
 			SetConnectionFlags();
 
-			writer.StartPacket(0, false);
-			writer.WriteInteger((int)connectionFlags, 
+			stream.StartOutput(0, false);
+			stream.WriteInteger((int)connectionFlags, 
                 version.isAtLeast(4,1,0) ? 4 : 2);
-			writer.WriteInteger(MaxSinglePacket, 
+			stream.WriteInteger(MaxSinglePacket, 
                 version.isAtLeast(4,1,0) ? 4 : 3);
 
 			// 4.1.1 included some new server status info
-			if (reader.HasMoreData) 
+			if (stream.HasMoreData) 
 			{
 				/* New protocol with 16 bytes to describe server characteristics */
-				serverCharSetIndex = reader.ReadInteger(1);
+				serverCharSetIndex = stream.ReadInteger(1);
 
-				serverStatus = (ServerStatusFlags)reader.ReadInteger(2);
-				reader.SkipBytes(13);
+				serverStatus = (ServerStatusFlags)stream.ReadInteger(2);
+				stream.SkipBytes(13);
             }
 
             if (version.isAtLeast(4,1,1))
             {
-                string seedPart2 = reader.ReadString();
+                string seedPart2 = stream.ReadString();
                 encryptionSeed += seedPart2;
 
-                writer.WriteByte(8);
-				writer.Write( new byte[23], 0, 23 );
+                stream.WriteByte(8);
+				stream.Write(new byte[23]);
 			}
 
-			Authenticate();
+            stream.MaxBlockLength = MaxSinglePacket;
 
+            Authenticate();
+
 			// if we are using compression, then we use our CompressedStream class
 			// to hide the ugliness of managing the compression
 			if ((connectionFlags & ClientFlags.COMPRESS) != 0)
-			{
-				MySqlStream compStream = new MySqlStream(new CompressedStream(stream));
-				reader = new MySqlStreamReader(compStream, encoding);
-				writer = new MySqlStreamWriter(compStream, encoding);
-			}
+				stream = new MySqlStream(new CompressedStream(baseStream),encoding);
 
-			((MySqlStream)reader.Stream).MaxSinglePacket = MaxSinglePacket;
-			((MySqlStream)writer.Stream).MaxSinglePacket = MaxSinglePacket;
+			// give our stream the server version we are connected to.  
+            // We may have some fields that are read differently based 
+            // on the version of the server we are connected to.
+			stream.Version = this.version;
 
-			// give our reader the server version we are connected to.  Our reader may have some fields
-			// that are read differently based on the version of the server we are connected to.
-			reader.Version = writer.Version = this.version;
-
 			isOpen = true;
 		}
 
@@ -305,27 +298,28 @@
 			connectionFlags = flags;
 		}
 
-
-		/// <summary>Perform an authentication against a 4.1.1 server</summary>
+		/// <summary>
+        /// Perform an authentication against a 4.1.1 server
+        /// </summary>
 		private void Authenticate411()
 		{
-			if ( (connectionFlags & ClientFlags.SECURE_CONNECTION) == 0)
+			if ((connectionFlags & ClientFlags.SECURE_CONNECTION) == 0)
 				AuthenticateOld();
 
-			writer.Write( Crypt.Get411Password( connectionString.Password, this.encryptionSeed ));
+			stream.Write( Crypt.Get411Password( connectionString.Password, this.encryptionSeed ));
 			if ( (connectionFlags & ClientFlags.CONNECT_WITH_DB) != 0 && connectionString.Database != null)
-				writer.WriteString( connectionString.Database );
-			writer.Flush();
+				stream.WriteString(connectionString.Database);
+			stream.Flush();
 
 			// this result means the server wants us to send the password using
 			// old encryption
-			reader.OpenPacket();
-			if (reader.IsLastPacket)
+			stream.OpenPacket();
+			if (stream.IsLastPacket)
 			{
-				writer.StartPacket(0, false);
-				writer.WriteString( Crypt.EncryptPassword( 
-					connectionString.Password, this.encryptionSeed.Substring(0,8), true ) );
-				writer.Flush();
+				stream.StartOutput(0, false);
+				stream.WriteString(Crypt.EncryptPassword( 
+					connectionString.Password, this.encryptionSeed.Substring(0,8), true ));
+				stream.Flush();
 				ReadOk(true);
 			}
 			else 
@@ -334,20 +328,20 @@
 
 		private void AuthenticateOld()
 		{
-			writer.WriteString( Crypt.EncryptPassword( 
+			stream.WriteString( Crypt.EncryptPassword( 
 				connectionString.Password, encryptionSeed, protocol > 9));
-			if ( (connectionFlags & ClientFlags.CONNECT_WITH_DB) != 0 && connectionString.Database != null)
-				writer.WriteString( connectionString.Database );
-			writer.Flush();
+			if ((connectionFlags & ClientFlags.CONNECT_WITH_DB) != 0 && connectionString.Database != null)
+				stream.WriteString(connectionString.Database);
+			stream.Flush();
 			ReadOk(true);
 		}
 
 		public void Authenticate()
 		{
 			// write the user id to the auth packet
-			writer.WriteString( connectionString.UserID ); 
+			stream.WriteString(connectionString.UserID); 
 
-			if ( version.isAtLeast(4,1,1) )
+			if (version.isAtLeast(4,1,1))
 				Authenticate411();
 			else
 				AuthenticateOld();
@@ -355,8 +349,8 @@
 
 		public override void Reset()
 		{
-			writer.StartPacket(0, true);
-			writer.WriteByte((byte)DBCmd.CHANGE_USER);
+            stream.StartOutput(0, true);
+			stream.WriteByte((byte)DBCmd.CHANGE_USER);
 			Authenticate();
 		}
 
@@ -380,7 +374,7 @@
             // the server will respond in one of several ways with the first byte indicating
             // the type of response.
             // 0 == ok packet.  This indicates non-select queries
-            // 0xff == error packet.  This is handled in reader.OpenPacket
+            // 0xff == error packet.  This is handled in stream.OpenPacket
             // > 0 = number of columns in select query
             // We don't actually read the result here since a single query can generate
             // multiple resultsets and we don't want to duplicate code.  See ReadResult
@@ -392,11 +386,9 @@
 		public override void Close() 
 		{
 			if (isOpen)
-				ExecuteCommand( DBCmd.QUIT, null, 0 );
+				ExecuteCommand(DBCmd.QUIT, null, 0);
 
-			writer.Stream.Close();
-			reader.Close();
-
+			stream.Close();
 			base.Close();
 		}
 
@@ -436,29 +428,29 @@
             // again if necessary.
             serverStatus &= ~(ServerStatusFlags.AnotherQuery |
                     ServerStatusFlags.MoreResults);
-			reader.OpenPacket();
+			stream.OpenPacket();
 
-			long fieldCount = reader.GetFieldLength();
+			long fieldCount = stream.ReadFieldLength();
             if (fieldCount > 0)
                 return fieldCount;
 
 			if (-1 == fieldCount)
 			{
-				string filename = reader.ReadString();
+				string filename = stream.ReadString();
 				SendFileToServer(filename);
 
                 return ReadResult(ref affectedRows, ref lastInsertId);
 			}
 
-			affectedRows = (ulong)reader.GetFieldLength();
-			lastInsertId = (long)reader.GetFieldLength();
+			affectedRows = (ulong)stream.ReadFieldLength();
+			lastInsertId = (long)stream.ReadFieldLength();
 			if ( version.isAtLeast(4,1,0) ) 
 			{
-				serverStatus = (ServerStatusFlags)reader.ReadInteger(2);
-				warningCount = reader.ReadInteger(2);
-				if (reader.HasMoreData) 
+				serverStatus = (ServerStatusFlags)stream.ReadInteger(2);
+				warningCount = stream.ReadInteger(2);
+				if (stream.HasMoreData) 
 				{
-					reader.ReadLenString();  //TODO: server message
+					stream.ReadLenString();  //TODO: server message
 				}
 			}
             return fieldCount;
@@ -478,22 +470,22 @@
 			try 
 			{
 				fs = new FileStream(filename, FileMode.Open);
-				writer.StartPacket(fs.Length, true);
+//				stream.StartPacket(fs.Length, true);
 
 				long len = fs.Length;
 				while (len > 0) 
 				{
 					int count = fs.Read( buffer, 0, 4092 );
-					writer.Write( buffer, 0, count );
+					//stream.Write(buffer, 0, count);
 					len -= count;
 				}
-				writer.Flush();
+				stream.Flush();
 
 				// write the terminating packet
 				//TODO: fix this
-//				writer.WriteInteger(0, 3);
-//				writer.WriteByte(this.SequenceByte ++);
-//				writer.Flush();
+//				stream.WriteInteger(0, 3);
+//				stream.WriteByte(this.SequenceByte ++);
+//				stream.Flush();
 			}
 			catch (Exception ex)
 			{
@@ -508,10 +500,10 @@
         public override bool SkipDataRow()
         {
             bool result = true;
-            if (!reader.HasMoreData)
+            if (!stream.HasMoreData)
                 result = FetchDataRow(-1, 0, 0);
             if (result)
-                reader.SkipPacket();
+                stream.SkipPacket();
             return result;
         }
 
@@ -520,8 +512,8 @@
 			// if we are binary, then we need to load in our null bitmap
 			nullMap = null;
 			byte[] nullMapBytes = new byte[ (fieldCount+9)/8 ];
-			reader.ReadByte();
-			reader.Read(nullMapBytes, 0, nullMapBytes.Length);
+			stream.ReadByte();
+			stream.Read(nullMapBytes, 0, nullMapBytes.Length);
 			nullMap = new BitArray( nullMapBytes );
 		}
 
@@ -534,14 +526,12 @@
 				isNull = nullMap [index+2];
 			else
 			{
-				length = reader.GetFieldLength();
+				length = stream.ReadFieldLength();
 				isNull = length == -1;
 			}
 
-//			if (valObject.IsNull) return valObject;
-
-			reader.Encoding = field.Encoding;
-			return valObject.ReadValue(reader, length, isNull);
+			stream.Encoding = field.Encoding;
+			return valObject.ReadValue(stream, length, isNull);
 		}
 
 		public override void SkipColumnValue(IMySqlValue valObject)
@@ -549,13 +539,13 @@
 			long length = -1;
 			if (nullMap == null)
 			{
-				length = reader.GetFieldLength();
+				length = stream.ReadFieldLength();
 				if (length == -1) return;
 			}
 			if (length > -1)
-				reader.SkipBytes( (int)length);
+				stream.SkipBytes( (int)length);
 			else
-				valObject.SkipValue(reader);				
+				valObject.SkipValue(stream);				
 		}
 
 		public override MySqlField[] ReadColumnMetadata(int count)
@@ -578,23 +568,23 @@
 				field = GetFieldMetaData41();
 			else 
 			{
-				reader.OpenPacket();
+				stream.OpenPacket();
 				field = new MySqlField( this.Version );
 
 				field.Encoding = encoding;
-				field.TableName = reader.ReadLenString();
-				field.ColumnName = reader.ReadLenString();
-				field.ColumnLength = reader.ReadNBytes();
-				MySqlDbType type = (MySqlDbType)reader.ReadNBytes();
-				reader.ReadByte();
+				field.TableName = stream.ReadLenString();
+				field.ColumnName = stream.ReadLenString();
+				field.ColumnLength = stream.ReadNBytes();
+				MySqlDbType type = (MySqlDbType)stream.ReadNBytes();
+				stream.ReadByte();
                 ColumnFlags colFlags;
 				if ((Flags & ClientFlags.LONG_FLAG) != 0)
-					colFlags = (ColumnFlags)reader.ReadInteger(2);
+					colFlags = (ColumnFlags)stream.ReadInteger(2);
 				else 
-					colFlags = (ColumnFlags)reader.ReadByte();
+					colFlags = (ColumnFlags)stream.ReadByte();
                 field.SetTypeAndFlags(type, colFlags);
 
-				field.Scale = (byte)reader.ReadByte();
+				field.Scale = (byte)stream.ReadByte();
 				if ( !version.isAtLeast(3,23,15) && version.isAtLeast(3,23,0))
 					field.Scale++;
 			}
@@ -604,31 +594,31 @@
 
 		private MySqlField GetFieldMetaData41() 
 		{
-			MySqlField field = new MySqlField( this.Version );
+			MySqlField field = new MySqlField(this.Version);
 
-			reader.OpenPacket();
+			stream.OpenPacket();
 			field.Encoding = encoding;
-			field.CatalogName = reader.ReadLenString();
-			field.DatabaseName = reader.ReadLenString();
-			field.TableName = reader.ReadLenString();
-			field.RealTableName = reader.ReadLenString();
-			field.ColumnName = reader.ReadLenString();
-			field.OriginalColumnName = reader.ReadLenString();
-			reader.ReadByte();
-			field.CharactetSetIndex = reader.ReadInteger(2);
-			field.ColumnLength = reader.ReadInteger(4);
-			MySqlDbType type = (MySqlDbType)reader.ReadByte();
+			field.CatalogName = stream.ReadLenString();
+			field.DatabaseName = stream.ReadLenString();
+			field.TableName = stream.ReadLenString();
+			field.RealTableName = stream.ReadLenString();
+			field.ColumnName = stream.ReadLenString();
+			field.OriginalColumnName = stream.ReadLenString();
+			stream.ReadByte();
+			field.CharactetSetIndex = stream.ReadInteger(2);
+			field.ColumnLength = stream.ReadInteger(4);
+			MySqlDbType type = (MySqlDbType)stream.ReadByte();
             ColumnFlags colFlags;
 			if ((Flags & ClientFlags.LONG_FLAG) != 0)
-				colFlags = (ColumnFlags)reader.ReadInteger(2);
+				colFlags = (ColumnFlags)stream.ReadInteger(2);
 			else 
-				colFlags = (ColumnFlags)reader.ReadByte();
+				colFlags = (ColumnFlags)stream.ReadByte();
             field.SetTypeAndFlags(type, colFlags);
 
-			field.Scale = (byte)reader.ReadByte();
+			field.Scale = (byte)stream.ReadByte();
 
-			if (reader.HasMoreData)
-				reader.ReadInteger(2);	// reserved
+			if (stream.HasMoreData)
+				stream.ReadInteger(2);	// reserved
 
 			if (charSets != null)
 				field.Encoding = CharSetMap.GetEncoding(this.version, (string)charSets[field.CharactetSetIndex]);
@@ -645,15 +635,15 @@
 
         private void CheckEOF()
         {
-            if (!reader.IsLastPacket)
+            if (!stream.IsLastPacket)
                 throw new MySqlException("Expected end of data packet");
 
-            reader.ReadByte();  // read off the 254
+            stream.ReadByte();  // read off the 254
 
-            if (reader.HasMoreData && version.isAtLeast(4, 1, 0))
+            if (stream.HasMoreData && version.isAtLeast(4, 1, 0))
             {
-                warningCount = reader.ReadInteger(2);
-                serverStatus = (ServerStatusFlags)reader.ReadInteger(2);
+                warningCount = stream.ReadInteger(2);
+                serverStatus = (ServerStatusFlags)stream.ReadInteger(2);
 
                 // if we are at the end of this cursor based resultset, then we remove
                 // the last row sent status flag so our next fetch doesn't abort early
@@ -668,7 +658,7 @@
 
         private void ReadEOF() 
 		{
-			reader.OpenPacket();
+			stream.OpenPacket();
             CheckEOF();
 		}
 
@@ -680,17 +670,17 @@
 			byte[] bytes = encoding.GetBytes(sql);
 			ExecuteCommand(DBCmd.PREPARE, bytes, bytes.Length);
 
-			reader.OpenPacket();
+			stream.OpenPacket();
 
-			int marker = reader.ReadByte();
+			int marker = stream.ReadByte();
 			if (marker != 0)
 				throw new MySqlException("Expected prepared statement marker");
 
-			int statementId = reader.ReadInteger(4);
-			int numCols = reader.ReadInteger(2);
-			int numParams = reader.ReadInteger(2);
+			int statementId = stream.ReadInteger(4);
+			int numCols = stream.ReadInteger(2);
+			int numParams = stream.ReadInteger(2);
             //TODO: find out what this is needed for
-            reader.ReadInteger(3);
+            stream.ReadInteger(3);
             if (numParams > 0)
 			{
 				parameters = ReadColumnMetadata(numParams);
@@ -705,8 +695,8 @@
 			{
                 while (numCols-- > 0)
                 {
-                    reader.OpenPacket();
-                    reader.SkipPacket();
+                    stream.OpenPacket();
+                    stream.SkipPacket();
                 }
 
 				ReadEOF();
@@ -723,8 +713,8 @@
 /*			CommandResult result = (CommandResult)commandResults[lastCommandResult];
 			result.ReadRemainingColumns();
 
-			reader.OpenPacket();
-			if (! reader.IsLastPacket)
+			stream.OpenPacket();
+			if (! stream.IsLastPacket)
 				throw new MySqlException("Cursor reading out of sync");
 
 			ReadEOF(false);
@@ -745,16 +735,16 @@
 			if ( (serverStatus & ServerStatusFlags.LastRowSent) != 0)
 				return false;
 
-			writer.StartPacket(9, true);
-			writer.WriteByte((byte)DBCmd.FETCH);
-			writer.WriteInteger(statementId, 4);
-			writer.WriteInteger(1, 4);
-			writer.Flush();
+			stream.StartPacket(9, true);
+			stream.WriteByte((byte)DBCmd.FETCH);
+			stream.WriteInteger(statementId, 4);
+			stream.WriteInteger(1, 4);
+			stream.Flush();
 
 			lastCommandResult = statementId;
             */
-			reader.OpenPacket();
-			if (reader.IsLastPacket)
+			stream.OpenPacket();
+			if (stream.IsLastPacket)
 			{
 				CheckEOF();
 				return false;

Modified: trunk/mysqlclient/PreparedStatement.cs
===================================================================
--- trunk/mysqlclient/PreparedStatement.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/PreparedStatement.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -73,11 +73,11 @@
 
 		public override void Execute(MySqlParameterCollection parameters)
 		{
-			MySqlStreamWriter writer = new MySqlStreamWriter(new MemoryStream(), driver.Encoding);
+			MySqlStream stream = new MySqlStream(driver.Encoding);
 
 			//TODO: support long data here
 			// create our null bitmap
-			BitArray nullMap = new BitArray(parameters.Count); //metaData.Length );
+			BitArray nullMap = new BitArray(parameters.Count);
 
             // now we run through the parameters that PREPARE sent back and use
             // those names to index into the parameters the user gave us.
@@ -94,12 +94,12 @@
 			nullMap.CopyTo(nullMapBytes, 0);
 
 			// start constructing our packet
-			writer.WriteInteger(Id, 4);
-			writer.WriteByte((byte)pageSize);          // flags; always 0 for 4.1
-			writer.WriteInteger(1, 4);    // interation count; 1 for 4.1
-			writer.Write(nullMapBytes);
+			stream.WriteInteger(Id, 4);
+            stream.WriteByte((byte)pageSize);          // flags; always 0 for 4.1
+            stream.WriteInteger(1, 4);    // interation count; 1 for 4.1
+            stream.Write(nullMapBytes);
 			//if (parameters != null && parameters.Count > 0)
-				writer.WriteByte(1);			// rebound flag
+            stream.WriteByte(1);			// rebound flag
 			//else
 			//	packet.WriteByte( 0 );
 			//TODO:  only send rebound if parms change
@@ -110,7 +110,7 @@
                 foreach (MySqlField param in paramList)
                 {
                     MySqlParameter parm = parameters[param.ColumnName];
-                    writer.WriteInteger((long)parm.GetPSType(), 2);
+                    stream.WriteInteger((long)parm.GetPSType(), 2);
                 }
 
                 // now write out all non-null values
@@ -124,14 +124,14 @@
                     if (parm.Value == DBNull.Value || parm.Value == null)
                         continue;
 
-                    writer.Encoding = param.Encoding;
-                    parm.Serialize(writer, true);
+                    stream.Encoding = param.Encoding;
+                    parm.Serialize(stream, true);
                 }
             }
 
 			executionCount ++;
 
-            driver.ExecuteStatement(((System.IO.MemoryStream)writer.Stream).ToArray());
+            driver.ExecuteStatement(stream.InternalBuffer.ToArray());
 		}
 
         public override bool ExecuteNext()

Modified: trunk/mysqlclient/Resources.Designer.cs
===================================================================
--- trunk/mysqlclient/Resources.Designer.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Resources.Designer.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -142,6 +142,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Connection unexpectedly terminated..
+        /// </summary>
+        internal static string ConnectionBroken {
+            get {
+                return ResourceManager.GetString("ConnectionBroken", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Connection must be valid and open.
         /// </summary>
         internal static string ConnectionMustBeOpen {
@@ -241,6 +250,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to An incorrect response was received from the server..
+        /// </summary>
+        internal static string IncorrectTransmission {
+            get {
+                return ResourceManager.GetString("IncorrectTransmission", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Index and length use more bytes than to has room for.
         /// </summary>
         internal static string IndexAndLengthTooBig {

Modified: trunk/mysqlclient/Resources.resx
===================================================================
--- trunk/mysqlclient/Resources.resx	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Resources.resx	2006-07-30 03:31:34 UTC (rev 279)
@@ -255,4 +255,7 @@
   <data name="ConnectionBroken" xml:space="preserve">
     <value>Connection unexpectedly terminated.</value>
   </data>
+  <data name="IncorrectTransmission" xml:space="preserve">
+    <value>An incorrect response was received from the server.</value>
+  </data>
 </root>
\ No newline at end of file

Modified: trunk/mysqlclient/Statement.cs
===================================================================
--- trunk/mysqlclient/Statement.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Statement.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -80,9 +80,8 @@
             // tokenize the sql
             ArrayList tokenArray = TokenizeSql(commandText);
 
-            MySqlStreamWriter writer = new MySqlStreamWriter(new MemoryStream(), 
-                driver.Encoding);
-            writer.Version = driver.Version;
+            MySqlStream stream = new MySqlStream(driver.Encoding);
+            stream.Version = driver.Version;
 
             // make sure our token array ends with a ;
             string lastToken = (string)tokenArray[tokenArray.Count - 1];
@@ -95,18 +94,18 @@
                     continue;
                 if (token == ";")
                 {
-                    buffers.Add(writer.Stream);
-                    writer = new MySqlStreamWriter(new MemoryStream(), driver.Encoding);
+                    buffers.Add(stream.InternalBuffer);
+                    stream = new MySqlStream(driver.Encoding);
                     continue;
                 }
                 if (token[0] == parameters.ParameterMarker)
                 {
-                    if (SerializeParameter(parameters, writer, token))
+                    if (SerializeParameter(parameters, stream, token))
                         continue;
                 }
  
                 // our fall through case is to write the token to the byte stream
-                writer.WriteStringNoNull(token);
+                stream.WriteStringNoNull(token);
             }
         }
 
@@ -120,7 +119,7 @@
         /// </remarks>
         /// <returns>True if the parameter was successfully serialized, false otherwise.</returns>
         private bool SerializeParameter(MySqlParameterCollection parameters, 
-            MySqlStreamWriter writer, string parmName)
+            MySqlStream stream, string parmName)
         {
             int index = parameters.IndexOf(parmName);
             if (index == -1)
@@ -132,7 +131,7 @@
                 throw new MySqlException("Parameter '" + parmName + "' must be defined");
             }
             MySqlParameter parameter = parameters[index];
-            parameter.Serialize(writer, false);
+            parameter.Serialize(stream, false);
             return true;
         }
 

Modified: trunk/mysqlclient/Types/MySqlBinary.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlBinary.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlBinary.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -93,7 +93,7 @@
 			}
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			byte[] buffToWrite = null;
 
@@ -106,10 +106,10 @@
                     length = s.Length;
                 else
 				    s = s.Substring(0, length);
-				buffToWrite = writer.Encoding.GetBytes(s);
+				buffToWrite = stream.Encoding.GetBytes(s);
 			}
 			else if (val is Char[]) 
-				buffToWrite = writer.Encoding.GetBytes(val as char[]);
+				buffToWrite = stream.Encoding.GetBytes(val as char[]);
 
             // we assume zero length means write all of the value
             if (length == 0)
@@ -120,60 +120,61 @@
 
 			if (binary) 
 			{
-				writer.WriteLength(length);
-				writer.Write(buffToWrite, 0, length);
+				stream.WriteLength(length);
+				stream.Write(buffToWrite, 0, length);
 			}
 			else 
 			{
-				if (writer.Version.isAtLeast(4,1,0))
-					writer.WriteStringNoNull("_binary ");
+				if (stream.Version.isAtLeast(4,1,0))
+					stream.WriteStringNoNull("_binary ");
 
-				writer.WriteByte((byte)'\'');
-				EscapeByteArray(buffToWrite, length, writer);
-				writer.WriteByte((byte)'\'');
+				stream.WriteByte((byte)'\'');
+				EscapeByteArray(buffToWrite, length, stream);
+				stream.WriteByte((byte)'\'');
 			}	
 		}
 
-		private void EscapeByteArray( byte[] bytes, int length, MySqlStreamWriter writer )
+		private void EscapeByteArray(byte[] bytes, int length, MySqlStream stream)
 		{
-			System.IO.MemoryStream ms = (System.IO.MemoryStream)writer.Stream;
-			ms.Capacity += (length * 2);
+		//	System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
+		//	ms.Capacity += (length * 2);
 
 			for (int x=0; x < length; x++)
 			{
 				byte b = bytes[x];
 				if (b == '\0') 
 				{
-					writer.WriteByte( (byte)'\\' );
-					writer.WriteByte( (byte)'0' );
+					stream.WriteByte( (byte)'\\' );
+					stream.WriteByte( (byte)'0' );
 				}
 				
 				else if (b == '\\' || b == '\'' || b == '\"')
 				{
-					writer.WriteByte( (byte)'\\' );
-					writer.WriteByte( b );
+					stream.WriteByte( (byte)'\\' );
+					stream.WriteByte( b );
 				}
 				else
-					writer.WriteByte( b );
+					stream.WriteByte( b );
 			}
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlBinary(type, true);
+			if (nullVal) 
+                return new MySqlBinary(type, true);
 
 			if (length == -1)
-				length = (long)reader.GetFieldLength();
+				length = (long)stream.ReadFieldLength();
 
 			byte[] newBuff = new byte[length];
-			reader.Read(newBuff, 0, (int)length);
+			stream.Read(newBuff, 0, (int)length);
 			return new MySqlBinary(type, newBuff);
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			long len = reader.GetFieldLength();
-			reader.SkipBytes((int)len);
+			long len = stream.ReadFieldLength();
+			stream.SkipBytes((int)len);
 		}
 
 		#endregion
@@ -247,12 +248,12 @@
 			else if (ourValue is String) 
 			{
 				string s = (ourValue as string).Substring(0, length);
-				buffToWrite = writer.Encoding.GetBytes(s);
+				buffToWrite = stream.Encoding.GetBytes(s);
 				length = buffToWrite.Length;
 			}
 			else if (ourValue is Char[]) 
 			{
-				buffToWrite = writer.Encoding.GetBytes( (ourValue as char[]) );
+				buffToWrite = stream.Encoding.GetBytes( (ourValue as char[]) );
 				length = buffToWrite.Length;
 			}
 
@@ -261,17 +262,17 @@
 
 			if (binary) 
 			{
-				writer.WriteLength( length );
-				writer.Write( buffToWrite, 0, length );
+				stream.WriteLength( length );
+				stream.Write( buffToWrite, 0, length );
 			}
 			else 
 			{
-				if ( writer.Version.isAtLeast(4,1,0))
-					writer.WriteStringNoNull( "_binary " );
+				if ( stream.Version.isAtLeast(4,1,0))
+					stream.WriteStringNoNull( "_binary " );
 
-				writer.WriteByte( (byte)'\'');
+				stream.WriteByte( (byte)'\'');
 				EscapeByteArray( buffToWrite, length, writer );
-				writer.WriteByte((byte)'\'');
+				stream.WriteByte((byte)'\'');
 			}
 		}
 
@@ -289,7 +290,7 @@
 
 		private void EscapeByteArray( byte[] bytes, int length, PacketWriter writer )
 		{
-			System.IO.MemoryStream ms = (System.IO.MemoryStream)writer.Stream;
+			System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
 			ms.Capacity += (length * 2);
 
 			for (int x=0; x < length; x++)
@@ -297,17 +298,17 @@
 				byte b = bytes[x];
 				if (b == '\0') 
 				{
-					writer.WriteByte( (byte)'\\' );
-					writer.WriteByte( (byte)'0' );
+					stream.WriteByte( (byte)'\\' );
+					stream.WriteByte( (byte)'0' );
 				}
 				
 				else if (b == '\\' || b == '\'' || b == '\"')
 				{
-					writer.WriteByte( (byte)'\\' );
-					writer.WriteByte( b );
+					stream.WriteByte( (byte)'\\' );
+					stream.WriteByte( b );
 				}
 				else
-					writer.WriteByte( b );
+					stream.WriteByte( b );
 			}
 		}
 
@@ -343,17 +344,17 @@
 		internal override MySqlValue ReadValue(PacketReader reader, long length)
 		{
 			if (length == -1)
-				length = (long)reader.GetFieldLength();
+				length = (long)stream.GetFieldLength();
 
 			byte[] newBuff = new byte[length];
-			reader.Read( ref newBuff, 0, length );
+			stream.Read( ref newBuff, 0, length );
 			return new MySqlBinary( newBuff, mySqlDbType );
 		}
 
 		internal override void Skip(PacketReader reader)
 		{
-			long len = reader.GetFieldLength();
-			reader.Skip( len );
+			long len = stream.GetFieldLength();
+			stream.Skip( len );
 		}
 
 	}*/

Modified: trunk/mysqlclient/Types/MySqlBit.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlBit.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlBit.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -70,34 +70,34 @@
             get { return "BIT"; }
         }
 
-        public void WriteValue(MySqlStreamWriter writer, bool binary, object value, int length)
+        public void WriteValue(MySqlStream stream, bool binary, object value, int length)
         {
 			ulong v = Convert.ToUInt64(value);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());
+				stream.WriteStringNoNull(v.ToString());
         }
 
-        public IMySqlValue ReadValue(MySqlStreamReader reader, long length, bool isNull)
+        public IMySqlValue ReadValue(MySqlStream stream, long length, bool isNull)
         {
             if (buffer == null)
                 buffer = new byte[8];
 			if (length == -1) 
 			{
-				length = reader.GetFieldLength();
+				length = stream.ReadFieldLength();
 			}
 			Array.Clear(buffer, 0, buffer.Length);
 			for (long i=length-1; i >= 0; i--)
-				buffer[i] = (byte)reader.ReadByte();
+				buffer[i] = (byte)stream.ReadByte();
 			mValue = BitConverter.ToUInt64(buffer, 0);
 			return this;
         }
 
-        public void SkipValue(MySqlStreamReader reader)
+        public void SkipValue(MySqlStream stream)
         {
-			long len = reader.GetFieldLength();
-            reader.SkipBytes((int)len);
+			long len = stream.ReadFieldLength();
+            stream.SkipBytes((int)len);
         }
 
         public static void SetDSInfo(DataTable dsTable)

Modified: trunk/mysqlclient/Types/MySqlByte.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlByte.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlByte.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -79,31 +79,32 @@
 			get	{ return "TINYINT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			sbyte v = ((IConvertible)val).ToSByte(null);
 			if (binary)
-				writer.Write( BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlByte(true);
+			if (nullVal) 
+                return new MySqlByte(true);
 
             if (length == -1)
-                return new MySqlByte((sbyte)reader.ReadByte());
+                return new MySqlByte((sbyte)stream.ReadByte());
             else
             {
-                string s = reader.ReadString(length);
+                string s = stream.ReadString(length);
                 return new MySqlByte(SByte.Parse(s, CultureInfo.InvariantCulture));
             }
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.ReadByte();
+			stream.ReadByte();
 		}
 
 		#endregion
@@ -158,9 +159,9 @@
 		{
 			sbyte v = Convert.ToSByte( value );
 			if (binary)
-				writer.WriteByte( (byte)v );
+				stream.WriteByte( (byte)v );
 			else
-				writer.WriteStringNoNull( v.ToString() );
+				stream.WriteStringNoNull( v.ToString() );
 		}
 
 
@@ -183,15 +184,15 @@
 		internal override MySqlValue ReadValue(PacketReader reader, long length)
 		{
 			if (length == -1)
-				Value = (sbyte)reader.ReadByte();
+				Value = (sbyte)stream.ReadByte();
 			else 
-				Value = SByte.Parse( reader.ReadString( length ) );
+				Value = SByte.Parse( stream.ReadString( length ) );
 			return this;
 		}
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.ReadByte();
+			stream.ReadByte();
 		}
 */
 

Modified: trunk/mysqlclient/Types/MySqlDateTime.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlDateTime.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlDateTime.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -182,11 +182,11 @@
 		}
 
 
-		private void SerializeText(MySqlStreamWriter writer, DateTime value) 
+		private void SerializeText(MySqlStream stream, DateTime value) 
 		{
 			string val = String.Empty;
 
-			if (type == MySqlDbType.Timestamp && !writer.Version.isAtLeast(4,1,0))
+			if (type == MySqlDbType.Timestamp && !stream.Version.isAtLeast(4,1,0))
 				val = String.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}",
 					value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second );
 			else 
@@ -194,10 +194,10 @@
 				val = String.Format("{0:0000}-{1:00}-{2:00} {3:00}:{4:00}:{5:00}", value.Year, value.Month, 
 					value.Day, value.Hour, value.Minute, value.Second );
 			}
-			writer.WriteStringNoNull( "'" + val + "'" );
+			stream.WriteStringNoNull( "'" + val + "'" );
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, 
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, 
             object value, int length)
 		{
 			if (value is MySqlDateTime)
@@ -213,33 +213,33 @@
 			DateTime dtValue = (DateTime)value;
 			if (! binary)
 			{
-				SerializeText( writer, dtValue );
+				SerializeText(stream, dtValue);
 				return;
 			}
 
 			if (type == MySqlDbType.Timestamp)
-				writer.WriteByte( 11 );
+				stream.WriteByte(11);
 			else
-				writer.WriteByte( 7 );
+				stream.WriteByte(7);
 
-			writer.WriteInteger( dtValue.Year, 2 );
-			writer.WriteByte( (byte)dtValue.Month );
-			writer.WriteByte( (byte)dtValue.Day );
+			stream.WriteInteger( dtValue.Year, 2 );
+			stream.WriteByte( (byte)dtValue.Month );
+			stream.WriteByte( (byte)dtValue.Day );
 			if (type == MySqlDbType.Date) 
 			{
-				writer.WriteByte( 0 );
-				writer.WriteByte( 0 );
-				writer.WriteByte( 0 );
+				stream.WriteByte( 0 );
+				stream.WriteByte( 0 );
+				stream.WriteByte( 0 );
 			}
 			else 
 			{
-				writer.WriteByte( (byte)dtValue.Hour );
-				writer.WriteByte( (byte)dtValue.Minute  );
-				writer.WriteByte( (byte)dtValue.Second );
+				stream.WriteByte( (byte)dtValue.Hour );
+				stream.WriteByte( (byte)dtValue.Minute  );
+				stream.WriteByte( (byte)dtValue.Second );
 			}
 			
 			if (type == MySqlDbType.Timestamp)
-				writer.WriteInteger( dtValue.Millisecond, 4 );
+				stream.WriteInteger( dtValue.Millisecond, 4 );
 		}
 
 		private MySqlDateTime Parse40Timestamp(string s) 
@@ -314,44 +314,44 @@
 			return new MySqlDateTime(type, year, month, day, hour, minute, second);
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
 			if (nullVal) return new MySqlDateTime(type,true);
 
 			if (length >= 0) 
 			{
-				string value = reader.ReadString( length );
-				return ParseMySql(value, reader.Version.isAtLeast(4,1,0));
+				string value = stream.ReadString( length );
+				return ParseMySql(value, stream.Version.isAtLeast(4,1,0));
 			}
 
-			long bufLength = reader.ReadByte();
+			long bufLength = stream.ReadByte();
             int year = 0, month = 0, day = 0;
             int hour = 0, minute = 0, second = 0;
             
             if (bufLength >= 4)
             {
-                year = reader.ReadInteger(2);
-                month = reader.ReadByte();
-                day = reader.ReadByte();
+                year = stream.ReadInteger(2);
+                month = stream.ReadByte();
+                day = stream.ReadByte();
             }
 
 			if (bufLength > 4) 
 			{
-				hour = reader.ReadByte();
-				minute = reader.ReadByte();
-				second = reader.ReadByte();
+				hour = stream.ReadByte();
+				minute = stream.ReadByte();
+				second = stream.ReadByte();
 			}
 		
 			if (bufLength > 7)
-				reader.ReadInteger(4);
+				stream.ReadInteger(4);
 		
 			return new MySqlDateTime(type, year, month, day, hour, minute, second);
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			long len = reader.ReadByte();
-			reader.SkipBytes((int)len);
+			long len = stream.ReadByte();
+			stream.SkipBytes((int)len);
 		}
 
 		#endregion

Modified: trunk/mysqlclient/Types/MySqlDecimal.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlDecimal.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlDecimal.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -97,38 +97,39 @@
 			get	{ return "DECIMAL"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			decimal v = Convert.ToDecimal(val);
             string valStr = v.ToString(CultureInfo.InvariantCulture);
 			if (binary)
-                writer.WriteLenString(valStr);
+                stream.WriteLenString(valStr);
 			else
-                writer.WriteStringNoNull(valStr);
+                stream.WriteStringNoNull(valStr);
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlDecimal(true);
+			if (nullVal) 
+                return new MySqlDecimal(true);
 
             if (length == -1)
             {
-                string s = reader.ReadLenString();
+                string s = stream.ReadLenString();
                 return new MySqlDecimal(Decimal.Parse(s,
                     CultureInfo.InvariantCulture));
             }
             else
             {
-                string s = reader.ReadString();
+                string s = stream.ReadString();
                 return new MySqlDecimal(Decimal.Parse(s,
                     CultureInfo.InvariantCulture));
             }
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			long len = reader.GetFieldLength();
-			reader.SkipBytes((int)len);
+			long len = stream.ReadFieldLength();
+			stream.SkipBytes((int)len);
 		}
 
 		#endregion
@@ -198,11 +199,11 @@
 			Decimal v = Convert.ToDecimal( value );
 			if (binary) 
 			{
-				writer.WriteLenString( v.ToString(numberFormat) );
+				stream.WriteLenString( v.ToString(numberFormat) );
 			}
 			else 
 			{
-				writer.WriteStringNoNull(v.ToString(numberFormat));
+				stream.WriteStringNoNull(v.ToString(numberFormat));
 			}
 		}
 
@@ -227,12 +228,12 @@
 		{
 			if (length == -1) 
 			{
-				string value = reader.ReadLenString();
+				string value = stream.ReadLenString();
 				Value = Decimal.Parse( value, numberFormat );
 			}
 			else 
 			{
-				string value = reader.ReadString( length );
+				string value = stream.ReadString( length );
 				Value = Decimal.Parse( value, numberFormat );
 			}
 			return this;
@@ -240,8 +241,8 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			long len = reader.GetFieldLength();
-			reader.Skip( len );
+			long len = stream.GetFieldLength();
+			stream.Skip( len );
 		}
 		
 	}*/

Modified: trunk/mysqlclient/Types/MySqlDouble.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlDouble.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlDouble.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -80,34 +80,35 @@
 			get	{ return "DOUBLE"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			double v = Convert.ToDouble(val);
             if (binary)
-                writer.Write(BitConverter.GetBytes(v));
+                stream.Write(BitConverter.GetBytes(v));
             else
-                writer.WriteStringNoNull(v.ToString(
+                stream.WriteStringNoNull(v.ToString(
                     CultureInfo.InvariantCulture));		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, 
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, 
             bool nullVal)
 		{
-			if (nullVal) return new MySqlDouble(true);
+			if (nullVal) 
+                return new MySqlDouble(true);
 
 			if (length == -1) 
 			{
 				byte[] b = new byte[8];
-				reader.Read(b, 0, 8);
+				stream.Read(b, 0, 8);
 				return new MySqlDouble(BitConverter.ToDouble(b, 0));
 			}
-			return new MySqlDouble(Double.Parse(reader.ReadString(length), 
+			return new MySqlDouble(Double.Parse(stream.ReadString(length), 
                 CultureInfo.InvariantCulture));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(8);
+			stream.SkipBytes(8);
 		}
 
 		#endregion
@@ -163,9 +164,9 @@
 		{
 			double v = Convert.ToDouble(value);
 			if (binary)
-				writer.Write( BitConverter.GetBytes( v ) );
+				stream.Write( BitConverter.GetBytes( v ) );
 			else 
-				writer.WriteStringNoNull( v.ToString("R", numberFormat) );
+				stream.WriteStringNoNull( v.ToString("R", numberFormat) );
 		}
 
 		public static double MaxValue 
@@ -199,12 +200,12 @@
 			if (length == -1) 
 			{
 				byte[] b = new byte[8];
-				reader.Read( ref b, 0, 8 );
+				stream.Read( ref b, 0, 8 );
 				Value = BitConverter.ToDouble( b, 0 );
 			}
 			else 
 			{
-				string value = reader.ReadString( length );
+				string value = stream.ReadString( length );
 				Value = Parse(value);
 			}
 			return this;
@@ -225,7 +226,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip( 8 );
+			stream.Skip( 8 );
 		}
 	}*/
 }

Modified: trunk/mysqlclient/Types/MySqlInt16.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlInt16.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlInt16.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -80,28 +80,29 @@
 			get	{ return "SMALLINT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			int v = Convert.ToInt32( val );
 			if (binary)
-				writer.Write( BitConverter.GetBytes(v));
+				stream.Write( BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlInt16(true);
+			if (nullVal) 
+                return new MySqlInt16(true);
 
 			if (length == -1) 
-				return new MySqlInt16((short)reader.ReadInteger(2));
+				return new MySqlInt16((short)stream.ReadInteger(2));
 			else 
-				return new MySqlInt16(Int16.Parse(reader.ReadString( length )));
+				return new MySqlInt16(Int16.Parse(stream.ReadString(length)));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(2);
+			stream.SkipBytes(2);
 		}
 
 		#endregion
@@ -156,9 +157,9 @@
 		{
 			short v = Convert.ToInt16(value);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString(numberFormat));
+				stream.WriteStringNoNull(v.ToString(numberFormat));
 		}
 
 
@@ -182,11 +183,11 @@
 		{
 			if (length == -1) 
 			{
-				Value = (short)reader.ReadInteger(2);
+				Value = (short)stream.ReadInteger(2);
 			}
 			else 
 			{
-				string value = reader.ReadString(length);
+				string value = stream.ReadString(length);
 				Value = Int16.Parse(value, numberFormat);
 			}
 			return this;
@@ -194,7 +195,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip( 2 );
+			stream.Skip( 2 );
 		}
 	}*/
 }

Modified: trunk/mysqlclient/Types/MySqlInt32.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlInt32.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlInt32.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -85,28 +85,30 @@
 			get	{ return is24Bit ? "MEDIUMINT" : "INT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
-			int v = Convert.ToInt32( val );
+			int v = Convert.ToInt32(val);
 			if (binary)
-				writer.Write( BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlInt32(MySqlDbType, true);
+			if (nullVal) 
+                return new MySqlInt32(MySqlDbType, true);
 
 			if (length == -1) 
-				return new MySqlInt32(MySqlDbType, reader.ReadInteger(4));
+				return new MySqlInt32(MySqlDbType, stream.ReadInteger(4));
 			else 
-				return new MySqlInt32(MySqlDbType, Int32.Parse(reader.ReadString( length )));
+				return new MySqlInt32(MySqlDbType, Int32.Parse(
+                    stream.ReadString(length )));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(4);
+			stream.SkipBytes(4);
 		}
 
 		#endregion
@@ -170,9 +172,9 @@
 		{
 			int v = Convert.ToInt32(value);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString(numberFormat));
+				stream.WriteStringNoNull(v.ToString(numberFormat));
 		}
 
 		public int Value
@@ -198,13 +200,13 @@
 			if (length == -1) 
 			{
 				if (mySqlDbType == MySqlDbType.Int24)
-					Value = reader.ReadInteger(3);
+					Value = stream.ReadInteger(3);
 				else
-					Value = (int)reader.ReadLong(4);
+					Value = (int)stream.ReadLong(4);
 			}
 			else 
 			{
-				string value = reader.ReadString(length);
+				string value = stream.ReadString(length);
 				Value = Int32.Parse(value, numberFormat);
 			}
 			return this;
@@ -212,7 +214,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip( 4 );
+			stream.Skip( 4 );
 		}
 	}*/
 }

Modified: trunk/mysqlclient/Types/MySqlInt64.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlInt64.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlInt64.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -79,28 +79,29 @@
 			get	{ return "BIGINT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			long v = Convert.ToInt64(val);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlInt64(true);
+			if (nullVal) 
+                return new MySqlInt64(true);
 
 			if (length == -1) 
-				return new MySqlInt64((long)reader.ReadLong(8));
+				return new MySqlInt64((long)stream.ReadLong(8));
 			else 
-				return new MySqlInt64(Int64.Parse(reader.ReadString(length)));
+				return new MySqlInt64(Int64.Parse(stream.ReadString(length)));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(8);
+			stream.SkipBytes(8);
 		}
 
 		#endregion
@@ -155,9 +156,9 @@
 		{
 			long v = Convert.ToInt64(value);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString(numberFormat));
+				stream.WriteStringNoNull(v.ToString(numberFormat));
 		}
 
 
@@ -181,11 +182,11 @@
 		{
 			if (length == -1) 
 			{
-				Value = (long)reader.ReadLong(8);
+				Value = (long)stream.ReadLong(8);
 			}
 			else 
 			{
-				string value = reader.ReadString(length);
+				string value = stream.ReadString(length);
 				Value = Int64.Parse(value, numberFormat);
 			}
 			return this;
@@ -193,7 +194,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip(8);
+			stream.Skip(8);
 		}
 
 	}*/

Modified: trunk/mysqlclient/Types/MySqlSingle.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlSingle.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlSingle.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -80,33 +80,34 @@
 			get	{ return "FLOAT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			Single v = Convert.ToSingle(val);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-                writer.WriteStringNoNull(v.ToString(
+                stream.WriteStringNoNull(v.ToString(
                     CultureInfo.InvariantCulture));		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlSingle(true);
+			if (nullVal) 
+                return new MySqlSingle(true);
 
 			if (length == -1) 
 			{
 				byte[] b = new byte[4];
-				reader.Read(b, 0, 4);
+				stream.Read(b, 0, 4);
 				return new MySqlSingle(BitConverter.ToSingle( b, 0 ));
 			}
-			return new MySqlSingle(Single.Parse(reader.ReadString(length), 
+			return new MySqlSingle(Single.Parse(stream.ReadString(length), 
                 CultureInfo.InvariantCulture));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(4);
+			stream.SkipBytes(4);
 		}
 
 		#endregion
@@ -161,9 +162,9 @@
 		{
 			Single v = Convert.ToSingle( value );
 			if (binary)
-				writer.Write( BitConverter.GetBytes( v ) );
+				stream.Write( BitConverter.GetBytes( v ) );
 			else
-				writer.WriteStringNoNull( v.ToString(numberFormat) );
+				stream.WriteStringNoNull( v.ToString(numberFormat) );
 		}
 
 		public Single Value
@@ -197,12 +198,12 @@
 			if (length == -1) 
 			{
 				byte[] b = new byte[4];
-				reader.Read( ref b, 0, 4 );
+				stream.Read( ref b, 0, 4 );
 				Value = BitConverter.ToSingle( b, 0 );
 			}
 			else 
 			{
-				string value = reader.ReadString( length );
+				string value = stream.ReadString( length );
 				Value = Parse(value);
 			}
 			return this;
@@ -210,7 +211,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip(4);
+			stream.Skip(4);
 		}
 
 <<<<<<< .working

Modified: trunk/mysqlclient/Types/MySqlString.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlString.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlString.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -95,36 +95,36 @@
 			return s;
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			string v = val.ToString();
 			if (length > 0)
 				v = v.Substring(0, length);
 
 			if (binary)
-				writer.WriteLenString(v);
+				stream.WriteLenString(v);
 			else
-				writer.WriteStringNoNull("'" + EscapeString(v) + "'");
+				stream.WriteStringNoNull("'" + EscapeString(v) + "'");
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlString(type, true);
+			if (nullVal) 
+                return new MySqlString(type, true);
 
 			string s = String.Empty;
 			if (length == -1)
-				s = reader.ReadLenString();
+				s = stream.ReadLenString();
 			else
-				s = reader.ReadString(length);
+				s = stream.ReadString(length);
             MySqlString str = new MySqlString(type, s);
             return str;
-			//return new MySqlString(type, s);
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			long len = reader.GetFieldLength();
-			reader.SkipBytes((int)len);
+			long len = stream.ReadFieldLength();
+			stream.SkipBytes((int)len);
 		}
 
 		#endregion
@@ -201,9 +201,9 @@
 				v = v.Substring(0, length);
 
 			if (binary)
-				writer.WriteLenString( v );
+				stream.WriteLenString( v );
 			else
-				writer.WriteStringNoNull( "'" + EscapeString(v) + "'" );
+				stream.WriteStringNoNull( "'" + EscapeString(v) + "'" );
 		}
 
 		public byte[] ToBytes( System.Text.Encoding encoding ) 
@@ -244,16 +244,16 @@
 		{
 			string s = String.Empty;
 			if (length == -1)
-				s = reader.ReadLenString();
+				s = stream.ReadLenString();
 			else
-				s = reader.ReadString( length );
+				s = stream.ReadString( length );
 			return new MySqlString( s, mySqlDbType );
 		}
 
 		internal override void Skip(PacketReader reader)
 		{
-			long len = reader.GetFieldLength();
-			reader.Skip( len );
+			long len = stream.GetFieldLength();
+			stream.Skip( len );
 		}
 
 	}*/

Modified: trunk/mysqlclient/Types/MySqlTime.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlTime.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlTime.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -79,7 +79,7 @@
 			get	{ return "TIME"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			if (! (val is TimeSpan))
 				throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
@@ -87,59 +87,59 @@
 			TimeSpan ts = (TimeSpan)val;
 			if (binary) 
 			{			
-				writer.WriteByte( 8 );
-				writer.WriteByte( (byte)(ts.TotalSeconds < 0 ? 1 : 0 ));
-				writer.WriteInteger( ts.Days, 4 );
-				writer.WriteByte( (byte)ts.Hours );
-				writer.WriteByte( (byte)ts.Minutes );
-				writer.WriteByte( (byte)ts.Seconds );
+				stream.WriteByte(8);
+                stream.WriteByte((byte)(ts.TotalSeconds < 0 ? 1 : 0));
+                stream.WriteInteger(ts.Days, 4);
+                stream.WriteByte((byte)ts.Hours);
+                stream.WriteByte((byte)ts.Minutes);
+                stream.WriteByte((byte)ts.Seconds);
 			}
 			else 
-			{
-				writer.WriteStringNoNull( String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'", 
+			{
+                stream.WriteStringNoNull(String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'", 
 					ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds ) );
 			}
 		}
 
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
 			if (nullVal) return new MySqlTimeSpan(true);
 
 			if (length >= 0) 
-			{
-				string value = reader.ReadString( length );
-				ParseMySql(value, reader.Version.isAtLeast(4,1,0));
+			{
+                string value = stream.ReadString(length);
+                ParseMySql(value, stream.Version.isAtLeast(4, 1, 0));
 				return this;
-			}
-
-			long bufLength = reader.ReadByte();
+			}
+
+            long bufLength = stream.ReadByte();
 			int negate = 0;
-			if (bufLength > 0)
-				negate = reader.ReadByte();
+			if (bufLength > 0)
+                negate = stream.ReadByte();
 
 			isNull = false;
 			if (bufLength == 0)
 				isNull = true;
-			else if (bufLength == 5)
-				mValue = new TimeSpan( reader.ReadInteger( 4 ), 0, 0, 0 );
-			else if (bufLength == 8)
-				mValue = new TimeSpan( reader.ReadInteger(4), 
-					reader.ReadByte(), reader.ReadByte(), reader.ReadByte() );
-			else 
-				mValue = new TimeSpan( reader.ReadInteger(4), 
-					reader.ReadByte(), reader.ReadByte(), reader.ReadByte(),
-					reader.ReadInteger(4) / 1000000 );
+			else if (bufLength == 5)
+                mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0);
+			else if (bufLength == 8)
+                mValue = new TimeSpan(stream.ReadInteger(4),
+                    stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
+			else
+                mValue = new TimeSpan(stream.ReadInteger(4),
+                    stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
+                    stream.ReadInteger(4) / 1000000);
 
 			if (negate == 1)
 				mValue = mValue.Negate();
 			return this;
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			int len = reader.ReadByte();
-			reader.SkipBytes(len);
+			int len = stream.ReadByte();
+			stream.SkipBytes(len);
 		}
 
 		#endregion
@@ -222,16 +222,16 @@
 			TimeSpan ts = (TimeSpan)value;
 			if (binary) 
 			{			
-				writer.WriteByte( 8 );
-				writer.WriteByte( (byte)(ts.TotalSeconds < 0 ? 1 : 0 ));
-				writer.WriteInteger( ts.Days, 4 );
-				writer.WriteByte( (byte)ts.Hours );
-				writer.WriteByte( (byte)ts.Minutes );
-				writer.WriteByte( (byte)ts.Seconds );
+				stream.WriteByte( 8 );
+				stream.WriteByte( (byte)(ts.TotalSeconds < 0 ? 1 : 0 ));
+				stream.WriteInteger( ts.Days, 4 );
+				stream.WriteByte( (byte)ts.Hours );
+				stream.WriteByte( (byte)ts.Minutes );
+				stream.WriteByte( (byte)ts.Seconds );
 			}
 			else 
 			{
-				writer.WriteStringNoNull( String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'", 
+				stream.WriteStringNoNull( String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'", 
 					ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds ) );
 			}
 		}
@@ -275,27 +275,27 @@
 		{
 			if (length >= 0) 
 			{
-				string value = reader.ReadString( length );
-				ParseMySql( value, reader.Version.isAtLeast(4,1,0));
+				string value = stream.ReadString( length );
+				ParseMySql( value, stream.Version.isAtLeast(4,1,0));
 				return this;
 			}
 
-			long bufLength = reader.ReadByte();
+			long bufLength = stream.ReadByte();
 			int negate = 0;
 			if (bufLength > 0)
-				negate = reader.ReadByte();
+				negate = stream.ReadByte();
 
 			if (bufLength == 0)
 				IsNull = true;
 			else if (bufLength == 5)
-				Value = new TimeSpan( reader.ReadInteger( 4 ), 0, 0, 0 );
+				Value = new TimeSpan( stream.ReadInteger( 4 ), 0, 0, 0 );
 			else if (bufLength == 8)
-				Value = new TimeSpan( reader.ReadInteger(4), 
-					reader.ReadByte(), reader.ReadByte(), reader.ReadByte() );
+				Value = new TimeSpan( stream.ReadInteger(4), 
+					stream.ReadByte(), stream.ReadByte(), stream.ReadByte() );
 			else 
-				Value = new TimeSpan( reader.ReadInteger(4), 
-					reader.ReadByte(), reader.ReadByte(), reader.ReadByte(),
-					reader.ReadInteger(4) / 1000000 );
+				Value = new TimeSpan( stream.ReadInteger(4), 
+					stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
+					stream.ReadInteger(4) / 1000000 );
 
 			if (negate == 1)
 				Value = mValue.Negate();
@@ -309,8 +309,8 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			long len = (long)reader.ReadByte();
-			reader.Skip( len );
+			long len = (long)stream.ReadByte();
+			stream.Skip( len );
 		}
 
 	}*/

Modified: trunk/mysqlclient/Types/MySqlUByte.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlUByte.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlUByte.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -79,28 +79,29 @@
 			get	{ return "TINYINT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			byte v = ((IConvertible)val).ToByte(null); 
 			if (binary)
-				writer.Write( BitConverter.GetBytes(v));
+				stream.Write( BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlUByte(true);
+			if (nullVal) 
+                return new MySqlUByte(true);
 
 			if (length == -1) 
-				return new MySqlUByte((byte)reader.ReadByte());
+				return new MySqlUByte((byte)stream.ReadByte());
 			else 
-				return new MySqlUByte(Byte.Parse(reader.ReadString(length)));
+				return new MySqlUByte(Byte.Parse(stream.ReadString(length)));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.ReadByte();
+			stream.ReadByte();
 		}
 
 		#endregion
@@ -155,9 +156,9 @@
 		{	
 			byte v = Convert.ToByte( value );
 			if (binary)
-				writer.WriteByte( v );
+				stream.WriteByte( v );
 			else
-				writer.WriteStringNoNull( v.ToString() );
+				stream.WriteStringNoNull( v.ToString() );
 		}
 
 		public byte Value
@@ -181,15 +182,15 @@
 		internal override MySqlValue ReadValue(PacketReader reader, long length)
 		{
 			if (length == -1)
-				Value = (byte)reader.ReadByte();
+				Value = (byte)stream.ReadByte();
 			else
-				Value = Byte.Parse( reader.ReadString(length));
+				Value = Byte.Parse( stream.ReadString(length));
 			return this;
 		}
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.ReadByte();
+			stream.ReadByte();
 		}
 	}*/
 }

Modified: trunk/mysqlclient/Types/MySqlUInt16.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlUInt16.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlUInt16.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -79,28 +79,29 @@
 			get	{ return "SMALLINT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
 			int v = Convert.ToUInt16( val );
 			if (binary)
-				writer.Write( BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlUInt16(true);
+			if (nullVal) 
+                return new MySqlUInt16(true);
 
 			if (length == -1) 
-				return new MySqlUInt16((ushort)reader.ReadInteger(2));
+				return new MySqlUInt16((ushort)stream.ReadInteger(2));
 			else 
-				return new MySqlUInt16(UInt16.Parse(reader.ReadString( length )));
+				return new MySqlUInt16(UInt16.Parse(stream.ReadString(length)));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(2);
+			stream.SkipBytes(2);
 		}
 
 		#endregion
@@ -160,9 +161,9 @@
 		{
 			ushort v = Convert.ToUInt16( value );
 			if (binary)
-				writer.Write( BitConverter.GetBytes( v ) );
+				stream.Write( BitConverter.GetBytes( v ) );
 			else
-				writer.WriteStringNoNull( v.ToString() );
+				stream.WriteStringNoNull( v.ToString() );
 		}
 
 		public ushort Value
@@ -185,11 +186,11 @@
 		{
 			if (length == -1) 
 			{
-				Value = (ushort)reader.ReadInteger(2);
+				Value = (ushort)stream.ReadInteger(2);
 			}
 			else 
 			{
-				string value = reader.ReadString( length );
+				string value = stream.ReadString( length );
 				Value = UInt16.Parse( value );
 			}
 			return this;
@@ -197,7 +198,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip(2);
+			stream.Skip(2);
 		}
 
 	}*/

Modified: trunk/mysqlclient/Types/MySqlUInt32.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlUInt32.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlUInt32.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -86,28 +86,29 @@
 			get	{ return is24Bit ? "MEDIUMINT" : "INT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object v, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object v, int length)
 		{
 			uint val = Convert.ToUInt32(v);
 			if (binary)
-				writer.Write(BitConverter.GetBytes(val));
+				stream.Write(BitConverter.GetBytes(val));
 			else
-				writer.WriteStringNoNull(val.ToString());		
+				stream.WriteStringNoNull(val.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
 			if (nullVal) return new MySqlUInt32(MySqlDbType, true);
 
 			if (length == -1) 
-				return new MySqlUInt32(MySqlDbType, (uint)reader.ReadInteger(4));
+				return new MySqlUInt32(MySqlDbType, (uint)stream.ReadInteger(4));
 			else 
-				return new MySqlUInt32(MySqlDbType, UInt32.Parse(reader.ReadString( length )));
+				return new MySqlUInt32(MySqlDbType, UInt32.Parse(
+                    stream.ReadString(length)));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(4);
+			stream.SkipBytes(4);
 		}
 
 		#endregion
@@ -166,9 +167,9 @@
 		{
 			uint v = Convert.ToUInt32( value );
 			if (binary)
-				writer.Write( BitConverter.GetBytes( v ) );
+				stream.Write( BitConverter.GetBytes( v ) );
 			else
-				writer.WriteStringNoNull( v.ToString() );
+				stream.WriteStringNoNull( v.ToString() );
 		}
 
 		public uint Value
@@ -192,13 +193,13 @@
 			if (length == -1) 
 			{
 				if (mySqlDbType == MySqlDbType.Int24)
-					Value = (uint)reader.ReadInteger( 3 );
+					Value = (uint)stream.ReadInteger( 3 );
 				else
-					Value = (uint)reader.ReadLong( 4  );
+					Value = (uint)stream.ReadLong( 4  );
 			}
 			else 
 			{
-				string value = reader.ReadString( length );
+				string value = stream.ReadString( length );
 				Value = UInt32.Parse( value );
 			}
 			return this;
@@ -206,7 +207,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip(4);
+			stream.Skip(4);
 		}
 	}*/
 }

Modified: trunk/mysqlclient/Types/MySqlUInt64.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlUInt64.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlUInt64.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -79,28 +79,29 @@
 			get	{ return "BIGINT"; }
 		}
 
-		void IMySqlValue.WriteValue(MySqlStreamWriter writer, bool binary, object val, int length)
+		void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 		{
-			ulong v = Convert.ToUInt64( val );
+			ulong v = Convert.ToUInt64(val);
 			if (binary)
-				writer.Write( BitConverter.GetBytes(v));
+				stream.Write(BitConverter.GetBytes(v));
 			else
-				writer.WriteStringNoNull(v.ToString());		
+				stream.WriteStringNoNull(v.ToString());		
 		}
 
-		IMySqlValue IMySqlValue.ReadValue(MySqlStreamReader reader, long length, bool nullVal)
+		IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 		{
-			if (nullVal) return new MySqlUInt64(true);
+			if (nullVal) 
+                return new MySqlUInt64(true);
 
 			if (length == -1) 
-				return new MySqlUInt64((ulong)reader.ReadLong(8));
+				return new MySqlUInt64((ulong)stream.ReadLong(8));
 			else 
-				return new MySqlUInt64(UInt64.Parse(reader.ReadString(length)));
+				return new MySqlUInt64(UInt64.Parse(stream.ReadString(length)));
 		}
 
-		void IMySqlValue.SkipValue(MySqlStreamReader reader)
+		void IMySqlValue.SkipValue(MySqlStream stream)
 		{
-			reader.SkipBytes(8);
+			stream.SkipBytes(8);
 		}
 
 		#endregion
@@ -155,9 +156,9 @@
 		{
 			ulong v = Convert.ToUInt64( value );
 			if (binary)
-				writer.Write( BitConverter.GetBytes( v ) );
+				stream.Write( BitConverter.GetBytes( v ) );
 			else
-				writer.WriteStringNoNull( v.ToString() );
+				stream.WriteStringNoNull( v.ToString() );
 		}
 
 		public ulong Value
@@ -180,11 +181,11 @@
 		{
 			if (length == -1) 
 			{
-				Value = reader.ReadLong( 8 );
+				Value = stream.ReadLong( 8 );
 			}
 			else 
 			{
-				string value = reader.ReadString( length );
+				string value = stream.ReadString( length );
 				Value = UInt64.Parse( value );
 			}
 			return this;
@@ -192,7 +193,7 @@
 
 		internal override void Skip(PacketReader reader)
 		{
-			reader.Skip(8);
+			stream.Skip(8);
 		}
 	}*/
 }

Modified: trunk/mysqlclient/Types/MySqlValue.cs
===================================================================
--- trunk/mysqlclient/Types/MySqlValue.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/Types/MySqlValue.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -34,9 +34,9 @@
 		Type		SystemType		{ get; }
 		string		MySqlTypeName	{ get; }
 
-		void		WriteValue(MySqlStreamWriter writer, bool binary, object value, int length);
-		IMySqlValue	ReadValue(MySqlStreamReader reader, long length, bool isNull);
-		void		SkipValue(MySqlStreamReader reader);
+		void		WriteValue(MySqlStream stream, bool binary, object value, int length);
+		IMySqlValue	ReadValue(MySqlStream stream, long length, bool isNull);
+		void		SkipValue(MySqlStream stream);
 	}
 
 

Deleted: trunk/mysqlclient/common/SocketStream.cs
===================================================================
--- trunk/mysqlclient/common/SocketStream.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/common/SocketStream.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -1,118 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Sockets;
-using System.Collections;
-
-namespace MySql.Data.Common
-{
-	/// <summary>
-	/// Summary description for MySqlSocket.
-	/// </summary>
-	internal sealed class SocketStream : Stream
-	{
-		private Socket	socket;
-
-		public SocketStream(AddressFamily addressFamily, SocketType socketType, ProtocolType protocol)
-			: base()
-		{
-			socket = new Socket(addressFamily, socketType, protocol);
-		}
-
-		#region Properties
-
-		public Socket Socket 
-		{
-			get { return socket; }
-		}
-
-		public override bool CanRead
-		{
-			get	{ return true;	}
-		}
-
-		public override bool CanSeek
-		{
-			get	{ return false;	}
-		}
-
-		public override bool CanWrite
-		{
-			get	{ return true; }
-		}
-
-		public override long Length
-		{
-			get	{ return 0;	}
-		}
-
-		public override long Position
-		{
-			get	{ return 0;	}
-			set	{ throw new NotSupportedException("SocketStream does not support seek"); }
-		}
-
-		#endregion
-
-		#region Stream Implementation
-
-		public override void Flush()
-		{
-		}
-
-		public override int Read(byte[] buffer, int offset, int count)
-		{
-			return socket.Receive(buffer, offset, count, SocketFlags.None);
-		}
-
-		public override long Seek(long offset, SeekOrigin origin)
-		{
-			throw new NotSupportedException("SocketStream does not support seek");
-		}
-
-		public override void SetLength(long value)
-		{
-		}
-
-		public override void Write(byte[] buffer, int offset, int count)
-		{
-			socket.Send(buffer, offset, count, SocketFlags.None);
-		}
-
-
-		#endregion
-
-		public bool Connect(EndPoint remoteEP, int timeout)
-		{
-            // set the socket to non blocking
-            socket.Blocking = false;
-
-			// then we star the connect
-			SocketAddress addr = remoteEP.Serialize();
-			byte[] buff = new byte[addr.Size];
-			for (int i=0; i<addr.Size; i++)
-				buff[i] = addr[i];
-
-			int result = NativeMethods.connect(socket.Handle, buff, addr.Size);
-			int wsaerror = NativeMethods.WSAGetLastError();
-			if (wsaerror != 10035)
-				throw new Exception("Error creating MySQLSocket");
-
-			// next we wait for our connect timeout or until the socket is connected
-			ArrayList write = new ArrayList();
-			write.Add(socket);
-			ArrayList error = new ArrayList();
-			error.Add(socket);
-
-			Socket.Select(null, write, error, timeout*1000*1000);
-
-			if (write.Count == 0) return false;
-
-			// set socket back to blocking mode
-            socket.Blocking = true;
-			return true;
-		}
-
-
-	}
-}

Modified: trunk/mysqlclient/common/StreamCreator.cs
===================================================================
--- trunk/mysqlclient/common/StreamCreator.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/common/StreamCreator.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -38,6 +38,7 @@
 		uint				port;
 		string				pipeName;
 		uint				timeOut;
+        ManualResetEvent    waitHandle;        
 
 		public StreamCreator( string hosts, uint port, string pipeName)
 		{
@@ -46,7 +47,8 @@
 				hostList = "localhost";
 			this.port = port;
 			this.pipeName = pipeName;
-		}
+            waitHandle = new ManualResetEvent(false);
+        }
 
 		public Stream GetStream(uint timeOut) 
 		{
@@ -122,9 +124,15 @@
 			return ep;
         }
 
+        private void ConnectCallback(IAsyncResult ias)
+        {
+            Socket s = (ias.AsyncState as Socket);
+            s.EndConnect(ias);
+            waitHandle.Set();
+        }
+
 		private Stream CreateSocketStream( IPAddress ip, uint port, bool unix ) 
 		{
-            SocketStream ss = null;
 			try
 			{
 				//
@@ -136,34 +144,37 @@
 				else
 					endPoint = 	new IPEndPoint(ip, (int)port);
 
-                ss = unix ? 
-                    new SocketStream(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP) :
-                    new SocketStream(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-                ss.Connect(endPoint, (int)timeOut);
-                ss.Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
-                return ss;
+                waitHandle.Reset();
+                Socket s = unix ?
+                    new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP) :
+                    new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                IAsyncResult ias = s.BeginConnect(endPoint, 
+                    new AsyncCallback(ConnectCallback), s);
+
+                if (ias.CompletedSynchronously || 
+                    waitHandle.WaitOne((int)timeOut * 1000, false))
+                    return new NetworkStream(s);
+                else 
+                {
+                    s.EndConnect(ias);
+                    return null;
+                }
             }
-			catch (ArgumentOutOfRangeException are)
+			catch (ArgumentNullException are)
 			{
 				Logger.LogException(are);
-				ss = null;
+                return null;
 			}
 			catch (SocketException se) 
 			{
 				Logger.LogException(se);
-				ss = null;
+                return null;
 			}
 			catch (ObjectDisposedException ode) 
 			{
 				Logger.LogException(ode);
-				ss = null;
+				return null;
 			}
-			catch (MySqlException me)
-			{
-				Logger.LogException(me);
-				ss = null;
-			}
-			return ss;
 		}
  
 	}

Modified: trunk/mysqlclient/parameter.cs
===================================================================
--- trunk/mysqlclient/parameter.cs	2006-07-28 17:38:45 UTC (rev 278)
+++ trunk/mysqlclient/parameter.cs	2006-07-30 03:31:34 UTC (rev 279)
@@ -355,14 +355,14 @@
             }
 		}
 
-        internal void Serialize(MySqlStreamWriter writer, bool binary)
+        internal void Serialize(MySqlStream stream, bool binary)
         {
             IMySqlValue v = MySqlField.GetIMySqlValue(mySqlDbType, true);
 
             if (!binary && (paramValue == null || paramValue == DBNull.Value))
-                writer.WriteStringNoNull("NULL");
+                stream.WriteStringNoNull("NULL");
             else
-                v.WriteValue(writer, binary, paramValue, size);
+                v.WriteValue(stream, binary, paramValue, size);
         }
 
 		private void SetMySqlDbType(MySqlDbType mySqlDbType) 

Thread
Connector/NET commit: r279 - in trunk/mysqlclient: . Types commonrburnett30 Jul