I now trying to implement sync socket actions (I'll need to make DLL so async model doesn't fit).
procedure TSockClient.Request;
begin
 if State <> wsConnected then
 begin
   Connect;
   while not (State in [wsConnected, wsClosed]) do
     MessagePump;
   if State <> wsConnected then
   begin
     //..
     Exit;
   end;
 end;
...send request...
end;

Why would you like to implement such code ? You'll just waste CPU cycles. There are a lot of easy way to use async operations in a DLL. If you need to export synchronous functions out of your DLL, I would suggest using a thread withing the DLL, having his own message ump and working purely asynchronoulsy as ICS does so well. Then the exported function will talk to this thread using traditional multithread synchonization mechanisms to looks blocking from the outside. A Windows event is a perfect item for that kind of job: the exported function will start the asynchonous operation by the worker thread and wait on an event which will be set by the worker thread once the work is done. Quite easy to implement without any change in TWSocket.

btw: If you really want to do something like you have show, do NOT loop on the state property value but use the events and your own application level state variable. TWSocket.State has never been intended for waiting on a given state. It has been designed for internal use and for informational purpose only. Events are the way to go to trigger state change into your own finite state machine related to your own application.

--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
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

Reply via email to