[twsocket] How to use many TSmtpCli's inside thread ?
Hi, It's possible to use multiple TSmtpCli inside single TThread ? For example, I want to handle 100 connections using 5 TThreads. Each TThread should contain 20 TStmpCli's. Is it's possible ? I must use T(ssl)SmtpCli or TSYNCSmtpCli ? --- With best regards, Max Terentiev. Business Software Products. AMS Development Team. supp...@bspdev.com -- 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
Re: [twsocket] How to use many TSmtpCli's inside thread ?
Max Terentiev wrote: > Hi, Hi, > It's possible to use multiple TSmtpCli inside single TThread ? Yes. > For example, I want to handle 100 connections using 5 TThreads. > Each TThread should contain 20 TStmpCli's. > > Is it's possible ? No problem, however you should consider to use just as many threads as CPUs are available. It's no problem to have 100 ICS objects and more in a single thread. > I must use T(ssl)SmtpCli or TSYNCSmtpCli ? 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). You also have to instanciate a TSslStaticLock object in a multi-threaded environment to make the OpenSSL libraries thread-safe. Read comments in unit OverbyteIcsThrdLock.pas for more details. Also TSslContext should be thread-safe so it's not required to use one context object per TSslSmtpCli instance. -- 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
Re: [twsocket] How to use many TSmtpCli's inside thread ?
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 ? I must implement loop like this this ? for i:=0 to MySmtpCliList_InThisThread.Count-1 do TSmtpCli(MyStmpCliList_InThisThread.Items[i]).CtrlSocket.MessageLoop; 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 ? Thanx for help ! -- 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 -- 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
Re: [twsocket] How to use many TSmtpCli's inside thread ?
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
Re: [twsocket] How to use many TSmtpCli's inside thread ?
Arno Garrels wrote: > **ALWAYS** create and destroy them in Execute method That is not always necessary, however ensures that they are always created in the context of the thread. Note that ICS event handlers are by default called in the context of the thread the object was created in. -- 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