|
-
July 13th, 2006, 07:18 AM
#8
Re: AfxSocketInit() unnecessary for worker threads ?
yes. what i do is:
all are worker threads
- in main thread:
i construct CSocket object on heap and declare equivalent SOCKET object
- in second thread:
declare CSocket pointer and point it at CSocket object just constructed in main thread, call Create() on that pointer, then Connect() or Listen() or Accept(). then i detach the CSocket pointer's handle to mentioned SOCKET object. then start another thread and second thread terminates.
- in third thread:
i construct CSocket object on heap and attach a mentioned CSOCKET object to it. then i delete CSocket object i constructed in main thread. then i point the leftover main thread's pointer at just constructed local CSocket object
i know it is a mess, however thanks to this approach i am able to control worker threads from the main thread. having a global pointer that points to CSocket object allows me to cancel blocking call at any time and terminate worker thread without major memory leaks.
next time though i will look into winapi sockets though, when it comes to synchronous sockets, as CSocket seems to be flawed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|