Skip to content

Commit b1cef3f

Browse files
committed
Lint fixes
1 parent 7027340 commit b1cef3f

File tree

6 files changed

+83
-57
lines changed

6 files changed

+83
-57
lines changed

src/Renci.SshNet/Common/ChannelInputStream.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace Renci.SshNet.Common
2-
{
3-
using System;
4-
using System.IO;
5-
using Renci.SshNet.Channels;
1+
using System;
2+
using System.IO;
3+
using Renci.SshNet.Channels;
64

5+
namespace Renci.SshNet.Common
6+
{
77
/// <summary>
88
/// ChannelInputStream is a one direction stream intended for channel data.
99
/// </summary>
@@ -33,7 +33,7 @@ public class ChannelInputStream : Stream
3333
/// <summary>
3434
/// Channel to send data to.
3535
/// </summary>
36-
private IChannelSession _channel;
36+
private readonly IChannelSession _channel;
3737

3838
/// <summary>
3939
/// Total bytes passed through the stream.
@@ -126,15 +126,29 @@ public override int Read(byte[] buffer, int offset, int count)
126126
public override void Write(byte[] buffer, int offset, int count)
127127
{
128128
if (buffer == null)
129+
{
129130
throw new ArgumentNullException("buffer");
131+
}
132+
130133
if (offset + count > buffer.Length)
134+
{
131135
throw new ArgumentException("The sum of offset and count is greater than the buffer length.");
136+
}
137+
132138
if (offset < 0 || count < 0)
139+
{
133140
throw new ArgumentOutOfRangeException("offset", "offset or count is negative.");
141+
}
142+
134143
if (_isDisposed)
144+
{
135145
throw CreateObjectDisposedException();
146+
}
147+
136148
if (count == 0)
149+
{
137150
return;
151+
}
138152

139153
_channel.SendData(buffer, offset, count);
140154

src/Renci.SshNet/Common/LinkedListQueue.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace Renci.SshNet.Common
2-
{
3-
using System;
4-
using System.Threading;
1+
using System;
2+
using System.Threading;
53

4+
namespace Renci.SshNet.Common
5+
{
66
/// <summary>
77
/// Fast concurrent generic linked list queue.
88
/// </summary>
@@ -55,22 +55,22 @@ public void Add(T item)
5555
lock (_lock)
5656
{
5757
if (_isAddingCompleted)
58+
{
5859
return;
60+
}
5961

60-
var entry = new Entry<T>();
61-
entry.Item = item;
62+
var entry = new Entry<T>()
63+
{
64+
Item = item
65+
};
6266

6367
if (_last != null)
6468
{
6569
_last.Next = entry;
6670
}
6771

6872
_last = entry;
69-
70-
if (_first == null)
71-
{
72-
_first = entry;
73-
}
73+
_first ??= entry;
7474

7575
Monitor.PulseAll(_lock);
7676
}
@@ -100,16 +100,18 @@ public bool TryTake(out T item, bool wait)
100100
{
101101
if (_first == null && !wait)
102102
{
103-
item = default(T);
103+
item = default;
104104
return false;
105105
}
106106

107107
while (_first == null && !_isAddingCompleted)
108-
Monitor.Wait(_lock);
108+
{
109+
_ = Monitor.Wait(_lock);
110+
}
109111

110112
if (_first == null && _isAddingCompleted)
111113
{
112-
item = default(T);
114+
item = default;
113115
return false;
114116
}
115117

src/Renci.SshNet/Common/Pipe.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace Renci.SshNet.Common
2-
{
3-
using System;
1+
using System;
42

3+
namespace Renci.SshNet.Common
4+
{
55
/// <summary>
66
/// A generic pipe to pass through data.
77
/// </summary>

src/Renci.SshNet/Common/PipeInputStream.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
namespace Renci.SshNet.Common
2-
{
3-
using System;
4-
using System.IO;
1+
using System;
2+
using System.IO;
53

4+
namespace Renci.SshNet.Common
5+
{
66
internal class PipeInputStream : Stream
77
{
8-
private LinkedListQueue<byte[]> _queue;
8+
private readonly LinkedListQueue<byte[]> _queue;
99
private byte[] _current;
1010
private int _currentPosition;
1111
private bool _isDisposed;
@@ -32,13 +32,24 @@ public override void SetLength(long value)
3232
public override int Read(byte[] buffer, int offset, int count)
3333
{
3434
if (buffer == null)
35+
{
3536
throw new ArgumentNullException("buffer");
37+
}
38+
3639
if (offset + count > buffer.Length)
40+
{
3741
throw new ArgumentException("The sum of offset and count is greater than the buffer length.");
42+
}
43+
3844
if (offset < 0 || count < 0)
45+
{
3946
throw new ArgumentOutOfRangeException("offset", "offset or count is negative.");
47+
}
48+
4049
if (_isDisposed)
50+
{
4151
throw CreateObjectDisposedException();
52+
}
4253

4354
var bytesRead = 0;
4455

@@ -57,7 +68,9 @@ public override int Read(byte[] buffer, int offset, int count)
5768

5869
var toRead = _current.Length - _currentPosition;
5970
if (toRead > count - bytesRead)
71+
{
6072
toRead = count - bytesRead;
73+
}
6174

6275
Buffer.BlockCopy(_current, _currentPosition, buffer, offset + bytesRead, toRead);
6376

src/Renci.SshNet/Common/PipeOutputStream.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
namespace Renci.SshNet.Common
2-
{
3-
using System;
4-
using System.IO;
1+
using System;
2+
using System.IO;
53

4+
namespace Renci.SshNet.Common
5+
{
66
internal class PipeOutputStream : Stream
77
{
8-
private LinkedListQueue<byte[]> _queue;
8+
private readonly LinkedListQueue<byte[]> _queue;
99
private bool _isDisposed;
1010

1111
public PipeOutputStream(LinkedListQueue<byte[]> queue)
@@ -35,15 +35,26 @@ public override int Read(byte[] buffer, int offset, int count)
3535
public override void Write(byte[] buffer, int offset, int count)
3636
{
3737
if (buffer == null)
38+
{
3839
throw new ArgumentNullException("buffer");
40+
}
41+
3942
if (offset + count > buffer.Length)
43+
{
4044
throw new ArgumentException("The sum of offset and count is greater than the buffer length.");
45+
}
46+
4147
if (offset < 0 || count < 0)
48+
{
4249
throw new ArgumentOutOfRangeException("offset", "offset or count is negative.");
50+
}
51+
4352
if (_isDisposed || _queue.IsAddingCompleted)
53+
{
4454
throw CreateObjectDisposedException();
55+
}
4556

46-
byte[] tmp = new byte[count];
57+
var tmp = new byte[count];
4758
Buffer.BlockCopy(buffer, offset, tmp, 0, count);
4859
_queue.Add(tmp);
4960
}
@@ -90,7 +101,9 @@ public override void Close()
90101
#endif
91102
{
92103
if (!_queue.IsAddingCompleted)
104+
{
93105
_queue.CompleteAdding();
106+
}
94107
}
95108

96109
protected override void Dispose(bool disposing)
@@ -100,7 +113,9 @@ protected override void Dispose(bool disposing)
100113
if (!_isDisposed)
101114
{
102115
if (!_queue.IsAddingCompleted)
116+
{
103117
_queue.CompleteAdding();
118+
}
104119
_isDisposed = true;
105120
}
106121
}

src/Renci.SshNet/SshCommand.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -245,22 +245,10 @@ public IAsyncResult BeginExecute(AsyncCallback callback, object state)
245245
throw new ArgumentException("CommandText property is empty.");
246246
}
247247

248-
var outputStream = OutputStream;
249-
if (outputStream is not null)
250-
{
251-
_stdoutPipe.Dispose();
252-
}
253-
254-
var extendedOutputStream = ExtendedOutputStream;
255-
if (extendedOutputStream is not null)
256-
{
257-
_stderrPipe.Dispose();
258-
}
248+
_stdoutPipe?.Dispose();
249+
_stderrPipe?.Dispose();
259250

260-
if (InputStream != null)
261-
{
262-
InputStream.Dispose();
263-
}
251+
InputStream?.Dispose();
264252

265253
// Initialize output pipes
266254
_stdoutPipe = new Pipe();
@@ -459,10 +447,7 @@ private void Channel_RequestReceived(object sender, ChannelRequestEventArgs e)
459447

460448
private void Channel_ExtendedDataReceived(object sender, ChannelExtendedDataEventArgs e)
461449
{
462-
if (_stderrPipe != null)
463-
{
464-
_stderrPipe.OutputStream.Write(e.Data, 0, e.Data.Length);
465-
}
450+
_stderrPipe?.OutputStream.Write(e.Data, 0, e.Data.Length);
466451

467452
if (e.DataTypeCode == 1)
468453
{
@@ -472,10 +457,7 @@ private void Channel_ExtendedDataReceived(object sender, ChannelExtendedDataEven
472457

473458
private void Channel_DataReceived(object sender, ChannelDataEventArgs e)
474459
{
475-
if (_stdoutPipe != null)
476-
{
477-
_stdoutPipe.OutputStream.Write(e.Data, 0, e.Data.Length);
478-
}
460+
_stdoutPipe?.OutputStream.Write(e.Data, 0, e.Data.Length);
479461

480462
if (_asyncResult != null)
481463
{

0 commit comments

Comments
 (0)