Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vytor Calixto
Caco
Commits
ac8127be
Commit
ac8127be
authored
9 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Plain Diff
Merge branch 'sliding-window' into develop
Conflicts: Protocol.cpp
parents
bc4a7d8e
b028852a
Branches
Branches containing commit
No related tags found
1 merge request
!1
Lento
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Protocol.cpp
+18
-9
18 additions, 9 deletions
Protocol.cpp
with
18 additions
and
9 deletions
Protocol.cpp
+
18
−
9
View file @
ac8127be
...
@@ -2,6 +2,11 @@
...
@@ -2,6 +2,11 @@
#include
"Protocol.h"
#include
"Protocol.h"
#include
"definitions.h"
#include
"definitions.h"
typedef
struct
{
int
index
;
bool
sent
;
}
FrameItem
;
vector
<
Message
>
Protocol
::
getMessages
(){
vector
<
Message
>
Protocol
::
getMessages
(){
return
messages
;
return
messages
;
}
}
...
@@ -108,26 +113,31 @@ int Protocol::recvMessage(int sockt){
...
@@ -108,26 +113,31 @@ int Protocol::recvMessage(int sockt){
void
Protocol
::
transmit
(
int
sockt
,
int
window
){
void
Protocol
::
transmit
(
int
sockt
,
int
window
){
int
status
;
int
status
;
vector
<
int
>
frame
;
vector
<
FrameItem
>
frame
;
int
lastFramed
=
0
;
int
lastFramed
=
0
;
int
messagesLeft
=
messages
.
size
();
int
messagesLeft
=
messages
.
size
();
bool
shouldSend
=
true
;
Protocol
response
;
Protocol
response
;
while
(
messagesLeft
>
0
){
while
(
messagesLeft
>
0
){
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
frame
.
push_back
(
lastFramed
++
);
// FIXME: this will probably brake with many messages
if
(
shouldSend
)
sendMessage
(
sockt
,
frame
[
j
]);
FrameItem
fi
=
{.
index
=
lastFramed
++
,
.
sent
=
false
};
frame
.
push_back
(
fi
);
if
(
!
frame
[
j
].
sent
){
sendMessage
(
sockt
,
frame
[
j
].
index
);
frame
[
j
].
sent
=
true
;
}
}
}
// TODO: timeout
// TODO: timeout
status
=
response
.
recvMessage
(
sockt
);
status
=
response
.
recvMessage
(
sockt
);
cout
<<
"transmit status:"
<<
status
<<
endl
;
cout
<<
"transmit status:"
<<
status
<<
endl
;
shouldSend
=
true
;
if
(
status
==
NACK
){
if
(
status
==
NACK
){
int
nackIndex
=
stoi
(
response
.
getMessages
().
back
().
getDataAsString
());
int
nackIndex
=
stoi
(
getDataAsString
());
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
if
(
frame
[
j
]
<
nackIndex
)
{
if
(
frame
[
j
]
.
index
<
nackIndex
)
{
frame
.
erase
(
frame
.
begin
()
+
j
);
frame
.
erase
(
frame
.
begin
()
+
j
);
--
messagesLeft
;
--
messagesLeft
;
}
else
if
(
frame
[
j
].
index
==
nackIndex
)
{
frame
[
j
].
sent
=
false
;
}
}
}
}
response
.
reset
();
response
.
reset
();
...
@@ -135,7 +145,7 @@ void Protocol::transmit(int sockt, int window){
...
@@ -135,7 +145,7 @@ void Protocol::transmit(int sockt, int window){
}
else
if
(
status
==
ACK
){
}
else
if
(
status
==
ACK
){
int
ackIndex
=
stoi
(
response
.
getMessages
().
back
().
getDataAsString
());
int
ackIndex
=
stoi
(
response
.
getMessages
().
back
().
getDataAsString
());
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
if
(
frame
[
j
]
<=
ackIndex
)
{
if
(
frame
[
j
]
.
index
<=
ackIndex
)
{
frame
.
erase
(
frame
.
begin
()
+
j
);
frame
.
erase
(
frame
.
begin
()
+
j
);
--
messagesLeft
;
--
messagesLeft
;
}
}
...
@@ -150,7 +160,6 @@ void Protocol::transmit(int sockt, int window){
...
@@ -150,7 +160,6 @@ void Protocol::transmit(int sockt, int window){
// cout << "Remoto:\n" << ((status == ERROR)?"ERROR: ":"") << getDataAsString() << endl;
// cout << "Remoto:\n" << ((status == ERROR)?"ERROR: ":"") << getDataAsString() << endl;
}
else
{
}
else
{
//TODO: treat error
//TODO: treat error
shouldSend
=
false
;
}
}
}
}
reset
();
reset
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment