示例#1
0
/* 
 * Consumer thread function. 
 */
DWORD Consumer( LPVOID lpParam )
{
    int n = 0;
    int ret;

    while (n < NUM_OF_CYCLES)
    {
        if (bProdErr == TRUE)
        {
            /* The consumer ran into an error so we'll stop */
            return 0;
        }

        ret = EmptyBuffer();

        if (ret == OP_OK)
        {
            n++;
        }
        else if (ret == OP_ERR)
        {
            bConErr = TRUE;
            return 0;
        }
    }

    return 0;
}
示例#2
0
文件: ogg.cpp 项目: pilkch/library
    void cOggStream::Release()
    {
      alSourceStop(source);
      EmptyBuffer();
      alDeleteSources(1, &source);
      ReportError();
      alDeleteBuffers(BUFFER_NUMBER, buffers);
      ReportError();

      ov_clear(&oggStream);
    }
示例#3
0
/* ChopParm: return parm chopped to st and end. end = 0 means all */
ParmBuf ChopParm(ParmBuf b, HTime start, HTime end, HTime sampRate)
{  
   int stObs, endObs, nObs, i;
   HTime length;
   short swidth[SMAX];
   Boolean eSep;
   ParmBuf cb;
   Observation o;
   BufferInfo info;

   length =  ObsInBuffer(b) * sampRate;
   ClampStEn(length,&start,&end);
   if(start >= length)
      HError(1030,"ChopParm: Src file too short to get data from %.0f",start);
   if(trace & T_SEGMENT)
      printf("ChopParm: Extracting segment %.0f to %.0f\n",start,end);
   stObs = (int) (start/sampRate);
   endObs = (int) (end/sampRate);
   nObs = endObs -stObs;
   if(nObs <= 0)
      HError(1030,"ChopParm: Truncation options result in zero-length file");
   GetBufferInfo(b,&info);
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&cStack, swidth, info.tgtPK, saveAsVQ, eSep);
   if (saveAsVQ){
      if (info.tgtPK&HASNULLE){
         info.tgtPK=DISCRETE+HASNULLE;
      }else{
         info.tgtPK=DISCRETE;
      }
   }
   cb =  EmptyBuffer(&cStack, nObs, o, info);
   for (i=stObs; i < endObs; i++){
      ReadAsTable(b, i, &o);
      AddToBuffer(cb, o);
   }
   CloseBuffer(b);
   if(chopF && labF) ChopLabs(tr,start,end);
   return(cb);
}
示例#4
0
/* OpenParmFile: open source parm file and return length */
HTime OpenParmFile(char *src)
{
   int i;
   ParmBuf b, cb;
   short swidth[SMAX];
   Boolean eSep;
   Observation o;
   BufferInfo info;

   if((b =  OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL)
      HError(1050,"OpenParmFile: Config parameters invalid");
   GetBufferInfo(b,&info);
   srcSampRate = info.srcSampRate;
   tgtSampRate = info.tgtSampRate;
   srcPK = info.srcPK; tgtPK = info.tgtPK;
   cb = chopF?ChopParm(b,st,en,info.tgtSampRate):b;
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&oStack, swidth, info.tgtPK, saveAsVQ, eSep);
   if (saveAsVQ){
      if (info.tgtPK&HASNULLE){
         info.tgtPK=DISCRETE+HASNULLE;
      }else{
         info.tgtPK=DISCRETE;
      }
   }
   pb =  EmptyBuffer(&oStack, ObsInBuffer(cb), o, info);
   for(i=0; i < ObsInBuffer(cb); i++){
      ReadAsTable(cb, i, &o);
      AddToBuffer(pb, o);
   }
   CloseBuffer(cb);
   if( info.nSamples > 0 )
      return(info.nSamples*srcSampRate);
   else
      return(ObsInBuffer(pb)*info.tgtSampRate);
}
void StreamService::FillEmptyBuffer(const StreamBuffer& buffer)
{
	StreamBuffer* emptyBuff = EmptyBuffer();
	AerAssert(emptyBuff != nullptr);
	*emptyBuff = buffer;
}
示例#6
0
int main(int argc, char *argv[])
{
		int input=6, output=6;
		char octal_buff[SIZE];
		char hexa_buff[SIZE];
		char ascii_buff[SIZE];
		char char_buff[SIZE];
		char buffer[SIZE];
		while (input > 5)
		{
			puts("-------------------------------------------------------");
			puts("\tSelect input:\t");
			puts("\t\t1 - Octal");
			puts("\t\t2 - Hexadecimal");
			puts("\t\t3 - ASCII Char");
			puts("\t\t4 - Char\n");
			puts("-------------------------------------------------------");
		
			printf("Choice Input: ");
			scanf("%d",&input);
			EmptyBuffer();
		}
		while (output > 5)
		{
			puts("-------------------------------------------------------");
			puts("\tSelect output:\t");
			puts("\t\t1 - Octal");
			puts("\t\t2 - Hexadecimal");
			puts("\t\t3 - ASCII Char");
			puts("\t\t4 - Char\n");
			puts("-------------------------------------------------------");
		
			printf("Choice Output: ");
			scanf("%d",&output);
			EmptyBuffer();
		
		}
		
		//Octal Input
		if(input ==1)
		{
			if(output == 1)
			{
				puts("Bitche I do not convert it !");
			}
			
			printf("Input octal: ");
			read(buffer);
			strcpy(octal_buff,buffer);
			if(output==2)
			{
				OcToHex(octal_buff,hexa_buff);
			}
			if(output==3)
			{
				OcToAscii(octal_buff,ascii_buff);
			}
			if(output==4)
			{
				OcToChar(octal_buff,char_buff);
			}
		}
		//Hexadecimal Input
		if(input == 2)
		{
			if(output==2)
			{
				puts("You want to suck ?");
			}
			
			printf("Input Hexadecimal: ");
			read(buffer);
			strcpy(hexa_buff,buffer);
			if(output==1)
			{
				HexToOct(hexa_buff,octal_buff);
			}
			if(output==3)
			{
				HexToAscii(hexa_buff,ascii_buff);
			}
			if(output==4)
			{
				HexToChar(hexa_buff,char_buff);
			}
		}
		//Ascii Input
		if(input == 3)
		{
			if(output==3)
			{
				puts("Kill yourself -->[-]");
			}
			
			printf("Input Ascii: ");
			read(buffer);
			strcpy(ascii_buff,buffer);
			
			if(output==1)
			{
				AsciiToOct(ascii_buff,octal_buff);
			}
			if(output==2)
			{
				AsciiToHex(ascii_buff,hexa_buff);
			}
			if(output==4)
			{
				AsciiToChar(ascii_buff,char_buff);
			}
		}
		//Char Input
		if(input == 4)
		{
			if(output==4)
			{
				puts("Exile you in /dev/null !!!");
			}
			
			printf("Input Char: ");
			read(buffer);
			strcpy(char_buff,buffer);
			
			if(output==1)
			{
				CharToOct(char_buff,octal_buff);
			}
			if(output==2)
			{
				CharToHex(char_buff,hexa_buff);
			}
			if(output==3)
			{
				CharToAscii(char_buff,ascii_buff);
			}
		}

	return 0;
}	
示例#7
0
////////////////////////////////////////
////////////////////////////////////////
// This Proc assumes that all the records in pDB has a common Prefix PrefixSeq with lenght of PrefixLen.
// It creates and returns projected db for that common prefix.
//struct PROJ_DB * MakeProjDB123( const struct PROJ_DB* pDB, Prefix * aPrefix )
struct PROJ_DB * MakeProjDBFromOrg(  const struct mem_map * pDB, Prefix * aPrefix, long nCount )
{
	int * PostStart = NULL;
	SeqWrap * aSeqWrap = NULL;
	//int * RecEnd;
	int * tmpPtr = NULL;
	int i = 0;
	int j = 0;
	int tmp = 0;
	int PatLen = 0;
	int Sup = 0;
	struct PROJ_DB * ProjDB = NULL;
	struct PROJ_SEQ * tmpSeq = NULL;


	tmp = sizeof( struct PROJ_DB );
	n_total_mem += tmp;
  ProjDB = (struct PROJ_DB*) memalloc(tmp);

	PatLen = (*aPrefix).Size();


	(*ProjDB).m_nPatLen = PatLen;

	// Copy the prefix of pDB to ProjDB's prefix.
	tmp = PatLen * sizeof(int);
	n_total_mem += tmp;
  (*ProjDB).m_pnPat = (int*) memalloc(tmp);

	// Add aPrefix to ProjDB's prefix.
	tmpPtr = (*aPrefix).GetFirst();
	while( *tmpPtr < 0 && tmpPtr < (*aPrefix).End )
		tmpPtr = GetNextItem( tmpPtr+1 ); // Get first frequent item.

	for( i = 0; i<PatLen; i++ )
	{
		(*ProjDB).m_pnPat[i] = (int) *tmpPtr;
		tmpPtr = (*aPrefix).GetNext();
	}

	(*ProjDB).m_nMaxSup = nCount;
	tmp = nCount * sizeof( struct PROJ_SEQ );
	n_total_mem += tmp;
	(*ProjDB).m_pProjSeq = (struct PROJ_SEQ*) memalloc( tmp );
	memset( (*ProjDB).m_pProjSeq, 0, tmp );
	(*ProjDB).m_nVer = -1;
	(*ProjDB).m_nSup = 0;

//'''''''''''''''''''''''''''''''''''''''

  int * RecStart = (int*) GetStartOfMap( pDB );
  int *LastAddr = (int*) GetLastAddrOfMap( pDB );

	while( RecStart < LastAddr )
	{
		aSeqWrap = new SeqWrap( RecStart );

		if( !(*aSeqWrap).IsEmpty() )
		{
			Sup++;

			PostStart = (*aSeqWrap).GetItemSet( (*aPrefix).NumOfItemSets );

			if( !SeqIsEmpty( PostStart ) )
			{
				tmpSeq = (struct PROJ_SEQ *) (*ProjDB).m_pProjSeq + (*ProjDB).m_nSup;
				(*ProjDB).m_nSup++;

				(*tmpSeq).m_nProjCount = 1;

				(*tmpSeq).m_ppSeq = (int**) PostStart;
			}
		
		}
		delete aSeqWrap;

		RecStart = GetEndPtr(RecStart) + 1;
	}


#if defined( _USE_OUTPUT_BUFFER )
	(*ProjDB).OutputBuf = OutputPattern( (*ProjDB).m_pnPat, PatLen, Sup );
#else
	OutputPattern( (*ProjDB).m_pnPat, PatLen, Sup );
#endif


	if( (*ProjDB).m_nSup < gSUP  )
	{

		//Added by Ramin
#if defined( _USE_OUTPUT_BUFFER )
				//fprintf( gpFreqFile, "+++===>>>>>>  Right Pattern  " );
				//(*(*ProjDB).OutputBuf).Print( gpFreqFile );
				EmptyBuffer( aSeqList, (*ProjDB).OutputBuf );
#else
				if( n_max_mem < n_total_mem )
					n_max_mem = n_total_mem;
#endif
#if defined( _FIND_MAX_SEQS ) && !defined( _DO_NAIVE_APPROACH )
				//Sequence * aSeq = new Sequence( (*ProjDB).m_pnPat, (*ProjDB).m_nPatLen, (*ProjDB).m_nSup );
				Sequence * aSeq = new Sequence( ProjDB, Sup );
				(*MainSeqTree).AddSeq( aSeq );
#endif


		tmp = (*ProjDB).m_nMaxSup * sizeof( struct PROJ_SEQ );
		n_total_mem -= tmp;
		freemem( (void**) &(*ProjDB).m_pProjSeq );

		tmp = PatLen * sizeof(int);
		n_total_mem -= tmp;
		freemem( (void**)&((*ProjDB).m_pnPat) );

		n_total_mem -= sizeof( struct PROJ_DB );
	  freemem( (void**)&(ProjDB) );
		return NULL;
	} else
		return ProjDB;
}
示例#8
0
// This Proc assumes that all the records in pDB has a common Prefix PrefixSeq with lenght of PrefixLen.
// It creates and returns projected db for that common prefix.
struct PROJ_DB * MakeProjDB( const struct PROJ_DB* pDB, Prefix * aPrefix )
{
	int * PostStart = NULL;
	SeqWrap * aSeqWrap = NULL;
	//int * RecEnd;
	int * tmpPtr = NULL;
	int i = 0;
	int j = 0;
	int tmp = 0;
	int PatLen = 0;
	int Sup = 0;
	struct PROJ_DB * ProjDB = NULL;
	struct PROJ_SEQ * tmpSeq = NULL;

//	RTATest( pDB );
//	if( (*pDB).m_nPatLen>2 && (*pDB).m_pnPat[0] == 33 && (*pDB).m_pnPat[2] == 56  )
//		printf( " werwrwrwrewerwrwrwrwer\n" );

	//if( (*pDB).m_nPatLen>4 && (*pDB).m_pnPat[0] == 867 && (*pDB).m_pnPat[2] == 92 && (*pDB).m_pnPat[4] == 631 )
	//	printf( " werwrwrwrewerwrwrwrwer\n" );



	tmp = sizeof( struct PROJ_DB );
	n_total_mem += tmp;
  ProjDB = (struct PROJ_DB*) memalloc(tmp);

	PatLen = (*aPrefix).Size() + (*pDB).m_nPatLen;


	(*ProjDB).m_nPatLen = PatLen;

	// Copy the prefix of pDB to ProjDB's prefix.
	tmp = PatLen * sizeof(int);
	n_total_mem += tmp;
  (*ProjDB).m_pnPat = (int*) memalloc(tmp);
	if( (*pDB).m_nPatLen == 1 ) 
		(*ProjDB).m_pnPat[0] = (int) (*pDB).m_pnPat;
	else
		memcpy( (*ProjDB).m_pnPat, (*pDB).m_pnPat, (*pDB).m_nPatLen * sizeof(int) );

	// Add aPrefix to ProjDB's prefix.
	tmpPtr = (*aPrefix).GetFirst();

	for( i = (*pDB).m_nPatLen; i<PatLen; i++ )
	{
		(*ProjDB).m_pnPat[i] = (int) *tmpPtr;
		tmpPtr = (*aPrefix).GetNext();
	}

	(*ProjDB).m_nMaxSup = (*pDB).m_nSup;
	tmp = (*pDB).m_nSup * sizeof( struct PROJ_SEQ );
	n_total_mem += tmp;
	(*ProjDB).m_pProjSeq = (struct PROJ_SEQ*) memalloc( tmp );
	memset( (*ProjDB).m_pProjSeq, 0, tmp );
	(*ProjDB).m_nVer = -1;
	(*ProjDB).m_nSup = 0;


	int JMax = 1;
	int PrjCnt;
	bool Inter;
	bool IncSup;
	if( *(*aPrefix).GetFirst() == -1 )
		Inter = true;
	else
		Inter = false;

	#if defined( _USE_STRING_ELEMINATION )
	bool CheckStrings = false;
	if( (*MainSeqTree).IsContained( new Sequence(pDB) ) )
	{
		CheckStrings = true;
	}

	#endif // defined( _USE_STRING_ELEMINATION )

	for( i=0; i<(*pDB).m_nSup; i++ ) // For every seq in DB
	{

		 
		PrjCnt = 0;
		if( !Inter )
			JMax = (*pDB).m_pProjSeq[i].m_nProjCount;


		IncSup = true;

		#if defined( _USE_STRING_ELEMINATION )
		//if( (*MainSeqTree).IsContained( pDB, (*aSeqWrap).GetFirst() ) )
		if( CheckStrings )
		{
			if( (*MainSeqTree).IsContained( pDB, GetStartPtr( pDB, i) ) )
			{
				//Sequence * aS = new Sequence( pDB, GetStartPtr( pDB, i) );
				//(*aS).Print();
				//printf( " Sequence Eleminated.\n" );
				continue;
			}
		}
		#endif // defined( _USE_STRING_ELEMINATION )

		for( j=0; j < JMax; j++ ) 
		{
			aSeqWrap = new SeqWrap( GetStartPtr( pDB, i, j ) );

			if( !(*aSeqWrap).IsEmpty() )
			{


				if( IncSup )
				{
					Sup++;
					IncSup = false;
				}

				PostStart = (*aSeqWrap).GetItemSet( (*aPrefix).NumOfItemSets );
/*
				Sequence * aSeq = NULL;
				aSeq = new Sequence( GetStartPtr( pDB, i ), false );
				printf( "Rec:\n  " );
				(*aSeq).Print();
				delete aSeq;
				aSeq = new Sequence( PostStart, false );
				printf( "Post:\n  " );
				(*aSeq).Print();
				delete aSeq;
*/

				if( !SeqIsEmpty( PostStart ) )
				{
					buf_idx[ PrjCnt++ ] = int( PostStart );
				}
			
			}
			delete aSeqWrap;
		}
		if( PrjCnt > 0 )
		{
			tmpSeq = (struct PROJ_SEQ *) (*ProjDB).m_pProjSeq + (*ProjDB).m_nSup;
			(*ProjDB).m_nSup++;
			(*tmpSeq).m_nProjCount = PrjCnt;
			if( PrjCnt == 1 )
			{
				(*tmpSeq).m_ppSeq = (int**) buf_idx[0];
			} else {
				tmp = PrjCnt * sizeof(int);
				n_total_mem += tmp;
				(*tmpSeq).m_ppSeq = (int**) memalloc( tmp );
				memcpy( (*tmpSeq).m_ppSeq, buf_idx, tmp );
			}
		}
	}

#if defined( _USE_OUTPUT_BUFFER )
	(*ProjDB).OutputBuf = OutputPattern( (*ProjDB).m_pnPat, PatLen, Sup );
	(*(*ProjDB).OutputBuf).Parent = (*pDB).OutputBuf;
	(*(*pDB).OutputBuf).ReferenceCount++;
#else
	OutputPattern( (*ProjDB).m_pnPat, PatLen, Sup );
#endif


	if( (*ProjDB).m_nSup < gSUP  )
	{

		//Added by Ramin
#if defined( _USE_OUTPUT_BUFFER )
				//fprintf( gpFreqFile, "+++===>>>>>>  Right Pattern  " );
				//(*(*ProjDB).OutputBuf).Print( gpFreqFile );
				EmptyBuffer( aSeqList, (*ProjDB).OutputBuf );
#else
				if( n_max_mem < n_total_mem )
					n_max_mem = n_total_mem;
#endif
#if defined( _FIND_MAX_SEQS ) && !defined( _DO_NAIVE_APPROACH )
				//Sequence * aSeq = new Sequence( (*ProjDB).m_pnPat, (*ProjDB).m_nPatLen, (*ProjDB).m_nSup );
				Sequence * aSeq = new Sequence( ProjDB, Sup );
				(*MainSeqTree).AddSeq( aSeq );
#endif


		tmp = (*ProjDB).m_nMaxSup * sizeof( struct PROJ_SEQ );
		n_total_mem -= tmp;
		freemem( (void**) &(*ProjDB).m_pProjSeq );

		tmp = PatLen * sizeof(int);
		n_total_mem -= tmp;
		freemem( (void**)&((*ProjDB).m_pnPat) );

		n_total_mem -= sizeof( struct PROJ_DB );
	  freemem( (void**)&(ProjDB) );
		return NULL;
	} else
		return ProjDB;
}
示例#9
0
文件: Task3R.c 项目: nbogdan/Homework
int Task3()
{
	pkg myPkg;
	msg* mesajDuplicat;
	msg t, aux;	
	char* filename;

	int window, k;
	int* NAKArray; /* vector in care retinem packNum-ul pachetelor care nu pot fi confirmate*/
	int superior = MAX_VALUE; /* limita superioara a numarului de pachete; 
					folosit in constructia NAKArray */
	
	int current = 0, last = 0, currentAux = 0, i = 0;
	
	int fdOut;
	int res;
	TLista bufferMesaje;
	int currentPack = 0;
	
	printf("[RECEIVER]Receiver starts.\n");
	printf("[RECEIVER]Task index=%i\n", 3);
		
	/* asteptare mesaj initializare */
	do
	{
		if (recv_message(&t) < 0) {
			printf("[RECEIVER] receive message");
			return -1;
		}
		printf("-----------------------------------------\n");
		printf("[RECEIVER]Receiving init message.\n");
	}while(msgCheckSum(t) != 0);

	/* initializare */
	myPkg = *((pkg*)t.payload);
	printf("[RECEIVER] Got msg with payload: %s\n", myPkg.payload);
	
	window = myPkg.packNum;
	
	NAKArray = (int*)calloc(window + 1, sizeof(int));
	if(myPkg.messageType != TYPE_INIT){
		perror("[RECEIVER]Didn't receive init file!\n");
	}
	sprintf(aux.payload, "ACK(%s)", myPkg.payload);
	aux.len = strlen(aux.payload + 1);
	send_message(&aux);
	
	/* deschidere fisier out */
	filename = strdup("recv_");
	strcat(filename, myPkg.payload);
	fdOut = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
	
	/*scriere in fisier pe masura ce se primesc pachetele.*/
	printf("Commence filewriting.\n");
	
	/* initializam NAKArray, salvand numele primelor window pachete care sunt asteptate */
	/* imediat ce un pachet este primit, el este sters din NAKArray, si urmatorul pachet 
	asteptat este trecut in locul lui */
	for(k = 0; k < window; k++)
		NAKArray[k] = k;
	
	/* initializare indice pachet curent */
	currentPack = 0;
	while(1) {
		/* curatare msg */
		memset(&myPkg, 0, sizeof(pkg));
		memset(&t, 0, sizeof(msg));
		
		res = recv_message(&t);
		myPkg = *((pkg*)t.payload);
		
		if (res < 0) {
				perror("[RECEIVER]Send ACK error. Exiting.\n");
				return -1;
			}
			
		if(msgCheckSum(t) != 0)
			{
				printf("[RECEIVER]Received corrupt message number: %i\n", myPkg.packNum);
				continue;
			}	
		
		printf("[RECEIVER]Received message number: %i\n", myPkg.packNum);
		
		/* daca pachetul final a fost primit, marcam o limita superioara pentru elementele
		din NAKArray */		
		if(myPkg.messageType == TYPE_END)
			superior = myPkg.packNum;	
		
		int auxiliar = 0;/* variabila folosita doar in cazul acestui ciclu */
		/* daca toate pachetele asteptate sunt "fictive" (numar de ordine mai mare decat
		al pachetului final, ne oprim) */
		for(i = 0; i < window; i++)
		{
			if(superior >= NAKArray[i])
				auxiliar = 1;
		}
		if(!auxiliar)
			break;
		
		/* daca pachetul primit se afla in lista de pachete asteptate */
		if(find(NAKArray, window, myPkg.packNum) >= 0)
		{
			/* salvam indicele ultimului pachet primit */
			last = current;
			/* retinem indicele pachetului curent*/
			current = find(NAKArray, window, myPkg.packNum);
			/* daca exista pachete neconfirmate intre ultimul pachet primit si 
			cel curent, trimitem NAK-uri pentru acestea*/
			if(current - last > 1)
				do{
					last++;
					printf("[RECEIVER]NACK Requestfor %i.\n", NAKArray[last]);
					sprintf(aux.payload, "NACK Pachet numarul: (%d)", NAKArray[last]);
					aux.len = strlen(aux.payload + 1);
					(*(pkg*)aux.payload).packNum = NAKArray[last];
					(*(pkg*)aux.payload).messageType = TYPE_NACK;
					
					res = send_message(&aux);
					if (res < 0) {
						perror("[RECEIVER]Send NACK error. Exiting.\n");
						return -1;
					}
				}while(current - last > 1);
			/* sunt analizate mai multe cazuri de pozitionare pentru last si current*/
			else if(last - current > 0)
			{
			
				currentAux = last + 1;
				while(currentAux < window)
				{	
					printf("[RECEIVER]NACK Request for %i\n", NAKArray[currentAux]);
					sprintf(aux.payload, "NACK Pachet numarul: (%d)", NAKArray[currentAux]);
					aux.len = strlen(aux.payload + 1);
					(*(pkg*)aux.payload).packNum = NAKArray[currentAux];
					(*(pkg*)aux.payload).messageType = TYPE_NACK;
					
					res = send_message(&aux);
					if (res < 0) {
						perror("[RECEIVER]Send NACK error. Exiting.\n");
						return -1;
					}
					currentAux++;
				}
				i = 0;
				while(i < current){
					printf("[RECEIVER]NACK Request for %i\n", NAKArray[i]);
					sprintf(aux.payload, "NACK Pachet numarul: (%d)", NAKArray[i]);
					aux.len = strlen(aux.payload + 1);
					(*(pkg*)aux.payload).packNum = NAKArray[i];
					(*(pkg*)aux.payload).messageType = TYPE_NACK;
					
					res = send_message(&aux);
					if (res < 0) {
						perror("[RECEIVER]Send NACK error. Exiting.\n");
						return -1;
					}
					i++;
				}
				
			}
			
			
			printf("[RECEIVER]Received correct package. Sending ACK.\n");

			/* pachetul primit este stocat in buffer, fiind inserat la pozitia corecta*/
			mesajDuplicat = mesageDup(&t);
			InsOrd(&bufferMesaje, mesajDuplicat);
			
			/* afisam mesajele consecutive, pornind de la currentPack, salvate in buffer */
			/* ex: Avem mesajele 3,4,5,7,9,10,11 si currentPack = 3
				Se vor scrie mesajele 3, 4, 5, iar currentPack devine 6 */
			currentPack += EmptyBuffer(&bufferMesaje, fdOut, currentPack);
			sprintf(aux.payload, "ACK Pachet numarul: (%d)", myPkg.packNum);
			aux.len = strlen(aux.payload + 1);
			(*(pkg*)aux.payload).packNum = myPkg.packNum;
			(*(pkg*)aux.payload).messageType = TYPE_ACK;
			
			res = send_message(&aux);
			if (res < 0) {
				perror("[RECEIVER]Send ACK error. Exiting.\n");
				return -1;
			}
			
			/* elementul confirmat il stergem din NAKArray, si inseram urmatorul element
			asteptat */
			i = find(NAKArray, window, myPkg.packNum);
			NAKArray[i] = k++;
		}
		/* Daca pachetul primit nu este dintre cele asteptate, il ignoram si trimitem 
		un NACK, pentru unul din pachetele asteptate*/
		else{
			int myAux;
			for(i = current + 1; i < window; i++)
			if(NAKArray[i] < superior)
			{
				myAux = i;
				printf("[RECEIVER]NACK Request for %i\n", NAKArray[myAux]);
				sprintf(aux.payload, "NACK Pachet numarul: (%d)", NAKArray[myAux]);
				aux.len = strlen(aux.payload + 1);
				(*(pkg*)aux.payload).packNum = NAKArray[myAux];
				(*(pkg*)aux.payload).messageType = TYPE_NACK;
			
				res = send_message(&aux);
				if (res < 0) {
					perror("[RECEIVER]Send NACK error. Exiting.\n");
					return -1;
				}
				break;}
			
			printf("[RECEIVER]Bizzare package received.\n");

		}
	}
		
	/* confirmare sfarsit date */
	sprintf((*(pkg*)aux.payload).payload, "ACK Pachet final");
	aux.len = strlen(aux.payload + 1);
	(*(pkg*)aux.payload).packNum = myPkg.packNum;	
	res = send_message(&aux);
	
	free(NAKArray);
	printf("[RECEIVER]All done.\n");
	close(fdOut);
	return 0;
}