Fixed minor stuff in code-a5
This commit is contained in:
parent
1f26e9fde1
commit
ea9f19e66c
@ -1,7 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class SlidingWindow {
|
class SlidingWindow {
|
||||||
@ -26,7 +25,8 @@ public:
|
|||||||
sent_frames.push_back(next_frame_to_send);
|
sent_frames.push_back(next_frame_to_send);
|
||||||
next_frame_to_send++;
|
next_frame_to_send++;
|
||||||
cout<<"Sent frame "<<sent_frames.back()<<endl;
|
cout<<"Sent frame "<<sent_frames.back()<<endl;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
cout<<"Window is full. Waiting before sending next frames."<<endl;
|
cout<<"Window is full. Waiting before sending next frames."<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,10 +36,10 @@ public:
|
|||||||
if (frame_number == next_frame_to_receive) {
|
if (frame_number == next_frame_to_receive) {
|
||||||
next_frame_to_receive++;
|
next_frame_to_receive++;
|
||||||
cout<<"Received frame "<<frame_number<<endl;
|
cout<<"Received frame "<<frame_number<<endl;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
cout<<"Received frame "<<frame_number<<", but expected frame "<<next_frame_to_receive<<endl;
|
cout<<"Received frame "<<frame_number<<", but expected frame "<<next_frame_to_receive<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove acknowledged frames from the sent_frames queue
|
// remove acknowledged frames from the sent_frames queue
|
||||||
while (!sent_frames.empty() && sent_frames.front()<=next_frame_to_receive-1) {
|
while (!sent_frames.empty() && sent_frames.front()<=next_frame_to_receive-1) {
|
||||||
sent_frames.erase(sent_frames.begin());
|
sent_frames.erase(sent_frames.begin());
|
||||||
@ -66,7 +66,6 @@ int main() {
|
|||||||
|
|
||||||
while (!window.all_frames_sent() || !window.all_frames_received()) {
|
while (!window.all_frames_sent() || !window.all_frames_received()) {
|
||||||
window.send_frame();
|
window.send_frame();
|
||||||
|
|
||||||
// simulate receiving frames
|
// simulate receiving frames
|
||||||
for (int i=0; i<rand()%3; i++) {
|
for (int i=0; i<rand()%3; i++) {
|
||||||
int frame_number = rand() % total_frames;
|
int frame_number = rand() % total_frames;
|
||||||
|
Loading…
Reference in New Issue
Block a user