public static void OnEndSend(IPeerNeighbor neighbor, FloodAsyncResult fresult)
 {
     if (neighbor.State < PeerNeighborState.Disconnecting)
     {
         UtilityExtension utility = neighbor.Utility;
         if (utility != null)
         {
             utility.OnEndSend(fresult);
         }
     }
 }
Beispiel #2
0
        public virtual void EndFloodMessage(IAsyncResult result)
        {
            if (result is CompletedAsyncResult)
            {
                CompletedAsyncResult.End(result);
                return;
            }
            FloodAsyncResult fresult = result as FloodAsyncResult;

            Fx.Assert(fresult != null, "Invalid AsyncResult type in EndFloodResult");
            fresult.End();
        }
Beispiel #3
0
        public static void OnEndSend(IPeerNeighbor neighbor, FloodAsyncResult fresult)
        {
            if (neighbor.State >= PeerNeighborState.Disconnecting)
            {
                return;
            }
            UtilityExtension instance = neighbor.Utility;

            if (instance == null)
            {
                return;
            }
            instance.OnEndSend(fresult);
        }
 public static void EndFloodEncodedMessage(IAsyncResult result)
 {
     if (result is CompletedAsyncResult)
     {
         CompletedAsyncResult.End(result);
     }
     else
     {
         FloodAsyncResult result3 = result as FloodAsyncResult;
         if (result3 == null)
         {
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("result", System.ServiceModel.SR.GetString("InvalidAsyncResult"));
         }
         result3.End();
     }
 }
Beispiel #5
0
        public static void EndFloodEncodedMessage(IAsyncResult result)
        {
            CompletedAsyncResult cresult = result as CompletedAsyncResult;

            if (cresult != null)
            {
                CompletedAsyncResult.End(result);
            }
            else
            {
                FloodAsyncResult fresult = result as FloodAsyncResult;
                if (fresult == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("result", SR.GetString(SR.InvalidAsyncResult));
                }
                fresult.End();
            }
        }
        protected virtual IAsyncResult FloodMessageToNeighbors(MessageBuffer messageBuffer, TimeSpan timeout, AsyncCallback callback, object state, int index, MessageHeader hopHeader, IPeerNeighbor except, EventHandler OnMessageSentCallback)
        {
            Interlocked.Increment(ref this.messageSequence);
            FloodAsyncResult fresult = new FloodAsyncResult(this.neighborManager, timeout, callback, state);

            fresult.OnMessageSent += OnMessageSentCallback;
            foreach (IPeerNeighbor neighbor in this.Neighbors)
            {
                if (!neighbor.Equals(except) && PeerNeighborStateHelper.IsConnected(neighbor.State))
                {
                    Message message = messageBuffer.CreateMessage();
                    if (index != -1)
                    {
                        message.Headers.ReplaceAt(index, hopHeader);
                    }
                    if (PeerNeighborStateHelper.IsConnected(neighbor.State))
                    {
                        this.BeginSendHelper(neighbor, timeout, message, fresult);
                    }
                }
            }
            fresult.MarkEnd(true);
            return(fresult);
        }
Beispiel #7
0
        protected virtual IAsyncResult FloodMessageToNeighbors(MessageBuffer messageBuffer,
                                                               TimeSpan timeout, AsyncCallback callback, object state,
                                                               int index, MessageHeader hopHeader, IPeerNeighbor except,
                                                               EventHandler OnMessageSentCallback)
        {
            long             temp    = Interlocked.Increment(ref messageSequence);
            FloodAsyncResult fresult = new FloodAsyncResult(this.neighborManager, timeout, callback, state);

            fresult.OnMessageSent += OnMessageSentCallback;
            List <IPeerNeighbor> neighbors = this.Neighbors;

            foreach (IPeerNeighbor neighbor in neighbors)
            {
                if (neighbor.Equals(except))
                {
                    continue;
                }
                // Don't do anything if the neighbor is not connected
                if (PeerNeighborStateHelper.IsConnected(neighbor.State))
                {
                    Message fmessage = messageBuffer.CreateMessage();
                    if (index != -1)
                    {
                        fmessage.Headers.ReplaceAt(index, hopHeader);
                    }

                    // Don't do anything if the neighbor is not connected
                    if (PeerNeighborStateHelper.IsConnected(neighbor.State))
                    {
                        BeginSendHelper(neighbor, timeout, fmessage, fresult);
                    }
                }
            }
            fresult.MarkEnd(true);
            return(fresult);
        }
        protected IAsyncResult BeginSendHelper(IPeerNeighbor neighbor, TimeSpan timeout, Message message, FloodAsyncResult fresult)
        {
            IAsyncResult result = null;
            IAsyncResult result2;
            bool         flag = false;

            try
            {
                UtilityExtension.OnMessageSent(neighbor);
                result = neighbor.BeginSend(message, timeout, Fx.ThunkCallback(new AsyncCallback(fresult.OnSendComplete)), message);
                fresult.AddResult(result, neighbor);
                if (result.CompletedSynchronously)
                {
                    neighbor.EndSend(result);
                    UtilityExtension.OnEndSend(neighbor, fresult);
                }
                result2 = result;
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    flag = true;
                    throw;
                }
                if (PeerFlooderBase <TFloodContract, TLinkContract> .CloseNeighborIfKnownException(this.neighborManager, exception, neighbor) != null)
                {
                    fresult.MarkEnd(false);
                    throw;
                }
                System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                result2 = null;
            }
            finally
            {
                if (((result == null) || result.CompletedSynchronously) && !flag)
                {
                    message.Close();
                }
            }
            return(result2);
        }
Beispiel #9
0
        public void EndFloodReceivedMessage(IAsyncResult result)
        {
            FloodAsyncResult fresult = result as FloodAsyncResult;

            Fx.Assert(fresult != null, "Invalid FloodAsyncResult instance during EndFloodReceivedMessage");
        }
Beispiel #10
0
        protected IAsyncResult BeginSendHelper(IPeerNeighbor neighbor, TimeSpan timeout, Message message, FloodAsyncResult fresult)
        {
            IAsyncResult result = null;
            bool         fatal  = false;

            try
            {
                UtilityExtension.OnMessageSent(neighbor);
                result = neighbor.BeginSend(message, timeout, Fx.ThunkCallback(new AsyncCallback(fresult.OnSendComplete)), message);
                fresult.AddResult(result, neighbor);
                if (result.CompletedSynchronously)
                {
                    neighbor.EndSend(result);
                    UtilityExtension.OnEndSend(neighbor, fresult);
                }
                return(result);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    fatal = true;
                    throw;
                }
                if (null != CloseNeighborIfKnownException(neighborManager, e, neighbor))
                {
                    fresult.MarkEnd(false);
                    throw;
                }

                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                return(null);
            }
            finally
            {
                if ((result == null || result.CompletedSynchronously) && !fatal)
                {
                    message.Close();
                }
            }
        }
Beispiel #11
0
 public void OnEndSend(FloodAsyncResult fresult)
 {
     Interlocked.Decrement(ref pendingSends);
 }