From: Date: January 8 2008 6:03pm Subject: Connector/NET commit: r1136 - in branches/5.1: . Driver/Source List-Archive: http://lists.mysql.com/commits/40702 X-Bug: 27865 Message-Id: <200801081703.m08H3iKL018940@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.1/CHANGES branches/5.1/Driver/Source/MySqlStream.cs branches/5.1/Driver/Source/NativeDriver.cs Log: - Fixed long standing problem with compression over a network. It's now fast again. (bug #27865) We were using a bufferedstream on top of a compression stream and this was causing some significant slowdowns. Modified: branches/5.1/CHANGES =================================================================== --- branches/5.1/CHANGES 2008-01-02 21:09:25 UTC (rev 1135) +++ branches/5.1/CHANGES 2008-01-08 17:03:44 UTC (rev 1136) @@ -1,6 +1,7 @@ Version 5.1.5 - - Fixed problem with membership provider where FindUserByEmail would fail trying to add a second parameter with the same name as the first (bug #33347) + - Fixed long standing problem with compression over a network. It's now fast again. (bug #27865) Version 5.1.4 - 11/12/2007 - Fixed issue where column name metadata was not using the charset given on the connection string Modified: branches/5.1/Driver/Source/MySqlStream.cs =================================================================== --- branches/5.1/Driver/Source/MySqlStream.cs 2008-01-02 21:09:25 UTC (rev 1135) +++ branches/5.1/Driver/Source/MySqlStream.cs 2008-01-08 17:03:44 UTC (rev 1136) @@ -41,16 +41,15 @@ private int maxBlockSize; private ulong maxPacketSize; - private BufferedStream inStream; + private Stream inStream; private ulong inLength; private ulong inPos; - private BufferedStream outStream; + private Stream outStream; private ulong outLength; private ulong outPos; private bool isLastPacket; private byte[] byteBuffer; - private Stream baseStream; public MySqlStream(Encoding encoding) { @@ -69,13 +68,18 @@ peekByte = -1; } - public MySqlStream(Stream baseStr, Encoding encoding) - : this(encoding) - { - baseStream = baseStr; + public MySqlStream(Stream baseStream, Encoding encoding, bool compress) + : this(encoding) + { + inStream = new BufferedStream(baseStream); outStream = new BufferedStream(baseStream); - } + if (compress) + { + inStream = new CompressedStream(inStream); + outStream = new CompressedStream(outStream); + } + } public void Close() { @@ -190,6 +194,7 @@ sequenceByte = (byte)++seqByte; inLength = (ulong)(b1 + (b2 << 8) + (b3 << 16)); + inPos = 0; } catch (IOException ioex) @@ -218,7 +223,8 @@ buffer[1] = (byte)((count >> 8) & 0xff); buffer[2] = (byte)((count >> 16) & 0xff); buffer[3] = sequenceByte++; - baseStream.Write(buffer, 0, count + 4); + outStream.Write(buffer, 0, count + 4); + outStream.Flush(); } /// @@ -456,11 +462,6 @@ try { outStream.Flush(); - if (baseStream is CompressedStream) - // we do a flush on the basestream here because we might be sitting on top of - // a compression stream and calling flush on the BufferedStream doesn't always - // call flush on the underlying stream. - baseStream.Flush(); } catch (IOException ioex) { Modified: branches/5.1/Driver/Source/NativeDriver.cs =================================================================== --- branches/5.1/Driver/Source/NativeDriver.cs 2008-01-02 21:09:25 UTC (rev 1135) +++ branches/5.1/Driver/Source/NativeDriver.cs 2008-01-08 17:03:44 UTC (rev 1136) @@ -207,7 +207,7 @@ throw new MySqlException("Unable to connect to any of the specified MySQL hosts"); int maxSinglePacket = 255*255*255; - stream = new MySqlStream(baseStream, encoding); + stream = new MySqlStream(baseStream, encoding, false); // read off the welcome packet and parse out it's values stream.OpenPacket(); @@ -269,7 +269,7 @@ // if we are using compression, then we use our CompressedStream class // to hide the ugliness of managing the compression if ((connectionFlags & ClientFlags.COMPRESS) != 0) - stream = new MySqlStream(new CompressedStream(baseStream), encoding); + stream = new MySqlStream(baseStream, encoding, true); // give our stream the server version we are connected to. // We may have some fields that are read differently based @@ -295,7 +295,7 @@ X509CertificateCollection certs = new X509CertificateCollection(); ss.AuthenticateAsClient(String.Empty, certs, SslProtocols.Default, false); baseStream = ss; - stream = new MySqlStream(ss, encoding); + stream = new MySqlStream(ss, encoding, false); stream.SequenceByte = 2; } catch (Exception)