Example #1
0
/**
 * Main loop, start handling packets.
 * @return Always FALSE?
 */
int MainLoop()
{
	int i;
	sigset_t set;

	DEBUGPATH;

#ifdef DEBUG
	printf("Starting loop in Threaded mode\n");
#endif

	/*
		Won't let an arbitrary thread get signals.
		Only this thread will do it. We will let
		the signal inheritance do the job.
	*/
	sigemptyset(&set);

	sigaddset(&set, SIGINT);
	sigaddset(&set, SIGQUIT);
	sigaddset(&set, SIGTERM);

	i = pthread_sigmask(SIG_BLOCK, &set, NULL);

	if (i) {
		fprintf (stderr, "Can't set the thread's signal mask");
		return FALSE;
	}

	Globals.Done=FALSE;

	InitPacketQueue (MAX_PACKETS);

	if (!InitInterfacesThreads()) {
		return FALSE;
	}

#ifdef LOGFILE_THREAD
	/* start up the log files keeper thread */
	pthread_create(&Globals.logThread, NULL, ProcessLogFilesThread, NULL);
#endif

#ifdef LOGFILE_THREAD_NO
	fprintf(stderr, "Thread for log file keeping won't be created because we're running in non-threaded mode.\n");
#endif

	if (!InitActionsProcessingThreads()) {
		return FALSE;
	}

	if (!InitPacketProcessingThreads()) {
		return FALSE;
	}

	/* Just to recall: this thread will handle the signals */
	pthread_sigmask(SIG_UNBLOCK, &set, NULL);
	while (pause() != -1);

	return FALSE;
}
Example #2
0
int main()
{	
	signal(SIGHUP, handle_signal);
	signal(SIGINT, handle_signal);
	signal(SIGQUIT, handle_signal);

	pPacketQueue = (SWPacketQueue *)InitPacketQueue();
	
	if (!pPacketQueue)
	{
		exit(1);
	}
	
	pMServer = InitServer(pPacketQueue, PORT);
	
	pWrite = InitAviWrite(pPacketQueue, "test.asf");
	
	
	StartServer(pMServer);
    StartThread(pWrite);
    
    
	while(flag);
    main_exit();	
	return 0;
}