Hello,

Assuming this is the official MT implementation for ICS, I am looking at the 
below code:

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*}

function TWSocketThrdServer.ClientAttachThread(

Client: TWSocketThrdClient): TWsClientThread;

var

WaitRes : Longword;

H : array[0..1] of THandle;

begin

if Client.Handle <> 0 then

Client.ThreadDetach;

//LogDebug(IntToHex(Integer(Client), 8) + ' Main Thread Detached');

Client.FClientThread := nil;

Client.FServer := Self;

Result := AcquireThread;

H[1] := Result.Handle;

{ Wait until the thread has initialized its message queue }

if not Result.FReadyForMsgs then begin

H[0] := Result.FEventArray[cteiThreadReady];

WaitRes := WaitForMultipleObjects(2, @H, FALSE, Infinite);

if WaitRes = WAIT_FAILED then

raise Exception.Create('Wait failed ' +

SysErrorMessage(GetLastError))

else if WaitRes = WAIT_OBJECT_0 + 1 then

raise Exception.Create('Thread terminated while waiting');

end;

if not PostThreadMessage(Result.ThreadID,

WM_THREAD_ADD_CLIENT, Integer(Client), 0) then

raise Exception.Create('PostThreadMessage ' +

SysErrorMessage(GetLastError));

H[0] := Result.FEventArray[cteiClientAttached];

{ Wait until thread has attached client socket to his own context. }

WaitRes := WaitForMultipleObjects(2, @H, FALSE, Infinite);

if WaitRes = WAIT_FAILED then

raise Exception.Create('Wait client ThreadAttach ' +

SysErrorMessage(GetLastError))

else if WaitRes = WAIT_OBJECT_0 + 1 then begin

{ ThreadAttach failed due to the thread terminated, let's try again }

ClientAttachThread(Client);

Exit;

end;

if Assigned(FOnClientAttached) then

FOnClientAttached(Self, Client, Result);

//LogDebug(IntToHex(Integer(Client), 8) + ' W att ID: ' + 
IntToHex(Result.ThreadID, 8));

end;

Now, does the end of this function (FOnClientAttached()) run in the worker 
thread context? If not, what's the point in waiting with 
waitformultiplemessages? Isn't only the PostThreadMessage enough? Francois, 
could you enlight me? I am puzzled!

Best Regards,

SZ

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to