Esempio n. 1
0
        private void ProTransferCompleted(TransferCompletedMessage message)
        {
            var            rid = message.Header.Rid;
            string         transferCompletedMessageCacheKey       = CacheKeyGenerator.GenerateTransferCompletedMessageCacheKey(message);
            const int      revTransferCompletedMessageCacheExpire = 60000;
            TransferSender sender;

            if (this._senderDic.TryGetValue(rid, out sender))
            {
                sender.ProResourceCompleted();
                MemoryCacheEx.Set(transferCompletedMessageCacheKey, rid, revTransferCompletedMessageCacheExpire);
                this.SendTransferCompletedAckMessage(message);
            }
            else
            {
                if (MemoryCacheEx.Get(transferCompletedMessageCacheKey) == null)
                {
                    //Loger.Warn($"未知的资源ID:{rid}");
                }
                else
                {
                    MemoryCacheEx.Set(transferCompletedMessageCacheKey, rid, revTransferCompletedMessageCacheExpire);
                    this.SendTransferCompletedAckMessage(message);
                }
            }
        }
Esempio n. 2
0
 private void SendTransferCompletedAckMessage(TransferCompletedMessage message)
 {
     try
     {
         var    transferCompletedAckMessage = new TransferCompletedAckMessage(message);
         byte[] buffer = transferCompletedAckMessage.GenerateBuffer();
         this._net.Send(buffer, message.SrcEndPoint);
     }
     catch (Exception ex)
     {
         Loger.Error(ex, "发送TransferCompletedAckMessage异常");
     }
 }
Esempio n. 3
0
        private void SendTransferCompletedMessage(SendDataNotifyMessage notifyMessage)
        {
            var transferCompletedMessage = new TransferCompletedMessage(notifyMessage);
            var buffer          = transferCompletedMessage.GenerateBuffer();
            var id              = CacheKeyGenerator.GenerateWaitTransferCompletedAckMessageEventWaitHandleId(notifyMessage.Header.Rid);
            var eventHandleInfo = AutoEventWaitHandleManager.CreateEventWaitHandle(id);

            try
            {
                long beginTs = TimeEx.GetTimestamp();
                long endTs   = beginTs;

                while (!notifyMessage.IsTimeout(beginTs, endTs))
                {
                    try
                    {
                        int rto = TransferParaManager.GetRto(notifyMessage.SrcEndPoint);
                        this._net.Send(buffer, notifyMessage.SrcEndPoint);
                        if (eventHandleInfo.EventWaitHandle.WaitOne(rto))
                        {
                            break;
                        }
                        else
                        {
                            TransferParaManager.AdjustUpRto(notifyMessage.SrcEndPoint);
                        }
                    }
                    catch (SendDataException)
                    {
                        break;
                    }
                    catch (Exception ex)
                    {
                        Loger.Error(ex, "发送传输完成消息异常");
                    }

                    endTs = TimeEx.GetTimestamp();
                }
            }
            finally
            {
                AutoEventWaitHandleManager.RemoveEventWaitHandle(id);
                eventHandleInfo.EventWaitHandle.Dispose();
            }

            //注:如果一直都没有收到确认消息,则超时线程处理
        }
Esempio n. 4
0
 /// <summary>
 /// 创建
 /// </summary>
 /// <param name="transferCompletedMessage"></param>
 public TransferCompletedAckMessage(TransferCompletedMessage transferCompletedMessage)
     : base(new CommonHeader(TransferCommands.TransferCompletedAck, transferCompletedMessage.Header.Timestamp, transferCompletedMessage.Header.Rid))
 {
 }
Esempio n. 5
0
 public static string GenerateTransferCompletedMessageCacheKey(TransferCompletedMessage message)
 {
     return($"UDP_TransferCompletedMessageCacheKey_{message.Header.Rid}");
 }