Esempio n. 1
0
        /// <summary>
        /// Check for timeout from timeout queue thread.
        /// </summary>
        protected internal bool CheckTimeout()
        {
            if (state != IN_PROGRESS)
            {
                return(false);
            }

            long elapsed = watch.ElapsedMilliseconds;

            if (policy.totalTimeout > 0)
            {
                // Check total timeout.
                if (elapsed < policy.totalTimeout)
                {
                    return(true);                    // Timeout not reached.
                }

                // Total timeout has occurred.
                if (Interlocked.CompareExchange(ref state, FAIL_TOTAL_TIMEOUT, IN_PROGRESS) == IN_PROGRESS)
                {
                    // Close connection. This will result in a socket error in the async callback thread.
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
                return(false);                 // Do not put back on timeout queue.
            }
            else
            {
                // Check socket idle timeout.
                if (elapsed < policy.socketTimeout)
                {
                    return(true);                    // Timeout not reached.
                }

                if (eventReceived)
                {
                    // Event(s) received within socket timeout period.
                    eventReceived = false;
                    watch         = Stopwatch.StartNew();
                    return(true);
                }

                // Socket timeout has occurred.
                if (Interlocked.CompareExchange(ref state, FAIL_SOCKET_TIMEOUT, IN_PROGRESS) == IN_PROGRESS)
                {
                    // Close connection. This will result in a socket error in the async callback thread.
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
                return(false);                 // Do not put back on timeout queue.
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (!active || !asyncConnQueue.TryAdd(conn))
     {
         conn.Close();
     }
 }
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (!(active && asyncConnQueue.Enqueue(conn)))
     {
         conn.Close();
     }
 }
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (!active || !asyncConnQueue.TryAdd(conn))
     {
         conn.Close();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (active)
     {
         asyncConnQueue.Enqueue(conn);
     }
     else
     {
         conn.Close();
     }
 }
        /// <summary>
        /// Check for timeout from timeout queue thread.
        /// </summary>
        protected internal bool CheckTimeout()
        {
            if (state != IN_PROGRESS)
            {
                return(false);
            }

            if (watch.ElapsedMilliseconds > policy.timeout)
            {
                // Command has timed out in timeout queue thread.
                if (Interlocked.CompareExchange(ref state, FAIL_TIMEOUT, IN_PROGRESS) == IN_PROGRESS)
                {
                    // Close connection. This will result in a socket error in the async callback thread.
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
                return(false);        // Do not put back on timeout queue.
            }
            return(true);             // Put back on timeout queue.
        }
 private void ResetConnection()
 {
     if (watch != null)
     {
         // A lock on reset is required when a client timeout is specified.
         lock (this)
         {
             if (conn != null)
             {
                 conn.Close();
                 conn = null;
             }
         }
     }
     else
     {
         if (conn != null)
         {
             conn.Close();
             conn = null;
         }
     }
 }
        public bool CheckTimeout()
        {
            if (state != 0)
            {
                return(false);                // Do not put back on timeout queue.
            }

            long elapsed = watch.ElapsedMilliseconds;

            if (elapsed < cluster.connectionTimeout)
            {
                return(true);                // Timeout not reached.
            }

            if (Interlocked.CompareExchange(ref state, 1, 0) == 0)
            {
                // Close connection. This will result in a socket error.
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(false);            // Do not put back on timeout queue.
        }
        /// <summary>
        /// Get asynchronous socket connection from connection pool for the server node.
        /// </summary>
        public AsyncConnection GetAsyncConnection()
        {
            // Try to find connection in pool.
            AsyncConnection conn = null;

            while (asyncConnQueue.TryDequeue(out conn))
            {
                if (conn.IsValid())
                {
                    return(conn);
                }
                conn.Close();
            }
            return(null);
        }
        /// <summary>
        /// Get asynchronous socket connection from connection pool for the server node.
        /// </summary>
        public AsyncConnection GetAsyncConnection()
        {
            // Try to find connection in pool.
            AsyncConnection conn = null;

            while (asyncConnQueue.TryDequeue(out conn))
            {
                if (cluster.IsConnCurrentTran(conn.LastUsed) && conn.IsValid())
                {
                    return(conn);
                }
                conn.Close();
            }
            return(null);
        }
Esempio n. 11
0
 private void CloseAsyncConn(AsyncConnection conn)
 {
     DecrAsyncConnTotal();
     IncrAsyncConnClosed();
     conn.Close();
 }