Renci.SshNet.ShellStream.Read C# (CSharp) Method

Read() public method

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
The sum of and is larger than the buffer length. is null. or is negative. An I/O error occurs. The stream does not support reading. Methods were called after the stream was closed.
public Read ( byte buffer, int offset, int count ) : int
buffer byte An array of bytes. When this method returns, the buffer contains the specified byte array with the values between and ( + - 1) replaced by the bytes read from the current source.
offset int The zero-based byte offset in at which to begin storing the data read from the current stream.
count int The maximum number of bytes to be read from the current stream.
return int
        public override int Read(byte[] buffer, int offset, int count)
        {
            var i = 0;

            lock (_incoming)
            {
                for (; i < count && _incoming.Count > 0; i++)
                {
                    buffer[offset + i] = _incoming.Dequeue();
                }
            }

            return i;
        }

Same methods

ShellStream::Read ( ) : string

Usage Example

示例#1
2
        /// <summary>
        /// Dump the input until we see a particular string in the returning text.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="refreshTimeout">If we see something back from the host, reset the timeout counter</param>
        /// <param name="p"></param>
        /// <param name="failNow">Function that returns true if we should throw out right away</param>
        private void DumpTillFind(ShellStream s, string matchText, 
            Action<string> ongo = null, 
            bool dontdumplineofmatch = true, 
            int secondsTimeout = 60*60, 
            bool refreshTimeout = false,
            Func<bool> failNow = null
            )
        {
            var lb = new LineBuffer(ongo);
            if (dontdumplineofmatch)
            {
                lb.Suppress(matchText);
            }

            var timeout = DateTime.Now + TimeSpan.FromSeconds(secondsTimeout);
            bool gotmatch = false;
            while (timeout > DateTime.Now)
            {
                s.Expect(TimeSpan.FromMilliseconds(100), new ExpectAction(matchText, l => { lb.Add(l); gotmatch = true; }));
                gotmatch = gotmatch || lb.Match(matchText);
                if (gotmatch)
                    break;

                var data = s.Read();
                if (data != null && data.Length > 0 && refreshTimeout)
                {
                    timeout = DateTime.Now + TimeSpan.FromSeconds(secondsTimeout);
                }

                lb.Add(data);

                if (failNow != null && failNow())
                {
                    throw new SSHCommandInterruptedException("Calling routine requested termination of command");
                }
            }
            if (!gotmatch)
            {
                throw new TimeoutException(string.Format("Waiting for '{0}' back from host and it was not seen inside of {1} seconds.", matchText, secondsTimeout));
            }
            lb.DumpRest();
        }
All Usage Examples Of Renci.SshNet.ShellStream::Read