Exemple #1
0
        // 处理 Server 端可能发来的 Close
        // return value:
        //      -1  error
        //      0   不是Close
        //      1   是Close,已经迫使ZChannel处于尚未初始化状态
        // return InitialResult:
        //      在 InitialResult::ResultInfo 中返回诊断信息
        async Task <InitialResult> CheckServerCloseRequest()
        {
            if (this._channel.Connected == false || this._channel.DataAvailable == false)
            {
                return(new InitialResult()); // 没有发现问题
            }
            // 注意调用返回后如果发现出错,调主要主动 Close 和重新分配 TcpClient
            RecvResult result = await ZChannel.SimpleRecvTcpPackage(this._channel._client, -1).ConfigureAwait(false);

            if (result.Value == -1)
            {
                this.CloseConnection();
                return(new InitialResult {
                    Value = -1, ErrorInfo = result.ErrorInfo
                });
            }

            BerTree tree1 = new BerTree();

            // TODO: 这里需要捕获异常,然后把 Package Dump 到日志文件(base64 形态),便于事后分析调试
            tree1.m_RootNode.BuildPartTree(result.Package,
                                           0,
                                           result.Package.Length,
                                           out int nTotalLen);

            if (tree1.GetAPDuRoot().m_uTag != BerTree.z3950_close)
            {
                // 不是Close
                return(new InitialResult {
                    Value = 0
                });
            }

            CLOSE_REQUEST closeStruct = new CLOSE_REQUEST();
            int           nRet        = BerTree.GetInfo_closeRequest(
                tree1.GetAPDuRoot(),
                ref closeStruct,
                out string strError);

            if (nRet == -1)
            {
                this.CloseConnection();
                return(new InitialResult {
                    Value = -1, ErrorInfo = strError
                });
            }

            this.CloseConnection();
            return(new InitialResult {
                Value = 1, ResultInfo = closeStruct.m_strDiagnosticInformation
            });
        }
Exemple #2
0
        // 处理 Server 端可能发来的 Close
        // return value:
        //      -1  error
        //      0   不是Close
        //      1   是Close,已经迫使ZChannel处于尚未初始化状态
        // return InitialResult:
        //      在 InitialResult::ResultInfo 中返回诊断信息
        async Task <InitialResult> CheckServerCloseRequest()
        {
            if (this._channel.Connected == false || this._channel.DataAvailable == false)
            {
                return(new InitialResult()); // 没有发现问题
            }
            RecvResult result = await this._channel.SimpleRecvTcpPackage();

            if (result.Value == -1)
            {
                return new InitialResult {
                           Value = -1, ErrorInfo = result.ErrorInfo
                }
            }
            ;

            BerTree tree1 = new BerTree();

            tree1.m_RootNode.BuildPartTree(result.Package,
                                           0,
                                           result.Package.Length,
                                           out int nTotalLen);

            if (tree1.GetAPDuRoot().m_uTag != BerTree.z3950_close)
            {
                // 不是Close
                return(new InitialResult {
                    Value = 0
                });
            }

            CLOSE_REQUEST closeStruct = new CLOSE_REQUEST();
            int           nRet        = BerTree.GetInfo_closeRequest(
                tree1.GetAPDuRoot(),
                ref closeStruct,
                out string strError);

            if (nRet == -1)
            {
                return new InitialResult {
                           Value = -1, ErrorInfo = strError
                }
            }
            ;

            this.CloseConnection();
            return(new InitialResult {
                Value = 1, ResultInfo = closeStruct.m_strDiagnosticInformation
            });
        }