Sockets without MFC/HWNDs or Spin-Locks?
-
MFC's ASyncSocket class provides a wrapper around a Win32 socket and adds functionality to detect events (such as connection, packet received etc). Now I'm aware that a similar method can be performed using plain winsock programming and the use of WSAAsyncSelect. However, it requires the use of a window to receive events (CAsyncSocket does it like this as well doesn't it?). I've seen code that sets up a thread and just waits on recv() using a spin-lock - this seems to go against the grain with me though. I have noticed the select() fn, but I'm not sure if it would truly be thread friendly or would just hide a spin-lock. So, to my question: Is it possible to detect an event from a Socket without resorting to window messages or requiring a spin-lock? Phil
-
MFC's ASyncSocket class provides a wrapper around a Win32 socket and adds functionality to detect events (such as connection, packet received etc). Now I'm aware that a similar method can be performed using plain winsock programming and the use of WSAAsyncSelect. However, it requires the use of a window to receive events (CAsyncSocket does it like this as well doesn't it?). I've seen code that sets up a thread and just waits on recv() using a spin-lock - this seems to go against the grain with me though. I have noticed the select() fn, but I'm not sure if it would truly be thread friendly or would just hide a spin-lock. So, to my question: Is it possible to detect an event from a Socket without resorting to window messages or requiring a spin-lock? Phil
-
MFC's ASyncSocket class provides a wrapper around a Win32 socket and adds functionality to detect events (such as connection, packet received etc). Now I'm aware that a similar method can be performed using plain winsock programming and the use of WSAAsyncSelect. However, it requires the use of a window to receive events (CAsyncSocket does it like this as well doesn't it?). I've seen code that sets up a thread and just waits on recv() using a spin-lock - this seems to go against the grain with me though. I have noticed the select() fn, but I'm not sure if it would truly be thread friendly or would just hide a spin-lock. So, to my question: Is it possible to detect an event from a Socket without resorting to window messages or requiring a spin-lock? Phil
You might find WSAEventSelect interesting. -------- There are 10 types of people in this world. Those who know binary and those who don't.