Re: [twsocket] closing socket socket
ThreadDetach and ThreadAttach are implemented: they save and check thread ID. Okay, but that is problematic for me. Maybe, but you have to live with that. Windows is working like that. You can't change anything in the API. -- [EMAIL PROTECTED] 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
Re: [twsocket] closing socket socket
So I called DetachThread before Attach Thread, but now I get the exception that the socket cannot be detached. You can detach a socket from a thread only when you call ThreadDetach within the same thread context which called TreadAttach (or the creating thread context if no attach has been done). See how ThreadDetach and ThreadAttach are implemented: they save and check thread ID. btw: Have you read my previous messages ? I'm still convinced you are confusing TThread class with thread execution context. -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: Humm, Markus [EMAIL PROTECTED] To: twsocket@elists.org Sent: Friday, February 03, 2006 10:15 AM Subject: [twsocket] closing socket socket Hello, I tried something different now, but without success yet. After looking at which thread ids where involved I got the following results: - the socket is created in one thread - the other thread is sending data over the socket, which works like a charm - the other thread then requests a close of the connection, so the socket.shutdown call is within the context of the other thread. Is this a problem? I do hope this is the reason for my problem. Now I tried to attach the socket to the new thread just before calling shutdown. I got the exception then taht one cannot attach a socket which isn't detached. So I called DetachThread before Attach Thread, but now I get the exception that the socket cannot be detached. I have to possibilities now: 1. find out why ThreadDetach doesn't work (I hiped you could shed light on this) 2. move the opening of the connection (thus the creation of the socket) to the execute method of the thread sending. Then creating, sending and closing will be within the same thread I assume. I'd like method 1. better because the communications dll could clean up sockets in the finalization section if the thread/programm using the dll didn't call close_connection properly. So it would be foolproof (nearly) I assume. Greetings Markus -- 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
Re: [twsocket] closing socket socket
Humm, Markus wrote: Now I tried to attach the socket to the new thread just before calling shutdown. I got the exception then taht one cannot attach a socket which isn't detached. So I called DetachThread before Attach Thread, but now I get the exception that the socket cannot be detached. Call WSocket.ThreadDetach in the thread you created WSocket, call WSocket.ThreadAttach in the thread you want attach to. This can be done by posting a custom message to signal the other thread that the socket has been detached and can now be attached to a thread again. Don't call any other WSocket-methods in the thread to be attached before it has been attached. And, the thread to be attached requires a working message pump, otherwise even your custom message won't work. Arno Garrels -- 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] closing socket socket
-Ursprüngliche Nachricht- Von: Francois Piette [mailto:[EMAIL PROTECTED] Gesendet: Freitag, 3. Februar 2006 11:21 An: ICS support mailing Betreff: Re: [twsocket] closing socket socket So I called DetachThread before Attach Thread, but now I get the exception that the socket cannot be detached. You can detach a socket from a thread only when you call ThreadDetach within the same thread context which called TreadAttach (or the creating thread context if no attach has been done). See how ThreadDetach and ThreadAttach are implemented: they save and check thread ID. Okay, but that is problematic for me. It may occur that the thread who created the socket is already gone but since it didn't close the socket properly (for what reason whatever) the communication dll is bound to close it. But now it can't since the socket has been created in another thread. btw: Have you read my previous messages ? I'm still convinced you are confusing TThread class with thread execution context. I do understand now that only the code within the execute method of a TThread descendant runs in the context of that thread. All other method of that TThread descendant won't unless being called from the own execute method. Greetings from a still learnig Markus -- 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] closing socket socket
So I called DetachThread before Attach Thread, but now I get the exception that the socket cannot be detached. You can detach a socket from a thread only when you call ThreadDetach within the same thread context which called TreadAttach (or the creating thread context if no attach has been done). See how ThreadDetach and ThreadAttach are implemented: they save and check thread ID. Okay, but that is problematic for me. It may occur that the thread who created the socket is already gone Sorry but this is bad design. Before going down, you thread has either to free the component, or the detach it and somehow make another thread (the main thread) attach it to be able to free it later. btw: Have you read my previous messages ? I'm still convinced you are confusing TThread class with thread execution context. I do understand now that only the code within the execute method of a TThread descendant runs in the context of that thread. That's not correct. Not only code executed within the execute method runs in the context of that thread, but also anything called directly or indirectly (such as an event handler) from the execute method. All other method of that TThread descendant won't unless being called from the own execute method. That's correct. -- [EMAIL PROTECTED] 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