Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
redes1-trabalho1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Eduardo Machado
redes1-trabalho1
Commits
d92c0afa
Commit
d92c0afa
authored
9 years ago
by
Eduardo Machado
Browse files
Options
Downloads
Patches
Plain Diff
Arrumadoinicializador de mensagem
parent
4a560ea6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/messages.cpp
+10
-1
10 additions, 1 deletion
src/messages.cpp
with
10 additions
and
1 deletion
src/messages.cpp
+
10
−
1
View file @
d92c0afa
...
...
@@ -12,7 +12,7 @@ int Message::sendMessage(unsigned char* stringMessage){
unsigned
char
*
mesgReturn
;
// mensagem que recebe de retorno (ack, erro, etc)
char
*
receiptMessage
=
(
char
*
)
malloc
(
sizeof
(
char
*
)
*
64
);
char
erro1
[
10
],
erro2
[
10
],
sucesso
[
10
],
buffer
[
10
];
struct
pollfd
ufds
[
1
];
struct
pollfd
ufds
[
1
];
// usado para timeout em recv
// Calcula o tamanho da msg
while
(
stringMessage
[
size
]
!=
'\0'
){
...
...
@@ -26,9 +26,11 @@ int Message::sendMessage(unsigned char* stringMessage){
numberOfMessages
=
(
size
/
64
);
}
sizeLastMessage
=
size
%
64
;
// Cria as sub mensagens
SubMessage
subMensagem
[
numberOfMessages
];
// Atribui os tipo
if
(
stringMessage
[
0
]
==
'l'
&&
stringMessage
[
1
]
==
's'
){
tipo
=
0x4
;
}
else
if
(
stringMessage
[
0
]
==
'c'
&&
stringMessage
[
1
]
==
'd'
){
...
...
@@ -41,24 +43,31 @@ int Message::sendMessage(unsigned char* stringMessage){
tipo
=
0xD
;
}
// string usada para dividir a mensagem de entrada e colocar na parte de data das SubMessages
subData
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
64
);
// Divide a mensagem
for
(
i
=
0
;
i
<
numberOfMessages
-
1
;
++
i
){
for
(
j
=
0
;
j
<
64
;
++
j
){
subData
[
j
]
=
stringMessage
[(
i
*
64
)
+
j
];
}
subMensagem
[
i
].
setStartMessage
();
subMensagem
[
i
].
setData
(
subData
,
tipo
,
i
);
}
if
(
sizeLastMessage
){
// Caso a última mensagem não seja completa realoca subData para o tamanho da última mensagem
subData
=
(
unsigned
char
*
)
realloc
(
subData
,
sizeof
(
unsigned
char
)
*
sizeLastMessage
);
for
(
j
=
0
;
j
<
sizeLastMessage
;
++
j
){
subData
[
j
]
=
stringMessage
[(
i
*
64
)
+
j
];
}
subMensagem
[
i
].
setStartMessage
();
subMensagem
[
i
].
setData
(
subData
,
tipo
,
i
);
}
else
{
// Caso contrario continua com o tamanho maior
for
(
j
=
0
;
j
<
64
;
++
j
){
subData
[
j
]
=
stringMessage
[(
i
*
64
)
+
j
];
}
subMensagem
[
i
].
setStartMessage
();
subMensagem
[
i
].
setData
(
subData
,
tipo
,
i
);
}
...
...
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