Exemplo n.º 1
0
static void dispose_event(int fd){
	eventTotal++;
	if(fd == raw_sock){
		retrieve_raw_sockets(fd);
	}else{
		struct receiver_msg_st * msg = msg_copyer_recv(fd);
		if(NULL == msg ){
			fprintf(stderr,"socket error:\n");
			exit(1);
		}   
		//it changes source port for this packet
		(msg->tcp_header).source=remote_port;
		//it is tricked as if from tested machine
#if (MULTI_THREADS)  
		putPacketToPool((const char*)msg,sizeof(receiver_msg_st));
#else
		process((char*)msg);
#endif
	}   
	if((eventTotal%1000000)==0)
	{
		//retrieve memory usage by this process
		//if more than 0.5G,then suicide
		int pid=getpid();
		char path[512];
		sprintf(path,"/proc/%d/status",pid);
		checkMemoryUsage(path);
	}
}
Exemplo n.º 2
0
void MemMan::alloc(MemHandle *bsMem, uint32 pSize, uint16 pCond) {
	_alloced += pSize;
	bsMem->data = (void*)malloc(pSize);
	if (!bsMem->data)
		error("MemMan::alloc(): Can't alloc %d bytes of memory.", pSize);
	bsMem->cond = pCond;
	bsMem->size = pSize;
	if (pCond == MEM_CAN_FREE) {
		warning("%d Bytes alloced as FREEABLE.", pSize); // why should one want to alloc mem if it can be freed?
		addToFreeList(bsMem);
	} else if (bsMem->next || bsMem->prev) // it's in our _freeAble list, remove it from there
		removeFromFreeList(bsMem);
	checkMemoryUsage();
}