Index: Driver.cs =================================================================== --- Driver.cs (.../MySql.Data/Driver/Source) (revision 29458) +++ Driver.cs (.../FogBugz/MySql.Data/Driver/Source) (working copy) @@ -302,6 +302,7 @@ public abstract MySqlField[] ReadColumnMetadata(int count); public abstract bool Ping(); public abstract void CloseStatement(int id); + public abstract int TimeOut { set; } #endregion Index: datareader.cs =================================================================== --- datareader.cs (.../MySql.Data/Driver/Source) (revision 29458) +++ datareader.cs (.../FogBugz/MySql.Data/Driver/Source) (working copy) @@ -50,6 +50,8 @@ private bool hasRead; private bool nextResultDone; + public int TimeOut { set { driver.TimeOut = value; } } + /* * Keep track of the connection in order to implement the * CommandBehavior.CloseConnection flag. A null reference means Index: NativeDriver.cs =================================================================== --- NativeDriver.cs (.../MySql.Data/Driver/Source) (revision 29458) +++ NativeDriver.cs (.../FogBugz/MySql.Data/Driver/Source) (working copy) @@ -279,6 +279,7 @@ stream.MaxBlockSize = maxSinglePacket; isOpen = true; + TimeOut = this.timeout; } #region SSL @@ -869,5 +870,24 @@ stream.Flush(); } - } + int timeout; + public override int TimeOut + { + set + { + if (isOpen) + { + NetworkStream ns = baseStream as NetworkStream; + if (ns != null) + { + // 0 and -1 both mean infinite to us, but only -1 means infinite to the NetworkStream object + if (value == 0) + value = -1; + ns.WriteTimeout = ns.ReadTimeout = value; + } + } + timeout = value; + } + } + } } Index: command.cs =================================================================== --- command.cs (.../MySql.Data/Driver/Source) (revision 29458) +++ command.cs (.../FogBugz/MySql.Data/Driver/Source) (working copy) @@ -391,16 +391,8 @@ // indicate that we can now be canceled canCancel = true; - // start a timeout timer - if (connection.driver.Version.isAtLeast(5, 0, 0) && - commandTimeout > 0) - { - TimerCallback timerDelegate = - new TimerCallback(TimeoutExpired); - timer = new Timer(timerDelegate, this, this.CommandTimeout * 1000, Timeout.Infinite); - } - // wait for data to return + reader.TimeOut = this.CommandTimeout * 1000; reader.NextResult(); // if we get here, then we have started receiving data and Index: common/StreamCreator.cs =================================================================== --- common/StreamCreator.cs (.../MySql.Data/Driver/Source) (revision 29458) +++ common/StreamCreator.cs (.../FogBugz/MySql.Data/Driver/Source) (working copy) @@ -150,19 +150,14 @@ Socket socket = unix ? new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP) : new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IAsyncResult ias = socket.BeginConnect(endPoint, null, null); - if (!ias.AsyncWaitHandle.WaitOne((int)timeOut * 1000, false)) - { - socket.Close(); - return null; - } + socket.ReceiveTimeout = socket.SendTimeout = (int)timeOut * 1000; try { - socket.EndConnect(ias); - } + socket.Connect(endPoint); + } catch (Exception) { - socket.Close(); + socket.Close(); return null; } NetworkStream stream = new NetworkStream(socket, true);