Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private void Receiving()
        {
            try
            {
                while (!this.stopReceiving)
                {
                    NetworkReadResult readResult = this.reader.BeginReading();
                    if (readResult.HasError)
                    {
                        this.logger?.Trace(
                            $"Could not read data from {this.caller}. " +
                            $"Socket error: {readResult.SocketError}.");
                        this.IsFinished = true;
                        return;
                    }

                    if (readResult.IsDisconnected)
                    {
                        this.logger?.Trace($"{this.caller} disconnected.");
                        this.IsFinished = true;
                        return;
                    }

                    this.writer.BeginWriting();
                    this.receivedCall.HandleCall(this.caller);
                    this.reader.EndReading();

                    NetworkWriteResult writeResult = this.writer.EndWriting(this.remoteIpEndPoint);
                    if (writeResult.HasError)
                    {
                        this.logger?.Trace(
                            $"Could not write data to {this.caller}. " +
                            $"Socket error: {writeResult.SocketError}.");
                        this.IsFinished = true;
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                this.logger?.Error($"Unexpected exception in connection to {this.caller}: {e}");
            }
        }