C++ Programming
04-04-2009, 06:02 AM
Alright, I'm trying to wrap a server written in c for the most part in a class. From inside one of the methods I want to launch a thread to another method. My attempt looks something like this:
void WebServer::ListenServer(void)
{
unsigned threadID;
while(true)
{
int fromlen = sizeof (from);
messageSocket = accept (listenSocket, (struct sockaddr*)&from, &fromlen);
// Handle the message socket:
if (messageSocket != INVALID_SOCKET)
{
// Launch thread to respond to the request :
_beginthreadex(NULL, 1000, (void*)&WebServer::HandleRequest, NULL, 0, &threadID);
}
}
}
void WebServer::HandleRequest()
{
// Do some work here:
}
Can this even be done? I have tried multiple castings etc of the beginthreadex() function. What would be an alternative to this?
void WebServer::ListenServer(void)
{
unsigned threadID;
while(true)
{
int fromlen = sizeof (from);
messageSocket = accept (listenSocket, (struct sockaddr*)&from, &fromlen);
// Handle the message socket:
if (messageSocket != INVALID_SOCKET)
{
// Launch thread to respond to the request :
_beginthreadex(NULL, 1000, (void*)&WebServer::HandleRequest, NULL, 0, &threadID);
}
}
}
void WebServer::HandleRequest()
{
// Do some work here:
}
Can this even be done? I have tried multiple castings etc of the beginthreadex() function. What would be an alternative to this?