Exemple #1
0
        private bool SendMessage(int procedure, int version, IXdrWritable argument, out string errorMessage)
        {
            this.networkWriter.BeginWriting();

            this.rpcMessage.Xid = this.nextXid++;
            this.rpcMessage.Body.CallBody.Procedure = (uint)procedure;
            this.rpcMessage.Body.CallBody.Version   = (uint)version;
            this.rpcMessage.WriteTo(this.xdrWriter);
            argument.WriteTo(this.xdrWriter);

            NetworkWriteResult writeResult = this.networkWriter.EndWriting(this.remoteIpEndPoint);

            if (writeResult.HasError)
            {
                errorMessage =
                    $"Could not send message to {this.remoteIpEndPoint}. Socket error: {writeResult.SocketError}.";
                return(false);
            }

            NetworkReadResult readResult = this.networkReader.BeginReading();

            if (readResult.HasError)
            {
                errorMessage =
                    $"Could not receive reply from {this.remoteIpEndPoint}. Socket error: {readResult.SocketError}.";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
        public void Reply(IXdrWritable result)
        {
            RpcMessage reply = this.GenerateReply(AcceptStatus.Success);

            reply.WriteTo(this.xdrWriter);
            result.WriteTo(this.xdrWriter);
        }
Exemple #3
0
        public void SendCall(int procedure, int version, IXdrWritable argument, IXdrReadable result)
        {
            for (int i = 0; i < 2; i++)
            {
                if (!this.SendMessage(procedure, version, argument, out string errorMessage))
                {
                    if (i == 0)
                    {
                        this.logger?.Error(errorMessage + " Retrying...");
                        this.reestablishConnection?.Invoke();
                        continue;
                    }

                    throw new RpcException(errorMessage);
                }

                if (!this.ReceiveReply(result, out errorMessage))
                {
                    if (i == 0)
                    {
                        this.logger?.Error(errorMessage + " Retrying...");
                        this.reestablishConnection?.Invoke();
                        continue;
                    }

                    throw new RpcException(errorMessage);
                }

                break;
            }
        }