示例#1
0
        /// <summary>
        /// 通信完成消息处理方法
        /// </summary>
        /// <param name="session"></param>
        /// <param name="notify"></param>
        private void OnNotifyProc(SessionProviderContext session, TcpSessionNotify notify)
        {
            if (SynchronizationContext.IsNull())
            {
                NotifyProc(null);
            }
            else
            {
                SynchronizationContext.Send(NotifyProc, null);
            }

            void NotifyProc(object @object)
            {
                try
                {
                    switch (notify)
                    {
                    case TcpSessionNotify.OnConnected:
                        //先分配好工作类型,等待工作指令分配新的工作类型
                        session.AppTokens = new object[SysConstants.INDEX_COUNT]
                        {
                            ConnectionWorkType.NONE,    //未经验证的状态
                            null
                        };
                        break;

                    case TcpSessionNotify.OnSend:
                        //耗时操作会导致性能严重降低
                        this.OnTransmitHandlerEvent?.Invoke(session);
                        break;

                    case TcpSessionNotify.OnDataReceiveing:
                        //耗时操作会导致性能严重降低
                        this.OnReceiveHandlerEvent?.Invoke(session);
                        break;

                    case TcpSessionNotify.OnDataReceived:
                        this.OnReceiveComplete(session);
                        break;

                    case TcpSessionNotify.OnClosed:
                        this.OnClosed(session);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteErrorByCurrentMethod(ex);
                }
            }
        }