Fix remote port forwarding socket read functionality

This commit is contained in:
olegkap_cp
2010-11-11 19:36:00 +00:00
parent 6cd224a0e4
commit 2c435ec12c
2 changed files with 43 additions and 8 deletions
@@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Renci.SshClient.Common;
using Renci.SshClient.Messages.Connection;
@@ -67,18 +68,41 @@ namespace Renci.SshClient.Channels
}
// Start reading data from the port and send to channel
using (var ns = new NetworkStream(this._socket))
while (this._socket.Connected || this.IsConnected)
{
do
try
{
var read = ns.Read(buffer, 0, buffer.Length);
this.SendMessage(new ChannelDataMessage
var read = this._socket.Receive(buffer);
if (read > 0)
{
LocalChannelNumber = this.RemoteChannelNumber,
Data = buffer.Take(read).GetSshString(),
});
this.SendMessage(new ChannelDataMessage
{
LocalChannelNumber = this.RemoteChannelNumber,
Data = buffer.Take(read).GetSshString(),
});
}
else
{
// Zero bytes received when remote host shuts down the connection
break;
}
}
catch (SocketException exp)
{
if (exp.SocketErrorCode == SocketError.WouldBlock ||
exp.SocketErrorCode == SocketError.IOPending ||
exp.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
{
// socket buffer is probably empty, wait and try again
Thread.Sleep(30);
}
else if (exp.SocketErrorCode == SocketError.ConnectionAborted)
{
break;
}
else
throw; // throw any other error
}
while (ns.DataAvailable);
}
this.SendMessage(new ChannelEofMessage
@@ -11,6 +11,17 @@ namespace Renci.SshClient
public ConnectionInfo ConnectionInfo { get; private set; }
public bool IsConnected
{
get
{
if (this._session == null)
return false;
else
return this._session.IsConnected;
}
}
private Sftp _sftp;
/// <summary>
/// Gets the shell.