[SFTP client] NonBlocking mode / console app

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
pcz
Posts: 81
Joined: Tue 04 Aug 2015 12:53

[SFTP client] NonBlocking mode / console app

Post by pcz » Wed 01 Jun 2016 12:05

Hello

I suppose that NonBlocking mode reqire a message loop to work? Am I right?

What is the easiest way to use NonBlocking mode in a windowless application?

Regards
P.C.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: [SFTP client] NonBlocking mode / console app

Post by ViktorV » Fri 03 Jun 2016 12:29

NonBlocking mode is not supported in console applications. If you want us to implement the feature, please post it at our user voice forum: http://devart.uservoice.com/forums/174370-securebridge If the suggestion gets a lot of votes, we will consider the possibility to implement it.

pcz
Posts: 81
Joined: Tue 04 Aug 2015 12:53

Re: [SFTP client] NonBlocking mode / console app

Post by pcz » Fri 03 Jun 2016 13:04

ViktorV wrote:NonBlocking mode is not supported in console applications. If you want us to implement the feature, please post it at our user voice forum: http://devart.uservoice.com/forums/174370-securebridge If the suggestion gets a lot of votes, we will consider the possibility to implement it.
I just don't have enough time ;)
I have experimented with simple message pumping and it looks to handle it.

If case of anybody interested...

Code: Select all

var
  AppTerminated: Boolean;
  ActiveTransmission: Boolen;

{...}

procedure PumpMessagess;
var
  Unicode: Boolean;
  Msg: TMsg;
begin
  while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
  begin
    Unicode := (Msg.hwnd = 0) or IsWindowUnicode(Msg.hwnd);
    TranslateMessage(Msg);
    if Unicode then
      DispatchMessageW(Msg)
    else
      DispatchMessageA(Msg);
  end;
end;

procedure Wait;
var
  WaitResult: DWORD;
  Dummy: THandle;
begin
  while ActiveTransmission and (not AppTerminated) do
  begin
    // event can be used to avoid potential 1 second delay
    WaitResult := MsgWaitForMultipleObjects(0, Dummy, False, 1000, QS_ALLINPUT);
    if WaitResult = WAIT_OBJECT_0 then   // messages in queue
      PumpMessagess;

    {check termination condition or do anything...}

  end;
end;

{.....}

ScSFTPClientInstance.UploadFile(....);
Wait;

{.....}
It looks that TScSFTPClient class relies mainly on WM_TIMER messages so
- you have to be really careful because some operations (like calling <TScSFTPClient>.OpenFile) can cause deadlock at DispatchMessageA/W call
- disconnect TScSFTPClient when idle to stop WM_TIMER mesages

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: [SFTP client] NonBlocking mode / console app

Post by ViktorV » Wed 08 Jun 2016 10:53

The NonBlocking mode does not work in console applications, since they do not have a native window message handler. If you implement message handling on your own, as you have done, the NonBlocking mode can be used in console applications.

Post Reply