diff --git a/Renci.SshClient/Renci.SshClient.sln b/Renci.SshClient/Renci.SshClient.sln
index 57146631..b77f7f56 100644
--- a/Renci.SshClient/Renci.SshClient.sln
+++ b/Renci.SshClient/Renci.SshClient.sln
@@ -22,6 +22,9 @@ Global
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
+ DebugNoTimeout|Any CPU = DebugNoTimeout|Any CPU
+ DebugNoTimeout|Mixed Platforms = DebugNoTimeout|Mixed Platforms
+ DebugNoTimeout|x86 = DebugNoTimeout|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
@@ -32,6 +35,11 @@ Global
{2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.DebugNoTimeout|Any CPU.ActiveCfg = DebugNoTimeout|Any CPU
+ {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.DebugNoTimeout|Any CPU.Build.0 = DebugNoTimeout|Any CPU
+ {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.DebugNoTimeout|Mixed Platforms.ActiveCfg = DebugNoTimeout|Any CPU
+ {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.DebugNoTimeout|Mixed Platforms.Build.0 = DebugNoTimeout|Any CPU
+ {2F5F8C90-0BD1-424F-997C-7BC6280919D1}.DebugNoTimeout|x86.ActiveCfg = DebugNoTimeout|Any CPU
{2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Any CPU.Build.0 = Release|Any CPU
{2F5F8C90-0BD1-424F-997C-7BC6280919D1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
@@ -42,6 +50,11 @@ Global
{23E84A34-A9EC-47D5-BECE-0725053BB17E}.Debug|Mixed Platforms.Build.0 = Debug|x86
{23E84A34-A9EC-47D5-BECE-0725053BB17E}.Debug|x86.ActiveCfg = Debug|x86
{23E84A34-A9EC-47D5-BECE-0725053BB17E}.Debug|x86.Build.0 = Debug|x86
+ {23E84A34-A9EC-47D5-BECE-0725053BB17E}.DebugNoTimeout|Any CPU.ActiveCfg = DebugNoTimeout|x86
+ {23E84A34-A9EC-47D5-BECE-0725053BB17E}.DebugNoTimeout|Mixed Platforms.ActiveCfg = DebugNoTimeout|x86
+ {23E84A34-A9EC-47D5-BECE-0725053BB17E}.DebugNoTimeout|Mixed Platforms.Build.0 = DebugNoTimeout|x86
+ {23E84A34-A9EC-47D5-BECE-0725053BB17E}.DebugNoTimeout|x86.ActiveCfg = DebugNoTimeout|x86
+ {23E84A34-A9EC-47D5-BECE-0725053BB17E}.DebugNoTimeout|x86.Build.0 = DebugNoTimeout|x86
{23E84A34-A9EC-47D5-BECE-0725053BB17E}.Release|Any CPU.ActiveCfg = Release|x86
{23E84A34-A9EC-47D5-BECE-0725053BB17E}.Release|Mixed Platforms.ActiveCfg = Release|x86
{23E84A34-A9EC-47D5-BECE-0725053BB17E}.Release|Mixed Platforms.Build.0 = Release|x86
diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelAsyncResult.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelAsyncResult.cs
index e5f7bfad..07d9f32c 100644
--- a/Renci.SshClient/Renci.SshClient/Channels/ChannelAsyncResult.cs
+++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelAsyncResult.cs
@@ -11,8 +11,18 @@ namespace Renci.SshClient.Channels
/// The channel.
internal ChannelExec Channel { get; private set; }
+ ///
+ /// Gets or sets the bytes received. If SFTP only file bytes are counted.
+ ///
+ /// Total bytes received.
public int BytesReceived { get; set; }
+ ///
+ /// Gets or sets the bytes sent by SFTP.
+ ///
+ /// Total bytes sent.
+ public int BytesSent { get; set; }
+
#region IAsyncResult Members
public object AsyncState { get; internal set; }
diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelExec.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelExec.cs
index 3a0c6c46..a0f33037 100644
--- a/Renci.SshClient/Renci.SshClient/Channels/ChannelExec.cs
+++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelExec.cs
@@ -111,6 +111,11 @@ namespace Renci.SshClient.Channels
{
this._channelData.Write(data.GetSshBytes().ToArray(), 0, data.Length);
}
+
+ if (this._asyncResult != null)
+ {
+ this._asyncResult.BytesReceived += data.Length;
+ }
}
protected override void OnChannelExtendedData(string data, uint dataTypeCode)
diff --git a/Renci.SshClient/Renci.SshClient/Channels/ChannelSftp.cs b/Renci.SshClient/Renci.SshClient/Channels/ChannelSftp.cs
index fab31ec6..5faab7b8 100644
--- a/Renci.SshClient/Renci.SshClient/Channels/ChannelSftp.cs
+++ b/Renci.SshClient/Renci.SshClient/Channels/ChannelSftp.cs
@@ -28,6 +28,8 @@ namespace Renci.SshClient.Channels
private StringBuilder _packetData;
+ private ChannelAsyncResult _asyncResult;
+
public override ChannelTypes ChannelType
{
get { return ChannelTypes.Session; }
@@ -229,7 +231,6 @@ namespace Renci.SshClient.Channels
this._packetData.Append(data);
}
-
if (this._packetData.Length < this._packetData.MaxCapacity)
{
// Wait for more packet data
@@ -350,6 +351,10 @@ namespace Renci.SshClient.Channels
}
else if (dataMessage != null)
{
+ if (this._asyncResult != null)
+ {
+ this._asyncResult.BytesReceived += dataMessage.Data.Length;
+ }
return dataMessage.Data;
}
else
@@ -370,6 +375,12 @@ namespace Renci.SshClient.Channels
var message = this.ReceiveMessage();
this.EnsureStatusCode(message, StatusCodes.Ok);
+
+ if (this._asyncResult != null)
+ {
+ this._asyncResult.BytesSent += data.Length;
+ }
+
}
private void RemoveRemoteFile(string fileName)
diff --git a/Renci.SshClient/Renci.SshClient/Renci.SshClient.csproj b/Renci.SshClient/Renci.SshClient/Renci.SshClient.csproj
index 72e90aeb..12c38092 100644
--- a/Renci.SshClient/Renci.SshClient/Renci.SshClient.csproj
+++ b/Renci.SshClient/Renci.SshClient/Renci.SshClient.csproj
@@ -34,6 +34,22 @@
prompt
4
+
+ true
+ bin\DebugNoTimeout\
+ TRACE;DEBUG;NOTIMEOUT
+ full
+ AnyCPU
+ bin\Debug\Renci.SshClient.dll.CodeAnalysisLog.xml
+ true
+ GlobalSuppressions.cs
+ prompt
+ MinimumRecommendedRules.ruleset
+ ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets
+ false
+ ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules
+ false
+
diff --git a/Renci.SshClient/Renci.SshClient/Session.cs b/Renci.SshClient/Renci.SshClient/Session.cs
index 2558c177..7873dbe1 100644
--- a/Renci.SshClient/Renci.SshClient/Session.cs
+++ b/Renci.SshClient/Renci.SshClient/Session.cs
@@ -71,10 +71,11 @@ namespace Renci.SshClient
private IDictionary _openChannels = new Dictionary();
- private EventWaitHandle _disconnectWaitHandle = new AutoResetEvent(false);
-
private EventWaitHandle _exceptionWaitHandle = new AutoResetEvent(false);
+ ///
+ /// Exception that need to be thrown by waiting thread
+ ///
private Exception _exceptionToThrow;
///
@@ -218,26 +219,31 @@ namespace Renci.SshClient
{
var waitHandles = new WaitHandle[]
{
- this._disconnectWaitHandle,
this._exceptionWaitHandle,
waitHandle,
};
- EventWaitHandle.WaitAny(waitHandles);
+ // TODO: Signal waitandle to stop waiting, in case someone waiting for it.
+ // TODO: throw exception in case of _disconnectWaitHandle or _exceptionWaitHandle was signalled
- //var index = EventWaitHandle.WaitAny(waitHandles, this._waitTimeout);
+ var index = 0;
+#if NOTIMEOUT
+ index = EventWaitHandle.WaitAny(waitHandles);
+#else
+ index = EventWaitHandle.WaitAny(waitHandles, this._waitTimeout);
+#endif
+ if (this._exceptionToThrow != null)
+ {
+ var exception = this._exceptionToThrow;
+ this._exceptionToThrow = null;
+ throw exception;
+ }
+ else if (index > waitHandles.Length)
+ {
+ // TODO: Issue timeout disconnect message if approapriate
+ throw new TimeoutException();
+ }
- //if (this._exceptionToThrow != null)
- //{
- // var exception = this._exceptionToThrow;
- // this._exceptionToThrow = null;
- // throw exception;
- //}
- //else if (index > waitHandles.Length)
- //{
- // // TODO: Issue timeout disconnect message if approapriate
- // throw new TimeoutException();
- //}
}
protected abstract Message ReceiveMessage();