>You get the best isolation from >the host application by creating a worker thread and run most of your code >in the context of this thread. Okay, I think I got the structure which seems correct. As I need several sockets for several purposes, I can't use socket's message loop (I don't want to create all of them on DLL load). And I export several functions each of them uses its own socket.
TSocketThread GetSocket(channel: TChannel) * return appropriate socket (create and init it if necessary, attach to the thread with ThreadAttach - I can't create them inside Execute because it's more complicated with my design). Execute() cycle while not terminated * WaitFor activate event (to avoid socket events outside the DLL functions — or maybe I just may pause all the sockets?) * do message loop TCommSocket InitConnection() * connect if closed, WaitFor connection event (set in SessionConnected/Closed/Timeout/... handlers) * send some init stuff Communicate() * send request * WaitFor reply received event (set in DataAvail/SessionClosed/Timeout/... handlers) DLLDoCommunicate * GetSocket * set thread's activate event (or resume socket?) * InitConnection * Communicate * process the received data * unset thread's activate event (or pause socket?) Questions are: 1) How to avoid socket events outside the DLL functions (I guess pausing/resuming the sockets is better cause I'll only have one active socket at a time — the one I need) 2) Do I have to do socket.ThreadDetach on app closing or it's OK? -- Anton -- 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