[Live-devel] BasicTaskScheduler crashed by clients leaving

avbalen at wxs.nl avbalen at wxs.nl
Fri Mar 25 10:32:34 PST 2005


Ross,

Thanks for the quick reply.
Allow me to suggest an alternative solution: once removeHandler has 
been called the iterator over the tasks should be reset. Adding a 
boolean bSetChanged accomplishes this, see the next code snippet. 
Strictly speaking it should be done also when an handler is added.
What do you think?

  // Call the handler function for each readable socket:
  HandlerIterator iter(*fReadHandlers);
  HandlerDescriptor* handler;
  while ((handler = iter.next()) != NULL) {
    if (FD_ISSET(handler->socketNum, &readSet) &&
	FD_ISSET(handler->socketNum, &fReadSet) /* sanity check */ &&
	handler->handlerProc != NULL) {
        (*handler->handlerProc)(handler->clientData, SOCKET_READABLE);
	  if (bSetChanged) {
	    iter.reset();
	    bSetChanged = false;
	  }
    }
  }
}

void BasicTaskScheduler::turnOnBackgroundReadHandling(int socketNum,
				BackgroundHandlerProc* handlerProc,
				void* clientData) {
  if (socketNum < 0) return;
  FD_SET((unsigned)socketNum, &fReadSet);
  fReadHandlers->assignHandler(socketNum, handlerProc, clientData);

  if (socketNum+1 > fMaxNumSockets) {
    fMaxNumSockets = socketNum+1;
  }
}

void BasicTaskScheduler::turnOffBackgroundReadHandling(int socketNum) {
  if (socketNum < 0) return;
  FD_CLR((unsigned)socketNum, &fReadSet);
  fReadHandlers->removeHandler(socketNum);
  bSetChanged = true;	
  if (socketNum+1 == fMaxNumSockets) {
    --fMaxNumSockets;
  }
}

Best regards,

Auke



More information about the live-devel mailing list