Exemple #1
0
            /// <summary>
            /// Releases an item back into the pool
            /// </summary>
            /// <param name="socket"></param>
            private void ReleaseSocket(IPooledSocket socket)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Releasing socket " + socket.InstanceId);
                    log.Debug("Are we alive? " + this.isAlive);
                }

                if (this.isAlive)
                {
                    // is it still working (i.e. the server is still connected)
                    if (socket.IsAlive)
                    {
                        // mark the item as free
                        this.freeItems.Push(socket);
                    }
                    else
                    {
                        // kill this item
                        //socket.Destroy();
                        socket.Dispose();

                        // mark ourselves as not working for a while
                        this.MarkAsDead();
                    }
                }
                else
                {
                    // one of our previous sockets has died, so probably all of them
                    // are dead. so, kill the socket (this will eventually clear the pool as well)
                    //socket.Destroy();
                    socket.Dispose();
                }

                // In any event, we want to let any waiters know that we can create a new
                // socket:
                if (semaphore != null)
                {
                    try
                    {
                        semaphore.Release();
                    }
                    catch (ObjectDisposedException e)
                    {
                        log.Error(e);
                    }
                }
            }
Exemple #2
0
        public bool ExecuteAsync(IOperation op, Action <bool> next)
        {
            IPooledSocket socket = null;
            var           result = false;

            try
            {
                socket = _pool.Acquire();
                var buffers = op.GetBuffer();
                socket.Write(buffers);

                result = op.ReadResponseAsync(socket, readSuccess =>
                {
                    socket.Dispose();
                    next(readSuccess);
                });
            }
            catch (IOException e)
            {
                Log.Error(e);
            }
            finally
            {
                if (socket != null)
                {
                    _pool.Release(socket);
                }
            }
            return(result);
        }