From 13b4f8bcd804fb1f2fdbfb9dc82fe4e0fea65450 Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 24 Apr 2016 17:41:43 +0200 Subject: [PATCH] Added ReadByte and SendByte convenience methods. --- .../Abstractions/SocketAbstraction.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index 8ffe3b49..c76a3b04 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -137,6 +137,37 @@ namespace Renci.SshNet.Abstractions #endif } + /// + /// Reads a byte from the specified . + /// + /// The to read from. + /// Specifies the amount of time after which the call will time out. + /// + /// The byte read, or -1 if the socket was closed. + /// + /// The read operation timed out. + /// The read failed. + public static int ReadByte(Socket socket, TimeSpan timeout) + { + var buffer = new byte[1]; + if (Read(socket, buffer, 0, 1, timeout) == 0) + return -1; + + return buffer[0]; + } + + /// + /// Sends a byte using the specified . + /// + /// The to write to. + /// The value to send. + /// The write failed. + public static void SendByte(Socket socket, byte value) + { + var buffer = new[] {value}; + Send(socket, buffer, 0, 1); + } + /// /// Receives data from a bound into a receive buffer. ///