Exemple #1
0
            public int Compare(
                object x1,
                object y1
                )
            {
                HttpWebRequest x = (HttpWebRequest)x1;
                HttpWebRequest y = (HttpWebRequest)y1;

                if (x.GetHashCode() == y.GetHashCode())
                {
                    return(0);
                }
                else if (x.GetHashCode() < y.GetHashCode())
                {
                    return(-1);
                }
                else if (x.GetHashCode() > y.GetHashCode())
                {
                    return(1);
                }

                return(0);
            }
        /// <devdoc>
        ///    <para>
        ///       Used by the ServicePoint to find a free or new Connection
        ///       for use in making Requests, this is done with the cavet,
        ///       that once a Connection is "locked" it can only be used
        ///       by a specific request.
        ///
        ///     NOTE: For Whidbey: try to integrate this code into FindConnection()
        ///    </para>
        /// </devdoc>
        private Connection FindConnectionAuthenticationGroup(HttpWebRequest request, string connName) {
            Connection leastBusyConnection = null;

            GlobalLog.Print("ConnectionGroup::FindConnectionAuthenticationGroup [" + connName + "] for request#" + request.GetHashCode() +", m_ConnectionList.Count:" + m_ConnectionList.Count.ToString());

            //
            // First try and find a free Connection (i.e. one not busy with Authentication handshake)
            //   or try to find a Request that has already locked a specific Connection,
            //   if a matching Connection is found, then we're done
            //
            lock (m_ConnectionList) {
                Connection matchingConnection;
                matchingConnection = FindMatchingConnection(request, connName, out leastBusyConnection);
                if (matchingConnection != null) {
                    matchingConnection.MarkAsReserved();
                    return matchingConnection;
                }
                if (AuthenticationRequestQueue.Count == 0) {
                    if (leastBusyConnection != null) {
                        if (request.LockConnection) {
                            m_NtlmNegGroup = true;
                            m_IISVersion = leastBusyConnection.IISVersion;
                        }
                        if(request.LockConnection || (m_NtlmNegGroup && !request.Pipelined && request.UnsafeOrProxyAuthenticatedConnectionSharing && m_IISVersion >= 6)){
                            GlobalLog.Print("Assigning New Locked Request#" + request.GetHashCode().ToString());
                            leastBusyConnection.LockedRequest = request;
                        }
                        leastBusyConnection.MarkAsReserved();
                        return leastBusyConnection;
                    }
                }
                else if (leastBusyConnection != null) {
                    AsyncWaitHandle.Set();
                }
                AuthenticationRequestQueue.Enqueue(request);
            }

            //
            // If all the Connections are busy, then we queue ourselves and need to wait.   As soon as
            //   one of the Connections are free, we grab the lock, and see if we find ourselves
            //   at the head of the queue.  If not, we loop backaround.
            //   Care is taken to examine the request when we wakeup, in case the request is aborted.
            //
            while (true) {
                GlobalLog.Print("waiting");
                request.AbortDelegate = m_AbortDelegate;

                if (!request.Aborted)
                    AsyncWaitHandle.WaitOne();

                GlobalLog.Print("wait up");
                lock(m_ConnectionList) {
                    if (request.Aborted)
                    {
                        PruneAbortedRequests();
                        // Note that request is not on any connection and it will not be submitted
                        return null;
                    }

                    FindMatchingConnection(request, connName, out leastBusyConnection);
                    if (AuthenticationRequestQueue.Peek() == request) {
                        GlobalLog.Print("dequeue");
                        AuthenticationRequestQueue.Dequeue();
                        if (leastBusyConnection != null) {
                            if (request.LockConnection) {
                                m_NtlmNegGroup = true;
                                m_IISVersion = leastBusyConnection.IISVersion;
                            }
                            if(request.LockConnection || (m_NtlmNegGroup  && !request.Pipelined && request.UnsafeOrProxyAuthenticatedConnectionSharing && m_IISVersion >= 6)){
                                leastBusyConnection.LockedRequest = request;
                            }

                            leastBusyConnection.MarkAsReserved();
                            return leastBusyConnection;
                        }
                        AuthenticationRequestQueue.Enqueue(request);
                    }
                    if (leastBusyConnection == null) {
                        AsyncWaitHandle.Reset();
                    }
                }
            }
        }
        /// <summary>
        /// Handler that the user will call when they want the request to resume processing.
        /// It will check to ensure that the correct WebRequest is passed back to this resumption point.
        /// Else an error will be thrown.
        /// </summary>
        /// <param name="request">HttpWebRequest for which the processing has to resume.</param>
        void ResumeRequestProcessing(HttpWebRequest request)
        {
            AsyncArgsWrapper wrapper = null;

            this._requestToArgsMapper.TryGetValue(request.GetHashCode(), out wrapper);
            if (wrapper == null)
            {
                // It means they called Resume with another WebRequest. Fail sync.
                throw new CacheControllerException("Incorrect HttpWebRequest object passed to ResumeRequestProcessing callback.");
            }

            try
            {
                this._requestToArgsMapper.Remove(request.GetHashCode());

                this.GetWebResponse(wrapper);
            }
            catch (Exception e)
            {
                if (ExceptionUtility.IsFatal(e))
                {
                    throw;
                }

                wrapper.Error = e;
                this._workerManager.CompleteWorkRequest(wrapper.WorkerRequest, wrapper);
            }
        }
Exemple #4
0
        /// <devdoc>
        ///    <para>
        ///       Used by the ServicePoint to find a free or new Connection
        ///       for use in making Requests, this is done with the cavet,
        ///       that once a Connection is "locked" it can only be used
        ///       by a specific request.
        ///
        ///     NOTE: For Whidbey: try to integrate this code into FindConnection()
        ///    </para>
        /// </devdoc>
        private Connection FindConnectionAuthenticationGroup(HttpWebRequest request, string connName)
        {
            Connection leastBusyConnection = null;

            GlobalLog.Print("ConnectionGroup::FindConnectionAuthenticationGroup [" + connName + "] for request#" + request.GetHashCode() + ", m_ConnectionList.Count:" + m_ConnectionList.Count.ToString());

            //
            // First try and find a free Connection (i.e. one not busy with Authentication handshake)
            //   or try to find a Request that has already locked a specific Connection,
            //   if a matching Connection is found, then we're done
            //
            lock (m_ConnectionList) {
                Connection matchingConnection;
                matchingConnection = FindMatchingConnection(request, connName, out leastBusyConnection);
                if (matchingConnection != null)
                {
                    matchingConnection.MarkAsReserved();
                    return(matchingConnection);
                }
                if (AuthenticationRequestQueue.Count == 0)
                {
                    if (leastBusyConnection != null)
                    {
                        if (request.LockConnection)
                        {
                            m_NtlmNegGroup = true;
                            m_IISVersion   = leastBusyConnection.IISVersion;
                        }
                        if (request.LockConnection || (m_NtlmNegGroup && !request.Pipelined && request.UnsafeOrProxyAuthenticatedConnectionSharing && m_IISVersion >= 6))
                        {
                            GlobalLog.Print("Assigning New Locked Request#" + request.GetHashCode().ToString());
                            leastBusyConnection.LockedRequest = request;
                        }
                        leastBusyConnection.MarkAsReserved();
                        return(leastBusyConnection);
                    }
                }
                else if (leastBusyConnection != null)
                {
                    AsyncWaitHandle.Set();
                }
                AuthenticationRequestQueue.Enqueue(request);
            }

            //
            // If all the Connections are busy, then we queue ourselves and need to wait.   As soon as
            //   one of the Connections are free, we grab the lock, and see if we find ourselves
            //   at the head of the queue.  If not, we loop backaround.
            //   Care is taken to examine the request when we wakeup, in case the request is aborted.
            //
            while (true)
            {
                GlobalLog.Print("waiting");
                request.AbortDelegate = m_AbortDelegate;

                if (!request.Aborted)
                {
                    AsyncWaitHandle.WaitOne();
                }

                GlobalLog.Print("wait up");
                lock (m_ConnectionList) {
                    if (request.Aborted)
                    {
                        PruneAbortedRequests();
                        // Note that request is not on any connection and it will not be submitted
                        return(null);
                    }

                    FindMatchingConnection(request, connName, out leastBusyConnection);
                    if (AuthenticationRequestQueue.Peek() == request)
                    {
                        GlobalLog.Print("dequeue");
                        AuthenticationRequestQueue.Dequeue();
                        if (leastBusyConnection != null)
                        {
                            if (request.LockConnection)
                            {
                                m_NtlmNegGroup = true;
                                m_IISVersion   = leastBusyConnection.IISVersion;
                            }
                            if (request.LockConnection || (m_NtlmNegGroup && !request.Pipelined && request.UnsafeOrProxyAuthenticatedConnectionSharing && m_IISVersion >= 6))
                            {
                                leastBusyConnection.LockedRequest = request;
                            }

                            leastBusyConnection.MarkAsReserved();
                            return(leastBusyConnection);
                        }
                        AuthenticationRequestQueue.Enqueue(request);
                    }
                    if (leastBusyConnection == null)
                    {
                        AsyncWaitHandle.Reset();
                    }
                }
            }
        }
Exemple #5
0
        /// <devdoc>
        ///    <para>
        ///       Used by the ServicePoint to find a free or new Connection
        ///       for use in making Requests, this is done with the cavet,
        ///       that once a Connection is "locked" it can only be used
        ///       by a specific request.
        ///
        ///     NOTE: For Whidbey: try to integrate this code into FindConnection()
        ///    </para>
        /// </devdoc>
        private Connection FindConnectionAuthenticationGroup(HttpWebRequest request, string connName)
        {
            Connection leastBusyConnection = null;

            GlobalLog.Print("ConnectionGroup::FindConnectionAuthenticationGroup [" + connName + "] m_ConnectionList.Count:" + m_ConnectionList.Count.ToString());

            //
            // First try and find a free Connection (i.e. one not busy with Authentication handshake)
            //   or try to find a Request that has already locked a specific Connection,
            //   if a matching Connection is found, then we're done
            //
            lock (m_ConnectionList) {
                Connection matchingConnection;
                matchingConnection = FindMatchingConnection(request, connName, out leastBusyConnection);
                if (matchingConnection != null)
                {
                    return(matchingConnection);
                }

                if (AuthenticationRequestQueue.Count == 0)
                {
                    if (leastBusyConnection != null)
                    {
                        if (request.LockConnection)
                        {
                            GlobalLog.Print("Assigning New Locked Request#" + request.GetHashCode().ToString());
                            leastBusyConnection.LockedRequest = request;
                        }
                        return(leastBusyConnection);
                    }
                }
                else if (leastBusyConnection != null)
                {
                    AsyncWaitHandle.Set();
                }
                AuthenticationRequestQueue.Enqueue(request);
            }

            //
            // If all the Connections are busy, then we queue ourselves and need to wait.   As soon as
            //   one of the Connections are free, we grab the lock, and see if we find ourselves
            //   at the head of the queue.  If not, we loop backaround.
            //   Care is taken to examine the request when we wakeup, in case the request is aborted.
            //
            while (true)
            {
                GlobalLog.Print("waiting");
                request.AbortDelegate = m_AbortDelegate;
                AsyncWaitHandle.WaitOne();
                GlobalLog.Print("wait up");
                lock (m_ConnectionList) {
                    if (m_Abort)
                    {
                        PruneAbortedRequests();
                    }
                    if (request.Aborted)
                    {
                        throw new WebException(
                                  NetRes.GetWebStatusString("net_requestaborted", WebExceptionStatus.RequestCanceled),
                                  WebExceptionStatus.RequestCanceled);
                    }

                    FindMatchingConnection(request, connName, out leastBusyConnection);
                    if (AuthenticationRequestQueue.Peek() == request)
                    {
                        GlobalLog.Print("dequeue");
                        AuthenticationRequestQueue.Dequeue();
                        if (leastBusyConnection != null)
                        {
                            if (request.LockConnection)
                            {
                                leastBusyConnection.LockedRequest = request;
                            }
                            return(leastBusyConnection);
                        }
                        AuthenticationRequestQueue.Enqueue(request);
                    }
                    if (leastBusyConnection == null)
                    {
                        AsyncWaitHandle.Reset();
                    }
                }
            }
        }
Exemple #6
0
        /*++

            ConstructTransport - Creates a transport for a given stream,
            and constructors a transport capable of handling it.

            Input:
                    socket - socket
                    result -
                    request -

            Returns:
                   WebExceptionStatus
        --*/
        private WebExceptionStatus ConstructTransport(Socket socket, ref NetworkStream result, HttpWebRequest request) {
            GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::ConstructTransport", "Socket#"+ValidationHelper.HashString(socket)+", ref NetworkStream, request#"+request.GetHashCode());
            //
            // for now we will look at the scheme and infer SSL if the scheme is "https"
            // in the future this will be replaced by full-extensible
            // scheme for cascadable streams in the future
            //
            Uri destination = request.Address;

            if (destination.Scheme == Uri.UriSchemeHttps) {
                return WebExceptionStatus.SecureChannelFailure;
            }

            if (destination.Scheme != Uri.UriSchemeHttps) {
                //
                // for HTTP we're done
                //
                try {
                    result = new NetworkStream(socket, true);
                }
                catch {
                    GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::ConstructTransport");
                    return WebExceptionStatus.ConnectFailure;
                }
                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::ConstructTransport");
                return WebExceptionStatus.Success;
            }

            //
            // we have to do our tunneling first for proxy case
            //
            if (m_Server.InternalProxyServicePoint) {

                bool success = TunnelThroughProxy(m_Server.Address, request, out socket);

                if (!success) {
                    GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::ConstructTransport");
                    return WebExceptionStatus.ConnectFailure;
                }
            }

            return WebExceptionStatus.ConnectFailure;
        }