/// <summary> /// 获取数据包 /// </summary> /// <param name="buffer">接收到的历史数据</param> /// <returns></returns> private IEnumerable <FastPacket> GetPacketsFromBuffer(ReceiveBuffer buffer) { FastPacket packet; while ((packet = FastPacket.From(buffer)) != null) { yield return(packet); } }
/// <summary> /// 当接收到远程端的数据时,将触发此方法 /// </summary> /// <param name="buffer">接收到的历史数据</param> protected override void OnReceive(ReceiveBuffer buffer) { while (true) { var packet = FastPacket.From(buffer); if (packet == null) { break; } // 新线程处理业务内容 Task.Factory.StartNew(() => this.OnRecvPacket(packet)); } }
/// <summary> /// 当接收到会话对象的数据时,将触发此方法 /// </summary> /// <param name="session">会话对象</param> /// <param name="buffer">接收到的历史数据</param> /// <returns></returns> protected override void OnReceive(FastSession session, ReceiveBuffer buffer) { while (true) { FastPacket packet = null; try { packet = FastPacket.From(buffer); } catch (Exception ex) { buffer.Clear(); this.OnException(session, ex); } if (packet == null) { break; } // 新线程处理业务内容 Task.Factory.StartNew(() => this.OnRecvPacket(session, packet)); } }