/// <summary>
        /// Resets the status of reestablishing.
        /// </summary>
        public void Reestablish_ResetStatus()
        {
            lock (this._accessToLocalMembers)
            {
                if (!_reestablish_IsBeingReestablished)
                {
                    BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;

                    if (binaryLogWriter != null)
                    {
                        binaryLogWriter.WriteImplementationWarningEvent("PhysicalConnection.Reestablish_ResetStatus",
                                                                        LogMessageType.Error, GenuineExceptions.Get_Debugging_GeneralWarning("The connection is not being reestablished!"),
                                                                        GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                                        "The connection is not being reestablished!");
                    }
                }

                _reestablish_IsBeingReestablished = false;
            }
        }
Exemple #2
0
        /// <summary>
        /// Releases expired host structures.
        /// </summary>
        public void TimerCallback()
        {
            int             now             = GenuineUtility.TickCount;
            HostInformation hostInformation = null;

            // the released host
            ArrayList hostsToDelete = new ArrayList();

            // the entries being deleted
            ArrayList urisToDelete = new ArrayList();

            lock (this.SyncRoot)
            {
                // through all registered hosts
                foreach (DictionaryEntry entry in this._hashtable)
                {
                    ArrayList hosts = (ArrayList)entry.Value;
                    for (int i = 0; i < hosts.Count;)
                    {
                        hostInformation = (HostInformation)hosts[i];

                        // if the time has run out
                        if (GenuineUtility.IsTimeoutExpired(hostInformation.ExpireTime, now) || hostInformation.IsDisposed)
                        {
                            // exclude the host
                            hosts.RemoveAt(i);
                            hostsToDelete.Add(hostInformation);

                            // check on entry excluding
                            if (hosts.Count <= 0)
                            {
                                urisToDelete.Add(entry.Key);
                            }
                            continue;
                        }

                        i++;
                    }
                }

                // it is very important to remove all references to the host before disposing it
                foreach (string key in urisToDelete)
                {
                    this._hashtable.Remove(key);
                }

                // dispose all hosts
                foreach (HostInformation hostInformationExcluded in hostsToDelete)
                {
                    // LOG:
                    BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;
                    if (binaryLogWriter != null && binaryLogWriter[LogCategory.HostInformation] > 0)
                    {
                        binaryLogWriter.WriteEvent(LogCategory.HostInformation, "KnownHosts.this[string]",
                                                   LogMessageType.HostInformationReferencesDisassociated, GenuineExceptions.Get_Debugging_GeneralWarning("The association between HostInformation and its URL or URI has been broken."),
                                                   null, hostInformationExcluded, null,
                                                   GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                   null, null, -1, 0, 0, 0, hostInformationExcluded.Uri, hostInformationExcluded.Url, null, null,
                                                   "The current HostInformation does not refer to \"{0}\" and \"{1}\" any longer.",
                                                   hostInformationExcluded.Uri == null ? string.Empty : hostInformationExcluded.Uri,
                                                   hostInformationExcluded.Url == null ? string.Empty : hostInformationExcluded.Url);
                    }

                    GenuineThreadPool.QueueUserWorkItem(new WaitCallback(this.ReleaseHostResources), new HostInformationAndReason(hostInformationExcluded, GenuineExceptions.Get_Channel_ClientDidNotReconnectWithinTimeOut(hostInformationExcluded.ToString())), true);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Decreases all queue counters according to the provided message.
        /// WARNING: Releases all message resoruces.
        /// </summary>
        /// <param name="message">The message.</param>
        public void UnregisterSyncMessage(Message message)
        {
            lock (this._queue)
            {
                this._currentTotalMessages--;
                this._currentTotalSize -= message.EffectiveMessageSize;

                if (this._currentTotalMessages < 0 || this._currentTotalSize < 0)
                {
                    // LOG:
                    BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;
                    if (binaryLogWriter != null)
                    {
                        binaryLogWriter.WriteImplementationWarningEvent("MessageContainer.UnregisterSyncMessage",
                                                                        LogMessageType.CriticalError, GenuineExceptions.Get_Debugging_GeneralWarning("Implementation bug."),
                                                                        GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                                        "Incorrect queue state. CurrentTotalMessages = {0}. CurrentTotalSize = {1}.",
                                                                        this._currentTotalMessages, this._currentTotalSize);
                    }
                }
            }
        }
        /// <summary>
        /// Processes sending results.
        /// </summary>
        /// <param name="ar">The result.</param>
        private void Callback_OnEndReceiving(IAsyncResult ar)
        {
            BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter;

            try
            {
#if DEBUG
                if (ar.AsyncState != this.Listener && binaryLogWriter != null)
                {
                    binaryLogWriter.WriteImplementationWarningEvent("HttpClientConnection.Callback_OnEndSending",
                                                                    LogMessageType.Warning, GenuineExceptions.Get_Debugging_GeneralWarning("The provided receiver does not match the expected Listener instance"),
                                                                    GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                                    "The provided receiver does not match the expected Listener instance.");
                }
#endif


                HttpWebRequest httpWebRequest = (HttpWebRequest)ar.AsyncState;
#if (FRM20)
                // timeout has been already set
                HttpWebResponse httpWebResponse = null;
                try
                {
                    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    if (ex.Status == WebExceptionStatus.Timeout)
                    {
                        return;
                    }
                }
#else
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.EndGetResponse(ar);
#endif


                if (this._disposed)
                {
                    httpWebResponse.GetResponseStream().Close();
                    httpWebResponse.Close();
                    return;
                }

                this.ITransportContext.ConnectionManager.IncreaseBytesReceived((int)httpWebResponse.ContentLength);
                this.HttpClientConnectionManager.Listener_OnEndReceiving(this, httpWebResponse);
            }
            catch (Exception ex)
            {
                // LOG:
                if (binaryLogWriter != null && binaryLogWriter[LogCategory.LowLevelTransport] > 0)
                {
                    binaryLogWriter.WriteEvent(LogCategory.LowLevelTransport, "HttpClientConnection.Callback_OnEndReceiving",
                                               LogMessageType.LowLevelTransport_AsyncReceivingCompleted, ex, null, this.Remote, null,
                                               GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null,
                                               this.DbgConnectionId, 0, 0, 0, null, null, null, null,
                                               "Exception occurred while completing an asynchronous receiving.");
                }

                try
                {
                    // TODO: Receiving has been completed by this time. Wny do we call abort?
#if (!FRM20)
                    HttpWebRequest httpWebRequest = (HttpWebRequest)ar.AsyncState;
                    httpWebRequest.Abort();
#endif
                }
                catch
                {
                }

                if (this._disposed)
                {
                    return;
                }

                this.HttpClientConnectionManager.StartReestablishingIfNecessary(this, ex, false);
//
//				this.HttpClientConnectionManager.ConnectionFailed(this, false, ex, true);
            }
        }