// /// <summary> // /// The moment when this request was received. // /// </summary> // public int Received = GenuineUtility.TickCount; /// <summary> /// Completes the asynchronous invocation. /// </summary> /// <param name="completedSynchronously">True if the request was completed synchronously.</param> public void Complete(bool completedSynchronously) { try { this._completedSynchronously = completedSynchronously; this._asyncWaitHandle.Set(); if (this.AsyncCallback != null) { this.AsyncCallback.DynamicInvoke(new object[] { (IAsyncResult)this }); } } catch (Exception ex) { // LOG: BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter; if (binaryLogWriter != null) { binaryLogWriter.WriteImplementationWarningEvent("HttpServerRequestResult.Complete", LogMessageType.CriticalError, ex, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, "Fatal logic error."); } } }
/// <summary> /// Releases all resources related to the specified connection. /// </summary> /// <param name="exception">The reason.</param> /// <param name="sharedMemoryConnection">The connection.</param> private void ConnectionFailed(Exception exception, SharedMemoryConnection sharedMemoryConnection) { BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; try { sharedMemoryConnection.IsValid = false; // LOG: if (binaryLogWriter != null && binaryLogWriter[LogCategory.Connection] > 0) { binaryLogWriter.WriteEvent(LogCategory.Connection, "SharedMemoryConnectionManager.ConnectionFailed", LogMessageType.ConnectionFailed, exception, null, sharedMemoryConnection.Remote, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, sharedMemoryConnection.DbgConnectionId, 0, 0, 0, null, null, null, null, "Connection has failed."); } // unregister the connection if (sharedMemoryConnection.Remote.GenuinePersistentConnectionState == GenuinePersistentConnectionState.Accepted) { this._persistent.Remove(sharedMemoryConnection.Remote.Uri); } else { this._persistent.Remove(sharedMemoryConnection.Remote.Url); } // release all resources this.ITransportContext.KnownHosts.ReleaseHostResources(sharedMemoryConnection.Remote, exception); sharedMemoryConnection.ReleaseUnmanagedResources(); sharedMemoryConnection.SignalState(GenuineEventType.GeneralConnectionClosed, exception, null); } catch (Exception ex) { // LOG: if (binaryLogWriter != null) { binaryLogWriter.WriteImplementationWarningEvent("SharedMemoryConnectionManager.ConnectionFailed", LogMessageType.CriticalError, ex, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, "Unexpected exception inside the SharedMemoryClientConnectionManager.ConnectionFailed method. Most likely, something must be fixed."); } } }
/// <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; } }
/// <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> /// Registers the receiver and associate the provided object with it. /// Returns false if the receiver has already been registered. /// WARNING: does not check whether the receiver supports the required interface (via Reflection) /// because this check requires client's dll. /// </summary> /// <param name="obj">The receiver being registered.</param> /// <param name="tag">The object associated with the receiver. This object is accessible when receiver is being unregistered or during filtering.</param> /// <param name="remoteGenuineUri">The uri of the remote host provided by any of Genuine Channels.</param> /// <param name="transportContext">The transport context of the remote host.</param> /// <returns>False if the receiver has been already registered.</returns> public bool Add(MarshalByRefObject obj, object tag, string remoteGenuineUri, ITransportContext transportContext) { if (obj == null) { throw new ArgumentNullException("obj"); } BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter; // check if it is in the list string uri = RemotingServices.GetObjectUri(obj); if (uri == null && !RemotingServices.IsObjectOutOfAppDomain(obj)) { // it was not marshalled RemotingServices.Marshal(obj); uri = RemotingServices.GetObjectUri(obj); } using (ReaderAutoLocker reader = new ReaderAutoLocker(this._readerWriterLock)) { if (this._receivers.ContainsKey(uri)) { return(false); } } // this check can not be performed because client's dll is required // // check on the interface // bool supportInterface = false; // foreach(Type interfaceType in obj.GetType().GetInterfaces()) // if (interfaceType == this._interfaceToSupport) // { // supportInterface = true; // break; // } // if (! supportInterface) // throw GenuineExceptions.Get_Broadcast_ObjectDoesNotSupportDestinationInterface(); // adds the object to the receiver list ReceiverInfo receiverInfo = new ReceiverInfo(); receiverInfo.MbrObject = obj; receiverInfo.MbrUri = uri; receiverInfo.Tag = tag; if (binaryLogWriter != null) { try { if (receiverInfo.MbrObject != null) { receiverInfo.DbgRemoteHost = GenuineUtility.FetchHostInformationFromMbr(receiverInfo.MbrObject); } } catch (Exception ex) { binaryLogWriter.WriteImplementationWarningEvent("Dispatcher.Add", LogMessageType.Error, ex, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, "Can't get HostInformation from MbrObject."); } } ObjRef objRef = receiverInfo.MbrObject.CreateObjRef(typeof(MarshalByRefObject)); receiverInfo.Local = objRef.IsFromThisAppDomain(); // cache object's info to speed up sending thru Genuine Channels if (!receiverInfo.Local) { if (remoteGenuineUri != null) { receiverInfo.IClientChannelSink = new GenuineTcpClientTransportSink(remoteGenuineUri, transportContext); } else { // check whether the client sink has registered itself on this MBR receiverInfo.IClientChannelSink = ChannelServices.GetChannelSinkProperties(obj)["GC_TS"] as IClientChannelSink; if (receiverInfo.IClientChannelSink == null) { throw GenuineExceptions.Get_Broadcast_ClientSinkIsUnknown(); } } // object uri receiverInfo.SerializedObjRef = objRef; // // and shell's uri // string shellUri; // ITransportContext iTransportContext; // GenuineUtility.FetchChannelUriFromMbr(obj, out shellUri, out iTransportContext); // if (shellUri == null) // throw GenuineExceptions.Get_Send_NoSender(objRef.URI); // // receiverInfo.ReceiverUri = shellUri; } // LOG: if (binaryLogWriter != null && binaryLogWriter[LogCategory.BroadcastEngine] > 0) { binaryLogWriter.WriteBroadcastEngineEvent(LogCategory.BroadcastEngine, "Dispatcher.Add", LogMessageType.BroadcastRecipientAdded, null, null, receiverInfo.DbgRemoteHost, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, false, this, null, true, receiverInfo, null, null, "The broadcast recipient is added."); } // register the sponsor to prevent unexpected reclaiming ILease lease = (ILease)RemotingServices.GetLifetimeService(obj); if (lease != null) { lease.Register(this.GlobalSponsor); } // and register it using (WriterAutoLocker writer = new WriterAutoLocker(this._readerWriterLock)) { this._cachedReceiversInfoArray = null; this._receivers[uri] = receiverInfo; } return(true); }
/// <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); } }