Winsock inside a service problem

This topic is 2261 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Outputdebug does NOT work. I must have like 20 of them in my service and I never get to see one in visual studio.I'll try what endurion said.

Not sure if debugview doesn't work or I'm not using it the right way...i see nothing in the list

Edited by noatom

Share on other sites

I'd go for a logfile then. C:\out.txt or something like that.

Do breakpoints work? You probably want to narrow the problem down a bit before you start stepping through code though.

Share on other sites
void CSampleService::ServiceWorkerThread(void)
{
ServStart();

// Periodically check if the service is stopping.
FILE* pFile = fopen("logFile.txt", "a");
fprintf(pFile, "%s\n","In worker function");
while (!m_fStopping)
{

SOCKET NewConnection;

char recvbuff[1024];
// Main program loop
NewConnection = SOCKET_ERROR;
if(NewConnection == SOCKET_ERROR)
{

//NewConnection = accept(ListeningSocket, NULL, NULL);	// this is a blocking function
ByteReceived = recv(NewConnection, recvbuff, sizeof(recvbuff), 0);

{

memset(&SenderInfo, 0, sizeof(SenderInfo));
nlen = sizeof(SenderInfo);

}

}
if (shutdown(NewConnection, 2) != 0)
OutputDebugString(L"Line 355");
else
OutputDebugString(L"shutdown is working...\n");

}
fclose(pFile);
// Signal the stopped event.
SetEvent(m_hStoppedEvent);
}


So,see that ServStart() call at the begining,it turns out it calls that function(saw it on a logfile),but after it gets out of it,it doesn't to anything.I mean when it gets out it should post some of those lines of text,but it doesn't.

Why would the call to StartServer do fine,and after that "nothing happens" ?

Share on other sites

Print more stuff to the file. You are still using OutputDebugString as well...

Does accept() ever return? You can probably just put a breakpoint on the OutputDebugString following to see if it does.

When tracing I usually log

+functionname()

at the start of each function and

-functionname()

everywhere it returns/exits, along with other information, especially before and after calls to blocking functions...

Share on other sites

For one, m_fStopping might be true (or worse, uninitialized).

You really need to cover everything from the start downwards to see where the CPU is branching into and where not.

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 9
• 11
• 15
• 21