GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • src/Renci.SshNet
    • Abstractions
      • SocketAbstraction.cs
    • Session.cs
  • test/Renci.SshNet.Shared.Tests
    • Abstractions
      • SocketAbstraction_CanWrite.cs
    • Renci.SshNet.Shared.Tests.projitems
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Renci.SshNet/Abstractions/SocketAbstraction.cs‎

Copy file name to clipboardExpand all lines: src/Renci.SshNet/Abstractions/SocketAbstraction.cs
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ public static bool CanRead(Socket socket)
2525

2626
}
2727

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>
2836
public static bool CanWrite(Socket socket)
2937
{
30-
if (socket.Connected)
38+
if (socket != null && socket.Connected)
3139
{
3240
#if FEATURE_SOCKET_POLL
3341
return socket.Poll(-1, SelectMode.SelectWrite);
Collapse file

‎src/Renci.SshNet/Session.cs‎

Copy file name to clipboardExpand all lines: src/Renci.SshNet/Session.cs
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ internal void WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
834834
/// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the protocol.</exception>
835835
internal void SendMessage(Message message)
836836
{
837-
if (_socket == null || !_socket.CanWrite())
837+
if (!_socket.CanWrite())
838838
throw new SshConnectionException("Client not connected.");
839839

840840
if (_keyExchangeInProgress && !(message is IKeyExchangedAllowed))
@@ -893,7 +893,7 @@ internal void SendMessage(Message message)
893893
}
894894

895895
// 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
897897
// for each package sent.
898898
//
899899
// the server will use it to verify the data integrity, and as such the order in
Collapse file

‎test/Renci.SshNet.Shared.Tests/Abstractions/SocketAbstraction_CanWrite.cs‎

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

‎test/Renci.SshNet.Shared.Tests/Renci.SshNet.Shared.Tests.projitems‎

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 numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Compile Include="$(MSBuildThisFileDirectory)Abstractions\CryptoAbstraction_GenerateRandom.cs" />
1313
<Compile Include="$(MSBuildThisFileDirectory)Abstractions\DnsAbstraction_GetHostAddresses.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)Abstractions\FileSystemAbstraction_EnumerateFiles.cs" />
15+
<Compile Include="$(MSBuildThisFileDirectory)Abstractions\SocketAbstraction_CanWrite.cs" />
1516
<Compile Include="$(MSBuildThisFileDirectory)Abstractions\ThreadAbstraction_ExecuteThread.cs" />
1617
<Compile Include="$(MSBuildThisFileDirectory)ForwardedPortStatusTest_Started.cs" />
1718
<Compile Include="$(MSBuildThisFileDirectory)ForwardedPortStatusTest_Starting.cs" />

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.