Example #1
0
        internal void Execute(SocketPool pool, UseSocket use)
        {
            MSocket sock = null;

            try
            {
                //Acquire a socket
                sock = pool.Acquire();

                //Use the socket as a parameter to the delegate and return its result.
                if (sock != null)
                {
                    use(sock);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error in Execute: " + pool.Host, e);

                //Socket is probably broken
                if (sock != null)
                {
                    sock.Close();
                }
            }
            finally
            {
                if (sock != null)
                {
                    sock.Dispose();
                }
            }
        }
Example #2
0
        internal T Execute <T>(SocketPool pool, T defaultValue, UseSocket <T> use)
        {
            MSocket sock = null;

            try
            {
                //Acquire a socket
                sock = pool.Acquire();

                //Use the socket as a parameter to the delegate and return its result.
                if (sock != null)
                {
                    return(use(sock));
                }
            }
            catch (Exception e)
            {
                logger.Error("Error in Execute<T>: " + pool.Host, e);

                //Socket is probably broken
                if (sock != null)
                {
                    sock.Close();
                }
            }
            finally
            {
                if (sock != null)
                {
                    sock.Dispose();
                }
            }
            return(defaultValue);
        }