List:Internals« Previous MessageNext Message »
From:rburnett Date:August 23 2005 10:35pm
Subject:Connector/NET commit: r158 - in branches/1.0: . TestSuite TestSuite/configs mysqlclient mysqlclient/common
View as plain text  
Added:
   branches/1.0/TestSuite/configs/pipe.config
   branches/1.0/TestSuite/configs/pipe_compressed.config
   branches/1.0/TestSuite/configs/tcp.config
   branches/1.0/TestSuite/configs/tcp_compressed.config
Modified:
   branches/1.0/MySql.Data.csproj
   branches/1.0/TestSuite/Exceptions.cs
   branches/1.0/mysqlclient/PacketReader.cs
   branches/1.0/mysqlclient/PacketWriter.cs
   branches/1.0/mysqlclient/Strings.resx
   branches/1.0/mysqlclient/common/NamedPipeStream.cs
   branches/1.0/mysqlclient/common/Resources.cs
Log:
NamedPipeStream.cs - fixed named pipe issues
Resources.cs - fixed namespace for retrieval of Strings.resx
PacketReader.cs - fixed Read so it fails the connection on any stream read failure
PacketWriter.cs - fixed Write so it fails the connection on any stream write failure
Strings.resx - added some more needed Strings.resx
Exceptions.cs - timeout test didn't work for named pipes
Added the configs that I use for server testing

Modified: branches/1.0/MySql.Data.csproj
===================================================================
--- branches/1.0/MySql.Data.csproj	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/MySql.Data.csproj	2005-08-23 20:35:40 UTC (rev 158)
@@ -9,7 +9,7 @@
             <Settings
                 ApplicationIcon = ""
                 AssemblyKeyContainerName = ""
-                AssemblyName = "MySQL.Data"
+                AssemblyName = "MySql.Data"
                 AssemblyOriginatorKeyFile = ""
                 DefaultClientScript = "JScript"
                 DefaultHTMLPageLayout = "Grid"
@@ -18,7 +18,7 @@
                 OutputType = "Library"
                 PreBuildEvent = ""
                 PostBuildEvent = ""
-                RootNamespace = "MySQL.Data.MySQLClient"
+                RootNamespace = "MySql.Data.MySqlClient"
                 RunPostBuildEvent = "OnBuildSuccess"
                 StartupObject = ""
             >

Modified: branches/1.0/TestSuite/Exceptions.cs
===================================================================
--- branches/1.0/TestSuite/Exceptions.cs	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/TestSuite/Exceptions.cs	2005-08-23 20:35:40 UTC (rev 158)
@@ -55,13 +55,7 @@
 			MySqlConnection c2 = new MySqlConnection(conn.ConnectionString);
 			c2.Open();
 
-			// now we query to see what the write timeout is
-			MySqlCommand toCmd = new MySqlCommand("SET @@local.wait_timeout=5", c2);
-			toCmd.ExecuteNonQuery();
-			toCmd.CommandText = "SET @@local.interactive_timeout=5";
-			toCmd.ExecuteNonQuery();
-
-			Thread.Sleep(8000);
+			KillConnection(c2);
 			MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c2);
 			MySqlDataReader reader = null;
 

Added: branches/1.0/TestSuite/configs/pipe.config
===================================================================
--- branches/1.0/TestSuite/configs/pipe.config	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/TestSuite/configs/pipe.config	2005-08-23 20:35:40 UTC (rev 158)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252" ?>
+<configuration>
+    <appSettings>
+		<add key="host" value="localhost"/>
+		<add key="otherkeys" value=";protocol=pipe"/>
+    </appSettings>
+    
+</configuration>

Added: branches/1.0/TestSuite/configs/pipe_compressed.config
===================================================================
--- branches/1.0/TestSuite/configs/pipe_compressed.config	2005-08-23 18:35:28 UTC (rev
157)
+++ branches/1.0/TestSuite/configs/pipe_compressed.config	2005-08-23 20:35:40 UTC (rev
158)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252" ?>
+<configuration>
+    <appSettings>
+		<add key="host" value="localhost"/>
+		<add key="otherkeys" value=";protocol=pipe;compress=true"/>
+    </appSettings>
+    
+</configuration>

Added: branches/1.0/TestSuite/configs/tcp.config
===================================================================
--- branches/1.0/TestSuite/configs/tcp.config	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/TestSuite/configs/tcp.config	2005-08-23 20:35:40 UTC (rev 158)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252" ?>
+<configuration>
+    <appSettings>
+		<add key="host" value="localhost"/>
+		<add key="otherkeys" value=";protocol=tcp"/>
+    </appSettings>
+    
+</configuration>

Added: branches/1.0/TestSuite/configs/tcp_compressed.config
===================================================================
--- branches/1.0/TestSuite/configs/tcp_compressed.config	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/TestSuite/configs/tcp_compressed.config	2005-08-23 20:35:40 UTC (rev 158)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252" ?>
+<configuration>
+    <appSettings>
+		<add key="host" value="localhost"/>
+		<add key="otherkeys" value=";protocol=tcp;compess=true"/>
+    </appSettings>
+    
+</configuration>

Modified: branches/1.0/mysqlclient/PacketReader.cs
===================================================================
--- branches/1.0/mysqlclient/PacketReader.cs	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/mysqlclient/PacketReader.cs	2005-08-23 20:35:40 UTC (rev 158)
@@ -198,7 +198,7 @@
 			return ReadInteger((int)c);
 		}
 
-		public int Read( ref byte[] buffer, long pos, long len ) 
+		public int Read(ref byte[] buffer, long pos, long len) 
 		{
 			if (buffer == null || buffer.Length < len)
 				buffer = new byte[ pos + len ];
@@ -232,10 +232,10 @@
 
 				return (int)totalLen;
 			}
-			catch (IOException ioe) 
+			catch (Exception ex) 
 			{
-				Logger.LogException( ioe ) ;
-				throw new MySqlException( "Connection unexpectedly terminated", true, ioe );
+				Logger.LogException(ex) ;
+				throw new MySqlException("Connection unexpectedly terminated", true, ex);
 			}
 		}
 

Modified: branches/1.0/mysqlclient/PacketWriter.cs
===================================================================
--- branches/1.0/mysqlclient/PacketWriter.cs	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/mysqlclient/PacketWriter.cs	2005-08-23 20:35:40 UTC (rev 158)
@@ -166,7 +166,7 @@
 			while (length > 0) 
 			{
 				long toWrite = Math.Min( leftThisPacket, Math.Min( (long)length, leftToWrite  ) );
-				stream.Write( buf, (int)offset, (int)toWrite );
+				WriteFinal(buf, (int)offset, (int)toWrite);
 				stream.Flush();
 				leftThisPacket -= toWrite;
 				offset += (int)toWrite;
@@ -177,15 +177,28 @@
 			}
 		}
 
+		protected void WriteFinal(byte[] buffer, int offset, int count)
+		{
+			try 
+			{
+				stream.Write(buffer, offset, count);
+			}
+			catch (Exception ex)
+			{
+				Logger.LogException(ex);
+				throw new MySqlException("Unable to write to stream", true, ex);
+			}
+		}
+
 		public void Write( byte[] buffer, int offset, int count ) 
 		{
 			if (! Buffering)
 				WriteChunk( buffer, offset, count );
 			else
-				stream.Write( buffer, offset, count );
+				WriteFinal(buffer, offset, count);
 		}
 
-		public void WriteLength( long length ) 
+		public void WriteLength(long length) 
 		{
 			if (length < 251)
 				WriteByte( (byte)length );

Modified: branches/1.0/mysqlclient/Strings.resx
===================================================================
--- branches/1.0/mysqlclient/Strings.resx	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/mysqlclient/Strings.resx	2005-08-23 20:35:40 UTC (rev 158)
@@ -145,4 +145,10 @@
 	<data name="KeywordNotSupported">
 		<value>Keyword not supported.</value>
 	</data>
+	<data name="WriteToStreamFailed">
+		<value>Writing to the stream failed.</value>
+	</data>
+	<data name="ReadFromStreamFailed">
+		<value>Reading from the stream has failed.</value>
+	</data>
 </root>
\ No newline at end of file

Modified: branches/1.0/mysqlclient/common/NamedPipeStream.cs
===================================================================
--- branches/1.0/mysqlclient/common/NamedPipeStream.cs	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/mysqlclient/common/NamedPipeStream.cs	2005-08-23 20:35:40 UTC (rev 158)
@@ -50,29 +50,8 @@
 
 			pipeHandle = NativeMethods.CreateFile( host, pipemode,
 						0, null, NativeMethods.OPEN_EXISTING, 0, 0 );
-//			try 
-//			{
-//				stream = new FileStream( (IntPtr)pipeHandle, FileAccess.ReadWrite );
-//			}
-//			catch (Exception ex) 
-//			{
-//				Console.WriteLine( ex.Message );
-//			}
-
 		}
 
-/*		public bool DataAvailable
-		{
-			get 
-			{
-				uint bytesRead=0, avail=0, thismsg=0;
-
-				bool result = Win32.PeekNamedPipe( pipeHandle, 
-					null, 0, ref bytesRead, ref avail, ref thismsg );
-				return (result == true && avail > 0);
-			}
-		}
-*/
 		public override bool CanRead
 		{
 			get { return (_mode & FileAccess.Read) > 0; }
@@ -101,32 +80,12 @@
 
 		public override void Flush() 
 		{
-//			if (stream != null)
-//				stream.Flush();
-			if ( pipeHandle == 0 )
-				throw new ObjectDisposedException("NamedPipeStream", 
-					Resources.GetString("StreamAlreadyClosed"));
-			NativeMethods.FlushFileBuffers((IntPtr)pipeHandle);
+			if (pipeHandle != 0)
+				NativeMethods.FlushFileBuffers((IntPtr)pipeHandle);
 		}
 
 		public override int Read(byte[] buffer, int offset, int count)
 		{
-/*			try 
-			{
-				uint bytesRead=0, avail=0, thismsg=0;
-
-				bool result = Win32.PeekNamedPipe( pipeHandle, 
-					null, 0, ref bytesRead, ref avail, ref thismsg );
-				if (result)
-					return stream.Read( buffer, offset, (int)avail );
-				else
-					return -1;
-			}
-			catch (Exception ex) 
-			{
-				Console.WriteLine(ex.Message);
-			}
-			return -1;*/
 			if (buffer == null) 
 				throw new ArgumentNullException("buffer", 
 					Resources.GetString("BufferCannotBeNull"));
@@ -141,29 +100,34 @@
 					Resources.GetString("CountCannotBeNegative"));
 			if (! CanRead)
 				throw new NotSupportedException(Resources.GetString("StreamNoRead"));
-			if (pipeHandle == 0)
-				throw new ObjectDisposedException("NamedPipeStream", 
-					Resources.GetString("StreamAlreadyClosed"));
+			if (pipeHandle == 0) 
+				return 0;
 
 			// first read the data into an internal buffer since ReadFile cannot read into a buf
at
 			// a specified offset
 			uint read=0;
 			byte[] buf = new Byte[count];
-			NativeMethods.ReadFile((IntPtr)pipeHandle, buf, (uint)count, out read, IntPtr.Zero); 
+			bool result = NativeMethods.ReadFile((IntPtr)pipeHandle, buf, 
+				(uint)count, out read, IntPtr.Zero); 
 			
-			for (int x=0; x < read; x++) 
+			if (! result)
 			{
-				buffer[offset+x] = buf[x];
+				Close();
+				throw new MySqlClient.MySqlException(
+					Resources.GetString("ReadFromStreamFailed"), true, null);
 			}
+
+			Array.Copy(buf, 0, buffer, offset, read);
 			return (int)read;
 		}
 
 		public override void Close()
 		{
-//			stream.Close();
-			//stream = null;
-			NativeMethods.CloseHandle((IntPtr)pipeHandle);
-			pipeHandle = 0;
+			if (pipeHandle != 0)
+			{
+				NativeMethods.CloseHandle((IntPtr)pipeHandle);
+				pipeHandle = 0;
+			}
 		}
 
 		public override void SetLength(long length)
@@ -173,14 +137,6 @@
 
 		public override void Write(byte[] buffer, int offset, int count)
 		{
-//			try 
-//			{
-//				stream.Write( buffer, offset, count );
-//			}
-//			catch (Exception ex) 
-//			{
-//				Console.WriteLine( ex.Message );
-//			}
 			if (buffer == null) 
 				throw new ArgumentNullException("buffer", Resources.GetString("BufferCannotBeNull"));
 			if (buffer.Length < (offset + count))
@@ -194,7 +150,7 @@
 			if (! CanWrite)
 				throw new NotSupportedException(Resources.GetString("StreamNoWrite"));
 			if (pipeHandle == 0)
-				throw new ObjectDisposedException("NamedPipeStream",
Resources.GetString("StreamAlreadyClosed"));
+				return;
 			
 			// copy data to internal buffer to allow writing from a specified offset
 			uint bytesWritten = 0;
@@ -217,34 +173,13 @@
 					count -= cnt;
 					offset += cnt;
 				}
-
-//				byte[] tempBuf = new byte[count];
-//				try 
-//				{
-//					Array.Copy( buffer, offset, tempBuf, 0, count );
-//				}
-//				catch (Exception ex) 
-//				{
-//					Console.Write(ex.Message);
-//				}
-//				localBuf = tempBuf;
 			}
 
-//			bool result = Win32.WriteFile( pipeHandle, localBuf, (uint)count, out bytesWritten,
null );
-//			byte[] buf = new Byte[count];
-//			for (int x=0; x < count; x++) 
-//			{
-//				buf[x] = buffer[offset+x];
-//			}
-//			uint written=0;
-//			GCHandle h = GCHandle.Alloc( buffer, GCHandleType.Pinned );
-//			IntPtr addr = Marshal.UnsafeAddrOfPinnedArrayElement( buffer, offset );
-//			bool result = WriteFile( pipeHandle, addr, (uint)count, ref written, IntPtr.Zero );
-//			h.Free();
-
 			if (! result)
 			{
-				throw new IOException("Writing to the stream failed");
+				Close();
+				throw new MySqlClient.MySqlException(Resources.GetString("WriteToStreamFailed"),
+					true, null);
 			}
 			if (bytesWritten < count)
 				throw new IOException("Unable to write entire buffer to stream");

Modified: branches/1.0/mysqlclient/common/Resources.cs
===================================================================
--- branches/1.0/mysqlclient/common/Resources.cs	2005-08-23 18:35:28 UTC (rev 157)
+++ branches/1.0/mysqlclient/common/Resources.cs	2005-08-23 20:35:40 UTC (rev 158)
@@ -30,7 +30,8 @@
 		public static string GetString(string name)
 		{
 			if (rm == null)
-				rm = new ResourceManager("Strings", System.Reflection.Assembly.GetCallingAssembly());
+				rm = new ResourceManager("MySql.Data.MySqlClient.MySqlClient.Strings", 
+					System.Reflection.Assembly.GetCallingAssembly());
 			return rm.GetString (name);
 		}
 	}

Thread
Connector/NET commit: r158 - in branches/1.0: . TestSuite TestSuite/configs mysqlclient mysqlclient/commonrburnett23 Aug