Example #1
0
IoEventManager *IoEventManager_proto(void *state)
{
	IoObject *self = IoObject_new(state);
	IoObject_tag_(self, IoEventManager_newTag(state));

	IoObject_setDataPointer_(self, calloc(1, sizeof(IoEventManagerData)));

	DATA(self)->handleEventMessage = IoMessage_newWithName_(state, IOSYMBOL("handleEvent"));
	DATA(self)->activeEvents = List_new();

	IoState_registerProtoWithFunc_((IoState *)state, self, IoEventManager_proto);

	{
		IoMethodTable methodTable[] = {
		{"addEvent", IoEventManager_addEvent},
		{"removeEvent", IoEventManager_removeEvent},

		{"listen", IoEventManager_listen},
		{"listenUntilEvent", IoEventManager_listenUntilEvent},
		{"setListenTimeout", IoEventManager_setListenTimeout},

		{"hasActiveEvents", IoEventManager_hasActiveEvents},
		{"activeEvents", IoEventManager_activeEvents},

		{NULL, NULL},
		};

		IoObject_addMethodTable_(self, methodTable);
	}


//#if !defined(AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER)
#if defined(__APPLE__)
	setenv("EVENT_NOKQUEUE", "1", 1);
	//printf("EventManager warning: disabling libevent kqueue support to avoid bug in OSX < 10.4\n");
	setenv("EVENT_NOPOLL", "1", 1);
	//setenv("EVENT_NOSELECT", "1", 1);
#endif

	DATA(self)->eventBase = event_init();

	//IoEventManager_setDescriptorLimitToMax(self);
	Socket_SetDescriptorLimitToMax();

	return self;
}
Example #2
0
int VertexServer_run(VertexServer *self)
{  	
	Socket_SetDescriptorLimitToMax();
	VertexServer_setupActions(self);
	VertexServer_openLog(self);
	Log_Printf("VertexServer_run\n");
	
	if (self->isDaemon)
	{
		Log_Printf("Running as Daemon\n");
		daemon(0, 0);
		
		if (self->pidPath)
		{
			VertexServer_writePidFile(self);
		}
		else
		{
			Log_Printf("-pid is required when running as daemon\n");
			exit(-1);
		}
	}
	
	VertexServer_registerSignals(self);
		
	if (PDB_open(self->pdb)) 
	{ 
		Log_Printf("unable to open database file\n");
		return -1; 
	}

	HttpServer_run(self->httpServer);
	
	PDB_commit(self->pdb);
	PDB_close(self->pdb);
	
	VertexServer_removePidFile(self);
	
	Log_Printf("shutdown\n\n");
	Log_close();
	return 0;  
}