Re: [twsocket] Threading question

2007-04-06 Thread DZ-Jay

On Apr 5, 2007, at 10:23, Éric Fleming Bonilha wrote:

 Another thing, now FSocket is being destroyed on my class destructor, 
 should I destroy it on the end of the execute method, after leaving 
 the message loop?

You should destroy FSocket at the end of the Execute method.

dZ.

-- 
DZ-Jay [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html

-- 
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


Re: [twsocket] Threading question

2007-04-05 Thread Francois Piette
 Do I need to do any other things to make it work right?

Looks OK, except destruction of the component which must be done in the
context of the creating thread, so at the end of your execute method. Use
try/finally.

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be

- Original Message - 
From: Éric Fleming Bonilha [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Thursday, April 05, 2007 4:23 PM
Subject: [twsocket] Threading question


 Hello!

 I have a client application that should connect to different servers at
the same time but for each connection it may have very lengthy operations so
I decided to used one thread per connection, but I´m writting this email
just to be sure that I´m doing the right thing

 Basically I have a thread class that have an internal socket component:

   TDriverCommSocketThread = class(TDigiThread)
   private

 // Connection socket
 FSocket: TWSocket;

 and this is my execute method

 TDriverCommSocketThread.Execute;
 begin

   // Creates the socket
   FSocket:= TWSocket.Create(nil);
   FSocket.MultiThreaded  := TRUE;
   FSocket.OnSessionConnected := HandleOnSocketConnected;
   FSocket.OnSessionClosed:= HandleOnSocketClosed;
   FSocket.OnDataAvailable:= HandleOnSocketDataAvailable;
   FSocket.OnError:= HandleOnSocketError;
   FSocket.OnBgException  := HandleOnSocketException;
   FSocket.Connect;

   // Message Loop
   while GetMessage(MsgRec, 0, 0, 0) do
   begin

 if not Terminated then
 begin

   // Process the received messages
   TranslateMessage(MsgRec);
   DispatchMessage(MsgRec)

 end;

   end;

 end;

 Doing this, all events like OnSessionConnected, OnSessionClosed,
OnDataAvailable, OnError and OnBgException will be triggered within my
message loop, consequently it will be triggered on the thread´s context
right?

 Do I need to do any other things to make it work right? Now it is working
great, but I´m having some problems that I don´t know if it is related to
this multi-threaded scenario, because of that I´m asking if I´m doing the
right thing..

 Another thing, now FSocket is being destroyed on my class destructor,
should I destroy it on the end of the execute method, after leaving the
message loop?

 Thanks a lot!
 Éric Fleming Bonilha
 -- 
 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


-- 
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