-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.cpp
More file actions
59 lines (52 loc) · 990 Bytes
/
buffer.cpp
File metadata and controls
59 lines (52 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/***************************************************************************
BUFFER.C
***************************************************************************/
#include "buffer.h"
buffer::buffer(){
head=NULL;
last=NULL;
Kqueue = INT_MAX;
count = 0;
status=0;
tot_delay=0.0;
tot_packs=0.0;
tot_lost = 0;
}
// inserisce in coda, estrae dalla testa
void buffer::insert(packet* pack){
if (head == NULL) { // buffer vuoto
head = pack;
last = pack;
last->next = head;
count++;
}
else { // inserimento in coda
if (count <= Kqueue) { //controllo se il buffer non è pieno
last->next = pack;
last = pack;
last->next = head;
count++;
}
else { // buffer pieno
tot_lost++;
}
}
}
packet* buffer::get(){
packet* pack;
if(head==NULL) // buffer vuoto
return NULL;
if(last==head){ // un unico pacchetto
pack=head;
last=NULL;
head=NULL;
count--;
}
else{
pack=head;
head=head->next;
last->next=head;
count--;
}
return pack;
}