memory leak fixed

This commit is contained in:
Dhanya Maliakal
2015-11-12 13:49:09 +01:00
parent 24438419d5
commit 53f11c499d
4 changed files with 77 additions and 83 deletions

View File

@ -78,8 +78,10 @@ int CircularFifo<Element>::getSemValue()
template<typename Element>
bool CircularFifo<Element>::push(Element*& item_)
{
//cout<<"*head:"<<head<<endl;
//cout<<"*tail before"<<tail<<endl;
unsigned int nextTail = increment(tail);
//cout<<"*next tail"<<nextTail<<endl;
if(nextTail != head)
{
array[tail] = item_;
@ -101,12 +103,15 @@ bool CircularFifo<Element>::push(Element*& item_)
template<typename Element>
bool CircularFifo<Element>::pop(Element*& item_)
{
// if(head == tail)
// return false; // empty queue
//cout<<"-tail:"<<tail<<endl;
//cout<<"-head before:"<<head<<endl;
//if(head == tail)
// return false; // empty queue
sem_wait(&free_mutex);
item_ = array[head];
head = increment(head);
//cout<<"-head after:"<<head<<endl;
return true;
}

View File

@ -580,43 +580,43 @@ typedef struct
int ReceiveDataOnly(void* buf,int length=0){
if (buf==NULL) return -1;
total_sent=0;
switch(protocol) {
case TCP:
if (file_des<0) return -1;
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
nsent = read(file_des,(char*)buf+total_sent,nsending);
if(!nsent) break;
length-=nsent;
total_sent+=nsent;
}
if (buf==NULL) return -1;
if (total_sent>0)
strcpy(thisClientIP,dummyClientIP);
if (strcmp(lastClientIP,thisClientIP))
differentClients=1;
else
differentClients=0;
total_sent=0;
break;
case UDP:
if (socketDescriptor<0) return -1;
switch(protocol) {
case TCP:
if (file_des<0) return -1;
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
nsent = read(file_des,(char*)buf+total_sent,nsending);
if(!nsent) break;
length-=nsent;
total_sent+=nsent;
}
//if length given, listens to length, else listens for packetsize till length is reached
if(length){
/*int k = 0;*/
if (total_sent>0)
strcpy(thisClientIP,dummyClientIP);
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
/*
if (strcmp(lastClientIP,thisClientIP))
differentClients=1;
else
differentClients=0;
break;
case UDP:
if (socketDescriptor<0) return -1;
//if length given, listens to length, else listens for packetsize till length is reached
if(length){
/*int k = 0;*/
while(length>0){
nsending = (length>packet_size) ? packet_size:length;
/*
//created for debugging on 11.05.2015
nsending=5000;
nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
@ -632,33 +632,32 @@ typedef struct
}
else
k++;
*/
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
if(!nsent) break;
length-=nsent;
total_sent+=nsent;
}
}
//listens to only 1 packet
else{
//normal
nsending=packet_size;
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
total_sent+=nsent;
}
break;
default:
;
}
*/
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
if(!nsent) break;
length-=nsent;
total_sent+=nsent;
}
}
//listens to only 1 packet
else{
//normal
nsending=packet_size;
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
//nsent = 1040;
total_sent+=nsent;
}
break;
default:
;
}
#ifdef VERY_VERBOSE
cout << "sent "<< total_sent << " Bytes" << endl;
cout << "sent "<< total_sent << " Bytes" << endl;
#endif
return total_sent;
return total_sent;
}
@ -714,21 +713,12 @@ typedef struct
protected:
communicationProtocol protocol;
int is_a_server;
int socketDescriptor;
int file_des;
int packet_size;
struct sockaddr_in clientAddress, serverAddress;
socklen_t clientAddress_length;
char dummyClientIP[INET_ADDRSTRLEN];

View File

@ -111,7 +111,7 @@
#define EIGER_MAX_PORTS 2
#define EIGER_HEADER_LENGTH 48
#define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000
#define EIGER_FIFO_SIZE 100
/*#define EIGER_ALIGNED_FRAME_SIZE 65536*/
#define EIGER_ONE_GIGA_CONSTANT 16
#define EIGER_TEN_GIGA_CONSTANT 4