CAsyncSocket::Close Crashes
-
Hey, im doing some client/server stuff in a windows service. Pretty much new to this stuff using Visual C++ 6 The problem I'm encountering is that when I try to stop the service through Service Manager, it crashes. I added some MessageBoxes code, to trace where they are crashing and I found that when it closes the listener socket it crashes!!! I tried to run the service as a console application, and by myself called the function which is called SERVICE__CONTROL__STOP event is received so that I may reproduce the bug and debug easily. But it is working fine. The windows service is only crashing when I stop it through Service Manager Here is some code The main function
int main(int argc, char* argv[])
{
// Create the service object
CTestService CustomServiceObject;if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { std::cerr << "MFC failed to initialize!" << std::endl; return 1; } // Parse for standard arguments (install, uninstall, version etc.) if (! CustomServiceObject.ParseStandardArgs(argc, argv)) { // StartService() calls ::StartServiceCtrlDispatcher() // with the ServiceMain func and stuff CustomServiceObject.StartService(); } // When we get here, the service has been stopped return CustomServiceObject.m\_Status.dwWin32ExitCode;
}
The Service Handler callback function
// static member function (callback) to handle commands from the
// service control manager
void CNTService::Handler(DWORD dwOpcode)
{
// Get a pointer to the object
CNTService* pService = m_pThis;pService->DebugMsg("CNTService::Handler(%lu)", dwOpcode); switch (dwOpcode) { case SERVICE\_CONTROL\_STOP: // 1 pService->SetStatus(SERVICE\_STOP\_PENDING); pService->OnStop(); // .. // .. // other event handling // .. // ..
}
the OnStop() function
void CTestService::OnStop()
{
m_sListener.ShutDown(2);
m_sConnected.ShutDown(2);MessageBox(NULL, "After Shutdown", NULL, IDOK); m\_sConnected.Close(); MessageBox(NULL, "Closed connected socket", NULL, IDOK); // crashes here when I try to stop through service manager // but if I run as console application works fine and terminates successfully m\_sListener.Close(); MessageBox(NULL, "Closed listener socket", NULL, IDOK); ::PostThreadMessa
-
Hey, im doing some client/server stuff in a windows service. Pretty much new to this stuff using Visual C++ 6 The problem I'm encountering is that when I try to stop the service through Service Manager, it crashes. I added some MessageBoxes code, to trace where they are crashing and I found that when it closes the listener socket it crashes!!! I tried to run the service as a console application, and by myself called the function which is called SERVICE__CONTROL__STOP event is received so that I may reproduce the bug and debug easily. But it is working fine. The windows service is only crashing when I stop it through Service Manager Here is some code The main function
int main(int argc, char* argv[])
{
// Create the service object
CTestService CustomServiceObject;if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { std::cerr << "MFC failed to initialize!" << std::endl; return 1; } // Parse for standard arguments (install, uninstall, version etc.) if (! CustomServiceObject.ParseStandardArgs(argc, argv)) { // StartService() calls ::StartServiceCtrlDispatcher() // with the ServiceMain func and stuff CustomServiceObject.StartService(); } // When we get here, the service has been stopped return CustomServiceObject.m\_Status.dwWin32ExitCode;
}
The Service Handler callback function
// static member function (callback) to handle commands from the
// service control manager
void CNTService::Handler(DWORD dwOpcode)
{
// Get a pointer to the object
CNTService* pService = m_pThis;pService->DebugMsg("CNTService::Handler(%lu)", dwOpcode); switch (dwOpcode) { case SERVICE\_CONTROL\_STOP: // 1 pService->SetStatus(SERVICE\_STOP\_PENDING); pService->OnStop(); // .. // .. // other event handling // .. // ..
}
the OnStop() function
void CTestService::OnStop()
{
m_sListener.ShutDown(2);
m_sConnected.ShutDown(2);MessageBox(NULL, "After Shutdown", NULL, IDOK); m\_sConnected.Close(); MessageBox(NULL, "Closed connected socket", NULL, IDOK); // crashes here when I try to stop through service manager // but if I run as console application works fine and terminates successfully m\_sListener.Close(); MessageBox(NULL, "Closed listener socket", NULL, IDOK); ::PostThreadMessa
many many my programs are running excellent in release but crashes at once in debug (I even can't see any interface) - I think this is microsoft's problem, we do not need to take responsibilities for it, I never worry about it at all. So take it easy.
-
many many my programs are running excellent in release but crashes at once in debug (I even can't see any interface) - I think this is microsoft's problem, we do not need to take responsibilities for it, I never worry about it at all. So take it easy.
-
Hey, im doing some client/server stuff in a windows service. Pretty much new to this stuff using Visual C++ 6 The problem I'm encountering is that when I try to stop the service through Service Manager, it crashes. I added some MessageBoxes code, to trace where they are crashing and I found that when it closes the listener socket it crashes!!! I tried to run the service as a console application, and by myself called the function which is called SERVICE__CONTROL__STOP event is received so that I may reproduce the bug and debug easily. But it is working fine. The windows service is only crashing when I stop it through Service Manager Here is some code The main function
int main(int argc, char* argv[])
{
// Create the service object
CTestService CustomServiceObject;if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { std::cerr << "MFC failed to initialize!" << std::endl; return 1; } // Parse for standard arguments (install, uninstall, version etc.) if (! CustomServiceObject.ParseStandardArgs(argc, argv)) { // StartService() calls ::StartServiceCtrlDispatcher() // with the ServiceMain func and stuff CustomServiceObject.StartService(); } // When we get here, the service has been stopped return CustomServiceObject.m\_Status.dwWin32ExitCode;
}
The Service Handler callback function
// static member function (callback) to handle commands from the
// service control manager
void CNTService::Handler(DWORD dwOpcode)
{
// Get a pointer to the object
CNTService* pService = m_pThis;pService->DebugMsg("CNTService::Handler(%lu)", dwOpcode); switch (dwOpcode) { case SERVICE\_CONTROL\_STOP: // 1 pService->SetStatus(SERVICE\_STOP\_PENDING); pService->OnStop(); // .. // .. // other event handling // .. // ..
}
the OnStop() function
void CTestService::OnStop()
{
m_sListener.ShutDown(2);
m_sConnected.ShutDown(2);MessageBox(NULL, "After Shutdown", NULL, IDOK); m\_sConnected.Close(); MessageBox(NULL, "Closed connected socket", NULL, IDOK); // crashes here when I try to stop through service manager // but if I run as console application works fine and terminates successfully m\_sListener.Close(); MessageBox(NULL, "Closed listener socket", NULL, IDOK); ::PostThreadMessa
-
Could you provide more information where it crashes in the debug build, including a stack trace? Is it your code or which line of the MFC source code causes the problem, perhaps it's an ASSERT? /M
My webchat in Europe :java: (in 4K)
Since, it is a Windows Service, and I'm using MSVC6, I'm really unable to debug it. When I call the Close method for CAsyncSocket class, the program crashes. So it seems that there is some problem in MFC's code.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
-
Since, it is a Windows Service, and I'm using MSVC6, I'm really unable to debug it. When I call the Close method for CAsyncSocket class, the program crashes. So it seems that there is some problem in MFC's code.
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
If you are not able to attach a debugger to the process, how about a simulated stop of the service handler? Maybe write a mockup framework that would trigger your code under similar conditions. Just a guess, you are not using
CAsyncSocket
in multiple worker threads, everything is one thread context?My webchat in Europe :java: (in 4K)
-
If you are not able to attach a debugger to the process, how about a simulated stop of the service handler? Maybe write a mockup framework that would trigger your code under similar conditions. Just a guess, you are not using
CAsyncSocket
in multiple worker threads, everything is one thread context?My webchat in Europe :java: (in 4K)
I call the function which is called when the SERVICE_CONTROL_STOP event is fired by myself. But I'm unable to reproduce that crash. It only occurs when it is stopped by Service Manager. No I'm not using CAsyncSocket in multiple threads
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.