TScSSHShell: OnAsyncReceive event never raise
Posted: Fri 06 Jan 2012 14:48
Hello,
with a shell in nonblocking mode, OnAsyncReceive doesn't raise.
part of my code:
class TThreadSshClient : public TThread
{
private:
struct DeviceInfo &Infos;
TScSSHClient *ScSSHClient1;
TScFileStorage *ScFileStorage1;
TScSSHShell *ScSSHShell1;
...
void __fastcall ScSSHClientServerKeyValidate(TObject *Sender, TScKey *NewServerKey, bool &Accept);
void __fastcall ScSSHShellOnAsyncReceive(TObject *Sender);
};
...
ScSSHClient1 = new TScSSHClient(Owner);
ScFileStorage1 = new TScFileStorage(Owner);
ScSSHShell1 = new TScSSHShell(Owner);
ScSSHClient1->KeyStorage = ScFileStorage1;
ScSSHClient1->OnServerKeyValidate = ScSSHClientServerKeyValidate ;
ScSSHShell1->Client = ScSSHClient1;
ScSSHShell1->OnAsyncReceive = ScSSHShellOnAsyncReceive;
ScSSHShell1->NonBlocking = true;
...
//---------------------------------------------------------------------------
void __fastcall TThreadSshClient::ScSSHShellOnAsyncReceive(TObject *Sender)
{
char buffer[10005];
int ReadBytes = ScSSHShell1->ReadBuffer(buffer, sizeof(buffer));
if(ReadBytes == 0)
throw EAbort("Failed. (ReadBytes == 0) Unexpected disconnection");
Text += AnsiString(buffer, ReadBytes);
}
------------------------------------------------------------------------
I made a tempory work around using a loop with a timeout, it's working fine but it's not very satisfying:
...
while (!Terminated && ScSSHShell1->Connected && i_SSHReceivedTimeOutReadBuffer(buffer, sizeof(buffer));
if(ReadBytes != 0)
Text += AnsiString(buffer, ReadBytes);
}
----------------------------------------------------------------
I have also a question about OnAsyncReceive:
when exaclty should it be raise please?
each time there is an action (write read..)or only on read? for each characters or only one time per message?
have you exemple using OnAsyncReceive (there is no demo in secure bridge for C++Builder5)
Thanks for your help.
regards.
with a shell in nonblocking mode, OnAsyncReceive doesn't raise.
part of my code:
class TThreadSshClient : public TThread
{
private:
struct DeviceInfo &Infos;
TScSSHClient *ScSSHClient1;
TScFileStorage *ScFileStorage1;
TScSSHShell *ScSSHShell1;
...
void __fastcall ScSSHClientServerKeyValidate(TObject *Sender, TScKey *NewServerKey, bool &Accept);
void __fastcall ScSSHShellOnAsyncReceive(TObject *Sender);
};
...
ScSSHClient1 = new TScSSHClient(Owner);
ScFileStorage1 = new TScFileStorage(Owner);
ScSSHShell1 = new TScSSHShell(Owner);
ScSSHClient1->KeyStorage = ScFileStorage1;
ScSSHClient1->OnServerKeyValidate = ScSSHClientServerKeyValidate ;
ScSSHShell1->Client = ScSSHClient1;
ScSSHShell1->OnAsyncReceive = ScSSHShellOnAsyncReceive;
ScSSHShell1->NonBlocking = true;
...
//---------------------------------------------------------------------------
void __fastcall TThreadSshClient::ScSSHShellOnAsyncReceive(TObject *Sender)
{
char buffer[10005];
int ReadBytes = ScSSHShell1->ReadBuffer(buffer, sizeof(buffer));
if(ReadBytes == 0)
throw EAbort("Failed. (ReadBytes == 0) Unexpected disconnection");
Text += AnsiString(buffer, ReadBytes);
}
------------------------------------------------------------------------
I made a tempory work around using a loop with a timeout, it's working fine but it's not very satisfying:
...
while (!Terminated && ScSSHShell1->Connected && i_SSHReceivedTimeOutReadBuffer(buffer, sizeof(buffer));
if(ReadBytes != 0)
Text += AnsiString(buffer, ReadBytes);
}
----------------------------------------------------------------
I have also a question about OnAsyncReceive:
when exaclty should it be raise please?
each time there is an action (write read..)or only on read? for each characters or only one time per message?
have you exemple using OnAsyncReceive (there is no demo in secure bridge for C++Builder5)
Thanks for your help.
regards.