コード例 #1
0
ファイル: Fragmentation.cs プロジェクト: weimingtom/miniclr
        private void HandleFragmentationMessageTerminated(object sender, FragmentationMessageTerminatedEventArgs args)
        {
            if (sender is InboundFragmentationMessage)
            {
                if ((args.FinalState != FragmentationMessageState.Final) || (args.FinalStatus != Status.Success))
                {
                    // do nothing.
                    return;
                }

                InboundFragmentationMessage inMsg = sender as InboundFragmentationMessage;

                Frame receivedMessage = inMsg.RetrieveData();

                if (receivedMessage != null)
                {
                    DataIndicationHandler handler = _dataIndicationHandler;
                    if (handler != null)
                    {
                        handler.Invoke(this, inMsg.Source, inMsg.Destination, receivedMessage);
                    }
                    else
                    {
                        Frame.Release(ref receivedMessage);
                    }
                }
            }
            else if (sender is OutboundFragmentationMessage)
            {
                OutboundFragmentationMessage outMsg, newOutMsg;
                lock (_lock)
                {
                    outMsg = sender as OutboundFragmentationMessage;
                    ushort previousDestination = outMsg.Destination;
                    _transmissionCharacteristicStorage.UpdateTransmissionCharacteristic(outMsg.Destination, outMsg.TimeoutForResending,
                                                                                        outMsg.MaxFragmentsBeforeAck);
                    // remove active message from repository
                    _outboundAssociations.RemoveFragmentationMessage(outMsg);
                    // try to start new message (if possible)
                    DataRequestItem newItem;
                    newOutMsg = null;
                    if (_dataRequestQueueSet.Dequeue(previousDestination, out newItem))
                    {
                        newOutMsg = CreateNewOutboundMessage(newItem);
                    }
                }

                // after releasing the lock, call method in FragmentationMessage class.
                outMsg.NotifySender(args.FinalState, args.FinalStatus);
                outMsg.Dispose();

                if (newOutMsg != null)
                {
                    newOutMsg.SendNextDataFragment(true);
                }
            }
        }