Пример #1
0
 /// <summary>
 /// 分配返回数据
 /// </summary>
 private void Process()
 {
     //取出请求ID
     byte[] reqID = new byte[8];
     while (!block.IsEmpty)
     {
         Console.WriteLine("客户端适配器数据处理线程运行中");
         object rsp;
         if (block.TryDequeue(out rsp))
         {
             Interlocked.Decrement(ref ReqCount);
             var buf = rsp as IByteBuffer;
             if (buf != null)
             {
                 long       id      = buf.ReadLong();
                 RequestNet request = null;
                 if (dicReslut.TryRemove(id, out request))
                 {
                     byte[] data = new byte[buf.ReadableBytes];
                     buf.ReadBytes(data);
                     request.Result = data;
                     request.ResetEvent.Set();
                 }
                 buf.Release();
             }
         }
     }
     Console.WriteLine("客户端适配器数据处理线程退出");
 }
Пример #2
0
        /// <summary>
        /// 投递数据
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        private RequestNet WaitSend(string clientFlage, byte[] req)
        {
            byte[]     buf     = new byte[req.Length + 8];
            RequestNet request = new RequestNet();

            request.ID = Interlocked.Increment(ref RequestID);
            using (var mem = new MemoryStream(buf))
            {
                mem.Write(BitConverter.GetBytes(request.ID), 0, 8);
                mem.Write(req, 0, req.Length);
            }
            req = null;//及时释放
            dicReslut[request.ID] = request;
            NettyClientManager.Singleton.Submit(clientFlage, buf);
            return(request);
        }