Пример #1
0
        internal void ProResourceResponse(ResourceResponseMessage message, byte[] revData)
        {
            try
            {
                if (message.Size == ResourceResponseMessage.RESOURCE_NOT_EXIST)
                {
                    //资源不存在,发送超时,将接收数据移除
                    Loger.Warn("请求资源不存在");
                }
                else
                {
                    int mtu = message.Size + ResourceResponseMessage.HEAD_SIZE;
                    int rto = (int)(TimeEx.GetTimestamp() - message.Header.Timestamp);
                    TransferParaManager.RecordMtuAndRto(message.SrcEndPoint, mtu, rto, false);

                    ReceiveDataItem receiveDataItem;
                    if (this._revItemDic.TryGetValue(message.Header.Rid, out receiveDataItem))
                    {
                        //发送收到响应数据通知
                        EventWaitHandle eventHandle = AutoEventWaitHandleManager.GetEventWaitHandle(message.ContextId);
                        if (eventHandle != null)
                        {
                            try
                            {
                                receiveDataItem.UpdateLastAccessTimestamp();
                                if (message.Size == ResourceResponseMessage.RESOURCE_NOT_EXIST)
                                {
                                    return;
                                }

                                receiveDataItem.Write(message.Position, revData, ResourceResponseMessage.HEAD_SIZE, message.Size);
                                eventHandle.Set();
                            }
                            catch (ObjectDisposedException)
                            { }
                        }
                    }
                    else
                    {
                        //var tt = TimeEx.GetTimestamp();
                        //Loger.Warn($"未知的资源ID:{message.Header.Rid},[ContextId:{message.ContextId}],[请求响应时长:{tt - message.Header.Timestamp}],[请求数据Position:{message.Position},Size:{message.Size}],[线程:{Thread.CurrentThread.Name}]");
                    }
                }
            }
            catch (Exception ex)
            {
                Loger.Error(ex, "ProResourceResponse发生异常");
            }
        }
Пример #2
0
        internal void ProResourceRequest(ResourceRequestMessage req)
        {
            try
            {
                this._resoucesInfo.UpdateLastAccessTimestamp();
                if (req.Size <= 0)
                {
                    Loger.Warn($"[RID:{req.Header.Rid}]请求数据长度值:{req.Size}无效,忽略");
                    return;
                }

                //Loger.Trace($"收到请求RID:{message.Rid},ContextId:{message.ContextId},Position:{message.Position}-Size:{message.Size}");
                byte[] data   = this.GetRequestData(req);
                var    res    = new ResourceResponseMessage(req, data);
                byte[] buffer = res.GenerateBuffer();
                this._net.Send(buffer, this._resoucesInfo.Policy.RemoteEP);
                //Loger.Trace($"响应请求RID:{req.Rid},ContextId:{req.ContextId},Position:{req.Position}-Size:{req.Size}");
            }
            catch (Exception ex)
            {
                Loger.Error(ex, "处理资源请求异常");
            }
        }