Wait Until Event Occurs
-
Hey, I'm doing sockets programming. Pretty much new to it. The application is a Windows Service, in its ServiceMain() function I call CAsyncSocket's Listen() method, to listen for client connections. But after it starts listening for connections, it'll return and the ServiceMain() function will return and the service is stopped. What I want to do with this is that, wait until a specific event occurs say WM_QUIT, till than listen for connections. How to do it?
// static member function (callback)
void CNTService::ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv)
{
// m_Server containts two sockets
// one for listening and one for accepting connectionsm\_Server.StartListening(); // calls Listen method on the listener socket // it will return and service will quit // which I don't want
}
I'm okay with mixing Win32 and MFC, so if it can be done in Win32 please do tell me too :)
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
-
Hey, I'm doing sockets programming. Pretty much new to it. The application is a Windows Service, in its ServiceMain() function I call CAsyncSocket's Listen() method, to listen for client connections. But after it starts listening for connections, it'll return and the ServiceMain() function will return and the service is stopped. What I want to do with this is that, wait until a specific event occurs say WM_QUIT, till than listen for connections. How to do it?
// static member function (callback)
void CNTService::ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv)
{
// m_Server containts two sockets
// one for listening and one for accepting connectionsm\_Server.StartListening(); // calls Listen method on the listener socket // it will return and service will quit // which I don't want
}
I'm okay with mixing Win32 and MFC, so if it can be done in Win32 please do tell me too :)
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
Ahmed Manzoor wrote:
What I want to do with this is that, wait until a specific event occurs say WM_QUIT
Does the service have a window (and associated window queue) on which to listen for window messages? Doubt it... Instead, use a Win32 IPC event object[^] with a name specific to your service (hint: use an ASCII representation of a UUID to get a unique name) and wait on that with WaitForSingleObject[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Ahmed Manzoor wrote:
What I want to do with this is that, wait until a specific event occurs say WM_QUIT
Does the service have a window (and associated window queue) on which to listen for window messages? Doubt it... Instead, use a Win32 IPC event object[^] with a name specific to your service (hint: use an ASCII representation of a UUID to get a unique name) and wait on that with WaitForSingleObject[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
But, won't that block the thread and everything will stop!
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
Quite true - I was thinking of the other sort of asynchronous IO that uses APCs (but that wouldn't work with WaitForSingleObject - it would need WaitForSingleObjectEx). OK. So, you need a window message pump to handle blocking for you...which is actually something that CSocket provides - whioch leads to the question - why not use CSocket instead of CAsyncSocket? I can't see any advantage to CAsyncSocket if you're only using one socket.... Anyway - to see how to block and process socket notifications, have a look at the CSocket message loop in CSocket::ProcessAuxQueue, which is in sockcore.cpp in your MFC source directory (that's C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc for me).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Quite true - I was thinking of the other sort of asynchronous IO that uses APCs (but that wouldn't work with WaitForSingleObject - it would need WaitForSingleObjectEx). OK. So, you need a window message pump to handle blocking for you...which is actually something that CSocket provides - whioch leads to the question - why not use CSocket instead of CAsyncSocket? I can't see any advantage to CAsyncSocket if you're only using one socket.... Anyway - to see how to block and process socket notifications, have a look at the CSocket message loop in CSocket::ProcessAuxQueue, which is in sockcore.cpp in your MFC source directory (that's C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc for me).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Okay, thanks I'll take a look at the source. Its not that I'm using only one socket :). I'll add support for more connections, but later. I only need blocking for listening and everything else asynchronous. I guess, I'll have to kick-off some threads. Any good strategy for using blocking listening and non-blocking I/O, MULTITHREADEDly :-D
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.