GeezerVison is showing github.com — Modify SocketAbstraction.CanWrite to return false when socket is null. · bazauto/SSH.NET@852efaf
File tree
Expand file treeCollapse file tree
Open diff view settings
test/Renci.SshNet.Shared.Tests
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/Renci.SshNet/Abstractions/SocketAbstraction.cs +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,9 +25,17 @@ public static bool CanRead(Socket socket) |
25 | 25 |
|
26 | 26 | } |
27 | 27 |
|
| 28 | + /// <summary> |
| 29 | + /// Returns a value indicating whether the specified <see cref="Socket"/> can be used |
| 30 | + /// to send data. |
| 31 | + /// </summary> |
| 32 | + /// <param name="socket">The <see cref="Socket"/> to check.</param> |
| 33 | + /// <returns> |
| 34 | + /// <c>true</c> if <paramref name="socket"/> can be written to; otherwise, <c>false</c>. |
| 35 | + /// </returns> |
28 | 36 | public static bool CanWrite(Socket socket) |
29 | 37 | { |
30 | | - if (socket.Connected) |
| 38 | + if (socket != null && socket.Connected) |
31 | 39 | { |
32 | 40 | #if FEATURE_SOCKET_POLL |
33 | 41 | return socket.Poll(-1, SelectMode.SelectWrite); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/Renci.SshNet/Session.cs +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -834,7 +834,7 @@ internal void WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout) |
834 | 834 | /// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the protocol.</exception> |
835 | 835 | internal void SendMessage(Message message) |
836 | 836 | { |
837 | | - if (_socket == null || !_socket.CanWrite()) |
| 837 | + if (!_socket.CanWrite()) |
838 | 838 | throw new SshConnectionException("Client not connected."); |
839 | 839 |
|
840 | 840 | if (_keyExchangeInProgress && !(message is IKeyExchangedAllowed)) |
@@ -893,7 +893,7 @@ internal void SendMessage(Message message) |
893 | 893 | } |
894 | 894 |
|
895 | 895 | // increment the packet sequence number only after we're sure the packet has |
896 | | - // been sent; even though it's only used for the MAC, it need to be incremented |
| 896 | + // been sent; even though it's only used for the MAC, it needs to be incremented |
897 | 897 | // for each package sent. |
898 | 898 | // |
899 | 899 | // the server will use it to verify the data integrity, and as such the order in |
|
Collapse file
Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +using System.Net.Sockets; |
| 2 | +using Renci.SshNet.Abstractions; |
| 3 | +#if SILVERLIGHT |
| 4 | +using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; |
| 5 | +#else |
| 6 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 7 | +#endif |
| 8 | + |
| 9 | +namespace Renci.SshNet.Tests.Abstractions |
| 10 | +{ |
| 11 | + [TestClass] |
| 12 | + public class SocketAbstraction_CanWrite |
| 13 | + { |
| 14 | + [TestMethod] |
| 15 | + public void ShouldReturnFalseWhenSocketIsNull() |
| 16 | + { |
| 17 | + const Socket socket = null; |
| 18 | + |
| 19 | + var actual = SocketAbstraction.CanWrite(socket); |
| 20 | + |
| 21 | + Assert.IsFalse(actual); |
| 22 | + } |
| 23 | + } |
| 24 | +} |
Collapse file
Copy file name to clipboardExpand all lines: test/Renci.SshNet.Shared.Tests/Renci.SshNet.Shared.Tests.projitems +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
12 | 12 | <Compile Include="$(MSBuildThisFileDirectory)Abstractions\CryptoAbstraction_GenerateRandom.cs" /> |
13 | 13 | <Compile Include="$(MSBuildThisFileDirectory)Abstractions\DnsAbstraction_GetHostAddresses.cs" /> |
14 | 14 | <Compile Include="$(MSBuildThisFileDirectory)Abstractions\FileSystemAbstraction_EnumerateFiles.cs" /> |
| 15 | + <Compile Include="$(MSBuildThisFileDirectory)Abstractions\SocketAbstraction_CanWrite.cs" /> |
15 | 16 | <Compile Include="$(MSBuildThisFileDirectory)Abstractions\ThreadAbstraction_ExecuteThread.cs" /> |
16 | 17 | <Compile Include="$(MSBuildThisFileDirectory)ForwardedPortStatusTest_Started.cs" /> |
17 | 18 | <Compile Include="$(MSBuildThisFileDirectory)ForwardedPortStatusTest_Starting.cs" /> |
|