Max Terentiev wrote:
Use TSslSmtpCli and call the async methods. Your threads must
also implement a message pump or simply call the ICS, built-in,
message pump instead (TSslSmtpCli.CtrlSocket.MessageLoop).
But how to implement message pump if I create many TSmtpCli
inside TThread ?
Unlike main thread in a Delphi GUI application TThread does not
processes messages by default.
A simple message pump was:
procedure TMyThread.PumpMessages(WaitForMessages: Boolean);
var
IsMessage : Boolean;
Msg : TMsg;
begin
while True do
begin
if Terminated and WaitForMessage then
break;
if WaitForMessages then
IsMessage := GetMessage(Msg, 0, 0, 0)
else
IsMessage := PeekMessage(Msg, 0, 0, 0, PM_REMOVE);
if not IsMessage then
break;
if Msg.hwnd = 0 then // messages posted to the thread
begin
if Msg.message = WM_MY_STOP_THREAD_MESSAGE then
begin
if not Terminated then
Terminate;
break;
end
else begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else begin // messages posted/sent to a window of this thread
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
end;
I must implement loop like this this ?
for i:=0 to MySmtpCliList_InThisThread.Count-1 do
TSmtpCli(MyStmpCliList_InThisThread.Items[i]).CtrlSocket.MessageLoop;
No, a single call to start the message loop is enough, for example:
procedure TMyThread.Execute;
begin
1) Create the TSslSmtpCli objects // **ALWAYS** create and destroy them in
Execute method
2) Assign properties and events
3) Call the first async method (probably Connect or Open) and
rely on and control program flow from the event handlers!
PumpMessages(TRUE);
finally
Free the TSslSmtpCli objects
end;
What is better - using 20 non-blocking TSmtpCli's inside thread and
call CtrlSocket.MessageLoop OR using blocking TSyncSmtpCli and call
Sync methods without MessageLoop ? What is fasten and more efficient ?
Use non-blocking, async methods for this purpose.
--
Arno Garrels
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be