<div dir="ltr">On Mon, May 16, 2016 at 9:01 AM, Bo Berglund <span dir="ltr"><<a href="mailto:bo.berglund@gmail.com" target="_blank">bo.berglund@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The Execute procedure handles everything going on and it acts on event<br>
signals picked up (I believe) by the WaitForMultipleObjects calls.<br>
<br>
What I would like to know is how exactly to handle this in FreePascal<br>
on Linux....<br></blockquote><div><br></div><div>I presume <span style="font-size:13px">FConnectEvent, FDisconnectEvent (and others) are of TEvent type (from FCLs syncobjs)</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">In this case, I'd think you could implement </span><span style="font-size:13px">WaitForMultipleObjects() yourself, via a simple event waiting loop:</span></div><div><span style="font-size:13px"><br></span></div><div>uses ... syncobjs, SysUtils ;</div><div><span style="font-size:13px"><br></span></div><div><div>const</div><div> WAIT_TIMEOUT = $102;</div><div><br></div><div>function WaitForMultipleObject(cnt : integer; const handle: array of TEventHandle;</div><div> waitforall: Boolean; timeOutMls: integer): integer;</div><div>var</div><div> event : Integer;</div><div> evNum : integer;</div><div> i : integer;</div><div> ev : array of boolean;</div><div> wr : TWaitResult;</div><div> any : Boolean;</div><div> d : TDateTime; // please forgive the usage of now() :)</div><div> dm : integer;</div><div>const</div><div> YIELD_TIME=0;</div><div>begin</div><div> evNum:=0;</div><div> SetLength(ev, cnt);</div><div> Result:=WAIT_TIMEOUT;</div><div> // create a loop of waiting for each event to fire</div><div> repeat</div><div> any:=false;</div><div> if timeOutMls>0 then d:=now;</div><div><br></div><div> for i:=0 to cnt-1 do</div><div> if not ev[i] then begin</div><div> // refer to synobj sources for .WaitFor() method of TEvent</div><div> wr:=TWaitResult(basiceventWaitFor(0, Handle[i]));</div><div> if wr=wrSignaled then begin</div><div> ev[i]:=true;</div><div> inc(evNum);</div><div> Result:=i;</div><div> if not waitforall then Break;</div><div> end;</div><div> end;</div><div><br></div><div> if not any and (timeOutMls>0) then begin</div><div> // if has timeout, must yeld the time for some time</div><div> // and then repeat the try</div><div> Sleep(YIELD_TIME);</div><div> if timeOutMls>0 then begin</div><div> d:=now-d;</div><div> dm:=round(d*MSecsPerDay);</div><div> dec(timeOutMls, dm);</div><div> if (timeOutMls<0) then timeOutMls:=0;</div><div> end;</div><div> end;</div><div> // btw, actual support for "waitforall" is not needed in this case</div><div> until (evNum>0) and (not waitforall or (cnt=evNum)) or (timeOutMls=0);</div><div> if waitforall and (evNum>0) then Result:=0;</div><div>end;</div></div><div><br></div><div>I've not tested this loop, but it should give you an idea of what you could do.</div><div><br></div><div>The fact that you're using the handles of the same type allows you to implement the loop yourself. </div><div><br></div><div><span style="font-size:13px">thanks,</span></div><div><span style="font-size:13px">Dmitry</span></div><div> </div></div></div></div>