Skip to content

Commit 0d5ecd9

Browse files
authored
Merge branch 'sshnet:develop' into feature_AES_CSP
2 parents 0a9be47 + 2eec748 commit 0d5ecd9

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

src/Renci.SshNet/Connection/ConnectorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected Socket SocketConnect(string host, int port, TimeSpan timeout)
4949
{
5050
SocketAbstraction.Connect(socket, ep, timeout);
5151

52-
const int socketBufferSize = 2 * Session.MaximumSshPacketSize;
52+
const int socketBufferSize = 10 * Session.MaximumSshPacketSize;
5353
socket.SendBufferSize = socketBufferSize;
5454
socket.ReceiveBufferSize = socketBufferSize;
5555
return socket;

src/Renci.SshNet/ServiceFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public INetConfSession CreateNetConfSession(ISession session, int operationTimeo
143143
/// </returns>
144144
public ISftpFileReader CreateSftpFileReader(string fileName, ISftpSession sftpSession, uint bufferSize)
145145
{
146-
const int defaultMaxPendingReads = 3;
146+
const int defaultMaxPendingReads = 10;
147147

148148
// Issue #292: Avoid overlapping SSH_FXP_OPEN and SSH_FXP_LSTAT requests for the same file as this
149149
// causes a performance degradation on Sun SSH
@@ -163,7 +163,7 @@ public ISftpFileReader CreateSftpFileReader(string fileName, ISftpSession sftpSe
163163
{
164164
var fileAttributes = sftpSession.EndLStat(statAsyncResult);
165165
fileSize = fileAttributes.Size;
166-
maxPendingReads = Math.Min(10, (int) Math.Ceiling((double) fileAttributes.Size / chunkSize) + 1);
166+
maxPendingReads = Math.Min(100, (int)Math.Ceiling((double)fileAttributes.Size / chunkSize) + 1);
167167
}
168168
catch (SshException ex)
169169
{

test/Renci.SshNet.IntegrationTests/SftpClientTests.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public void Create_directory_with_contents_and_list_it()
3434
Assert.IsTrue(_sftpClient.Exists(testFilePath));
3535

3636
// Check if ListDirectory works
37-
var files = _sftpClient.ListDirectory(testDirectory);
37+
var expectedFiles = new List<(string FullName, bool IsRegularFile, bool IsDirectory)>()
38+
{
39+
("/home/sshnet/sshnet-test/.", IsRegularFile: false, IsDirectory: true),
40+
("/home/sshnet/sshnet-test/..", IsRegularFile: false, IsDirectory: true),
41+
("/home/sshnet/sshnet-test/test-file.txt", IsRegularFile: true, IsDirectory: false),
42+
};
43+
44+
var actualFiles = _sftpClient.ListDirectory(testDirectory)
45+
.Select(f => (f.FullName, f.IsRegularFile, f.IsDirectory))
46+
.ToList();
3847

3948
_sftpClient.DeleteFile(testFilePath);
4049
_sftpClient.DeleteDirectory(testDirectory);
4150

42-
var builder = new StringBuilder();
43-
foreach (var file in files)
44-
{
45-
builder.AppendLine($"{file.FullName} {file.IsRegularFile} {file.IsDirectory}");
46-
}
47-
48-
Assert.AreEqual(@"/home/sshnet/sshnet-test/. False True
49-
/home/sshnet/sshnet-test/.. False True
50-
/home/sshnet/sshnet-test/test-file.txt True False
51-
", builder.ToString());
51+
CollectionAssert.AreEquivalent(expectedFiles, actualFiles);
5252
}
5353

5454
[TestMethod]
@@ -69,21 +69,24 @@ public async Task Create_directory_with_contents_and_list_it_async()
6969
Assert.IsTrue(_sftpClient.Exists(testFilePath));
7070

7171
// Check if ListDirectory works
72-
var files = _sftpClient.ListDirectoryAsync(testDirectory, CancellationToken.None);
72+
var expectedFiles = new List<(string FullName, bool IsRegularFile, bool IsDirectory)>()
73+
{
74+
("/home/sshnet/sshnet-test/.", IsRegularFile: false, IsDirectory: true),
75+
("/home/sshnet/sshnet-test/..", IsRegularFile: false, IsDirectory: true),
76+
("/home/sshnet/sshnet-test/test-file.txt", IsRegularFile: true, IsDirectory: false),
77+
};
78+
79+
var actualFiles = new List<(string FullName, bool IsRegularFile, bool IsDirectory)>();
7380

74-
var builder = new StringBuilder();
75-
await foreach (var file in files)
81+
await foreach (var file in _sftpClient.ListDirectoryAsync(testDirectory, CancellationToken.None))
7682
{
77-
builder.AppendLine($"{file.FullName} {file.IsRegularFile} {file.IsDirectory}");
83+
actualFiles.Add((file.FullName, file.IsRegularFile, file.IsDirectory));
7884
}
7985

8086
_sftpClient.DeleteFile(testFilePath);
8187
_sftpClient.DeleteDirectory(testDirectory);
8288

83-
Assert.AreEqual(@"/home/sshnet/sshnet-test/. False True
84-
/home/sshnet/sshnet-test/.. False True
85-
/home/sshnet/sshnet-test/test-file.txt True False
86-
", builder.ToString());
89+
CollectionAssert.AreEquivalent(expectedFiles, actualFiles);
8790
}
8891

8992
[TestMethod]

test/Renci.SshNet.Tests/Classes/ServiceFactoryTest_CreateSftpFileReader_EndLStatThrowsSshException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void SetupMocks()
5959
.Setup(p => p.EndLStat(_statAsyncResult))
6060
.Throws(new SshException());
6161
_sftpSessionMock.InSequence(seq)
62-
.Setup(p => p.CreateFileReader(_handle, _sftpSessionMock.Object, _chunkSize, 3, null))
62+
.Setup(p => p.CreateFileReader(_handle, _sftpSessionMock.Object, _chunkSize, 10, null))
6363
.Returns(_sftpFileReaderMock.Object);
6464
}
6565

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Renci.SshNet.Tests.Classes
99
{
1010
[TestClass]
11-
public class ServiceFactoryTest_CreateSftpFileReader_FileSizeIsMoreThanTenTimesGreaterThanChunkSize
11+
public class ServiceFactoryTest_CreateSftpFileReader_FileSizeIsMoreThanMaxPendingReadsTimesChunkSize
1212
{
1313
private ServiceFactory _serviceFactory;
1414
private Mock<ISftpSession> _sftpSessionMock;
@@ -22,18 +22,20 @@ public class ServiceFactoryTest_CreateSftpFileReader_FileSizeIsMoreThanTenTimesG
2222
private SftpFileAttributes _fileAttributes;
2323
private long _fileSize;
2424
private ISftpFileReader _actual;
25+
private int _maxPendingReads;
2526

2627
private void SetupData()
2728
{
2829
var random = new Random();
2930

31+
_maxPendingReads = 100;
3032
_bufferSize = (uint)random.Next(1, int.MaxValue);
3133
_openAsyncResult = new SftpOpenAsyncResult(null, null);
3234
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
3335
_statAsyncResult = new SFtpStatAsyncResult(null, null);
3436
_fileName = random.Next().ToString();
3537
_chunkSize = (uint) random.Next(1000, 5000);
36-
_fileSize = _chunkSize * random.Next(11, 50);
38+
_fileSize = _chunkSize * random.Next(_maxPendingReads + 1, _maxPendingReads * 2);
3739
_fileAttributes = new SftpFileAttributesBuilder().WithSize(_fileSize).Build();
3840
}
3941

@@ -63,7 +65,7 @@ private void SetupMocks()
6365
.Setup(p => p.EndLStat(_statAsyncResult))
6466
.Returns(_fileAttributes);
6567
_sftpSessionMock.InSequence(seq)
66-
.Setup(p => p.CreateFileReader(_handle, _sftpSessionMock.Object, _chunkSize, 10, _fileSize))
68+
.Setup(p => p.CreateFileReader(_handle, _sftpSessionMock.Object, _chunkSize, _maxPendingReads, _fileSize))
6769
.Returns(_sftpFileReaderMock.Object);
6870
}
6971

0 commit comments

Comments
 (0)