[fpc-devel] SimpleIPC and TWinMsgServerComm.PeekMessage
Sven Barth
pascaldragon at googlemail.com
Wed Oct 9 13:52:41 CEST 2013
Am 09.10.2013 10:40, schrieb Juha Manninen:
> I am testing SimpleIPC with components/chmhelp/lhelp
> and
> components/chmhelp/democontrol/lhelpconnectiondemo1
>
> The latter works as a master application, sending a file name to lhelp
> and starting it if not running already.
> On Linux this works perfectly. The return message status is always "Success".
> On Windows there is a bug when lhelp is not yet running and it must be started.
>
> In TWinMsgServerComm.PeekMessage() (part of SimpleIPC),
> if Windows.PeekMessage() failed, the idea is to wait a given TimeOut
> and then try again:
>
> R:=MsgWaitForMultipleObjects(1,FHWND,False,TimeOut,QS_SENDMESSAGE);
> B:=(R<>WAIT_TIMEOUT);
>
> The caller gives 50 ms as timeout but also uses a loop for 5 seconds
> total timeout.
> It should be enough for even slowly starting processes.
> However, when the process does not exist yet,
> MsgWaitForMultipleObjects returns WAIT_FAILED instead of WAIT_TIMEOUT,
> and it does NOT wait. It returns immediately.
>
> I was able to fix it like this:
> R:=MsgWaitForMultipleObjects(1,FHWND,False,TimeOut,QS_SENDMESSAGE);
> if R=WAIT_FAILED then
> Sleep(TimeOut);
> B:=(R<>WAIT_TIMEOUT) and (R<>WAIT_FAILED);
>
> The fix can be tested with lhelpconnectiondemo1.
> Currently the first reply status is NoAnswer, after the fix it is Success.
> If you think the fix is OK, I can make a patch.
You might want to take a look at WaitForInputIdle.
MSDN entry:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687022%28v=vs.85%29.aspx
Informative blog entry:
http://blogs.msdn.com/b/oldnewthing/archive/2010/03/25/9984720.aspx
In my opinion you should use this in TLHelpConnection.StartHelpServer.
Though you could add it in TWinMsgServerComm as well, as we rely on
messages anyway...
Regards,
Sven
More information about the fpc-devel
mailing list