|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Globalization;
|
4 | 4 | using System.Threading;
|
5 |
| -using Renci.SshNet.Abstractions; |
6 | 5 | using Renci.SshNet.Common;
|
7 | 6 | using Renci.SshNet.Messages.Connection;
|
8 | 7 |
|
@@ -65,27 +64,27 @@ public override ChannelTypes ChannelType
|
65 | 64 | /// </summary>
|
66 | 65 | public virtual void Open()
|
67 | 66 | {
|
68 |
| - if (!IsOpen) |
| 67 | + if (IsOpen) |
| 68 | + return; |
| 69 | + |
| 70 | + // Try to open channel several times |
| 71 | + do |
69 | 72 | {
|
70 |
| - // Try to open channel several times |
71 |
| - while (!IsOpen && _failedOpenAttempts < ConnectionInfo.RetryAttempts) |
| 73 | + SendChannelOpenMessage(); |
| 74 | + try |
| 75 | + { |
| 76 | + WaitOnHandle(_channelOpenResponseWaitHandle); |
| 77 | + } |
| 78 | + catch (Exception) |
72 | 79 | {
|
73 |
| - SendChannelOpenMessage(); |
74 |
| - try |
75 |
| - { |
76 |
| - WaitOnHandle(_channelOpenResponseWaitHandle); |
77 |
| - } |
78 |
| - catch (Exception) |
79 |
| - { |
80 |
| - // avoid leaking session semaphore |
81 |
| - ReleaseSemaphore(); |
82 |
| - throw; |
83 |
| - } |
| 80 | + // avoid leaking session semaphore |
| 81 | + ReleaseSemaphore(); |
| 82 | + throw; |
84 | 83 | }
|
| 84 | + } while (!IsOpen && _failedOpenAttempts < ConnectionInfo.RetryAttempts); |
85 | 85 |
|
86 |
| - if (!IsOpen) |
87 |
| - throw new SshException(string.Format(CultureInfo.CurrentCulture, "Failed to open a channel after {0} attempts.", _failedOpenAttempts)); |
88 |
| - } |
| 86 | + if (!IsOpen) |
| 87 | + throw new SshException(string.Format(CultureInfo.CurrentCulture, "Failed to open a channel after {0} attempts.", _failedOpenAttempts)); |
89 | 88 | }
|
90 | 89 |
|
91 | 90 | /// <summary>
|
@@ -386,16 +385,18 @@ protected override void Dispose(bool disposing)
|
386 | 385 |
|
387 | 386 | if (disposing)
|
388 | 387 | {
|
389 |
| - if (_channelOpenResponseWaitHandle != null) |
| 388 | + var channelOpenResponseWaitHandle = _channelOpenResponseWaitHandle; |
| 389 | + if (channelOpenResponseWaitHandle != null) |
390 | 390 | {
|
391 |
| - _channelOpenResponseWaitHandle.Dispose(); |
392 | 391 | _channelOpenResponseWaitHandle = null;
|
| 392 | + channelOpenResponseWaitHandle.Dispose(); |
393 | 393 | }
|
394 | 394 |
|
395 |
| - if (_channelRequestResponse != null) |
| 395 | + var channelRequestResponse = _channelRequestResponse; |
| 396 | + if (channelRequestResponse != null) |
396 | 397 | {
|
397 |
| - _channelRequestResponse.Dispose(); |
398 | 398 | _channelRequestResponse = null;
|
| 399 | + channelRequestResponse.Dispose(); |
399 | 400 | }
|
400 | 401 | }
|
401 | 402 | }
|
|
0 commit comments