コード例 #1
0
        /// <summary>
        /// Callback de notificação de pacote recebido.
        /// Localiza o RPC a partir do número da mensagem e transmite o pacote
        /// para o RPC.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="packet"></param>
        protected void OnPacketReceived(object sender, InternalPacket packet)
        {
            int msgId = packet.MsgId;

            IRpc rpc = GetRpc(msgId);

            if (rpc != null)
            {
                rpc.OnPacketReceived(GetSession(), packet);
                return;
            }

            MyDebug.LogDebug("Channel.OnPacketReceived: msgid {0} desconhecido ou inesperado", packet.MsgId);
        }
コード例 #2
0
        /// <summary>
        /// Callback de notificação de recebimento de pacote.
        /// </summary>
        /// <param name="session">Sessão de origem do pacote.</param>
        /// <param name="packet">Pacote de dados.</param>
        void IRpc.OnPacketReceived(IPacketSession session, InternalPacket packet)
        {
            if (m_State != StreamState.Open)
            {
                Debug.WriteLine(String.Format("{0}.OnPacketReceived: Unexpected packet: {1}", nameof(RpcTunnel <TSend, TReceive>), packet));
                return;
            }

            var options = packet.Options;

            if (options == P_OPTIONS_RPC_ERROR)
            {
                m_State = StreamState.Error;

                var rpcException = PacketHandler.GetException(packet);
                m_ReturnValueTcs.TrySetException(rpcException);
                m_RpcStreamReader.OnError(rpcException);

                Finish();
                return;
            }

            if (options == P_OPTIONS_RPC_CLOSE)
            {
                m_State = StreamState.Closed;

                Exception ex = new EndOfStreamException();
                m_ReturnValueTcs.TrySetException(ex);
                m_RpcStreamReader.OnDataClosed();

                Finish();
                return;
            }

            if (options == P_OPTIONS_RPC_RETURN)
            {
                m_State = StreamState.Closed;

                var data = GetData(packet);
                m_ReturnValueTcs.TrySetResult(data);
                m_RpcStreamReader.OnDataClosed();

                Finish();
                return;
            }

            if (options == P_OPTIONS_STREAM_DATA)
            {
                var data = GetData(packet);
                m_RpcStreamReader.OnDataReceived(data);
                return;
            }

            if (options == P_OPTIONS_STREAM_CLOSE)
            {
                m_RpcStreamReader.OnDataClosed();
                return;
            }

            // Unknow or unexpected value -> discard packet

            MyDebug.LogDebug("{0}.OnPacketReceived: Unknow or unexpected packet: {1}", nameof(RpcTunnel <TSend, TReceive>), packet);
        }