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
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
3322ccda
Commit
3322ccda
authored
9 years ago
by
Eduardo Machado
Browse files
Options
Downloads
Patches
Plain Diff
mexendo no get
parent
a168447b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
arc
+0
-0
0 additions, 0 deletions
arc
src/messages.cpp
+63
-45
63 additions, 45 deletions
src/messages.cpp
src/submessages.cpp
+20
-16
20 additions, 16 deletions
src/submessages.cpp
with
83 additions
and
61 deletions
arc
0 → 100644
+
0
−
0
View file @
3322ccda
This diff is collapsed.
Click to expand it.
src/messages.cpp
+
63
−
45
View file @
3322ccda
...
@@ -335,6 +335,9 @@ int Message::sendGET(unsigned char* fileName, char* currentPath){
...
@@ -335,6 +335,9 @@ int Message::sendGET(unsigned char* fileName, char* currentPath){
}
}
}
}
}
}
}
else
{
cout
<<
"Tempo limite de resposta excedido :c
\n
"
<<
endl
;
cout
<<
"TIMEOUT ATINGIDO (messages.cpp::sendPUT)"
<<
endl
;
}
}
}
}
}
}
...
@@ -537,9 +540,9 @@ int Message::receiveLS(unsigned char* options, char* currentPath){
...
@@ -537,9 +540,9 @@ int Message::receiveLS(unsigned char* options, char* currentPath){
int
Message
::
receiveGET
(
unsigned
char
*
fileName
){
int
Message
::
receiveGET
(
unsigned
char
*
fileName
){
char
*
tam
;
char
*
tam
;
unsigned
char
*
dados
;
unsigned
char
*
dados
,
*
fileData
;
int
fileSize
,
rv
,
i
,
success
=
0
;
int
fileSize
,
rv
,
i
,
success
=
0
,
length
;
ifstream
file
;
ifstream
file
In
;
string
temp
,
data
;
string
temp
,
data
;
SubMessage
resposta
,
answer
;
SubMessage
resposta
,
answer
;
struct
pollfd
ufds
[
1
];
struct
pollfd
ufds
[
1
];
...
@@ -554,20 +557,35 @@ int Message::receiveGET(unsigned char* fileName){
...
@@ -554,20 +557,35 @@ int Message::receiveGET(unsigned char* fileName){
send
(
soquete
,
resposta
.
objToString
(),
68
,
0
);
send
(
soquete
,
resposta
.
objToString
(),
68
,
0
);
}
else
{
}
else
{
// Calcula o tamanho do arquivo
// Calcula o tamanho do arquivo
file
.
seekg
(
0
,
ios
::
end
);
// file.seekg (0, ios::end);
fileSize
=
file
.
tellg
();
// fileSize = file.tellg();
file
.
seekg
(
0
,
ios
::
beg
);
// file.seekg (0, ios::beg);
//
// while(getline(file, temp)) {
// data += temp + "\n";
// }
// dados=(unsigned char*)malloc(sizeof(unsigned char)*data.size());
// for(i = 0; i < data.size(); ++i){
// dados[i] = data[i];
// }
while
(
getline
(
file
,
temp
))
{
fileIn
.
open
((
char
*
)
fileName
,
ios
::
binary
);
data
+=
temp
+
"
\n
"
;
}
// Contagem do tamanho do arquivo.
dados
=
(
unsigned
char
*
)
malloc
(
sizeof
(
unsigned
char
)
*
data
.
size
());
fileIn
.
seekg
(
0
,
ios
::
end
);
for
(
i
=
0
;
i
<
data
.
size
();
++
i
){
length
=
fileIn
.
tellg
();
dados
[
i
]
=
data
[
i
];
fileIn
.
seekg
(
0
,
ios
::
beg
);
// Alocação do vetor para a leitura do arquivo.
fileData
=
new
unsigned
char
[
length
];
// Leitura.
for
(
i
=
0
;
i
<
length
;
++
i
){
fileIn
.
read
((
char
*
)
&
fileData
[
i
],
sizeof
(
unsigned
char
));
}
}
// Manda o tamanho do arquivo
// Manda o tamanho do arquivo
sprintf
(
tam
,
"%d"
,
fileSize
);
sprintf
(
tam
,
"%d"
,
length
);
while
(
!
success
){
// Esse while está aqui pois a mensagem pode não chegar e precisar ser reenviada
while
(
!
success
){
// Esse while está aqui pois a mensagem pode não chegar e precisar ser reenviada
resposta
.
setData
((
unsigned
char
*
)
tam
,
9
,
0
);
resposta
.
setData
((
unsigned
char
*
)
tam
,
9
,
0
);
send
(
soquete
,
resposta
.
objToString
(),
resposta
.
getSize
()
+
4
,
0
);
send
(
soquete
,
resposta
.
objToString
(),
resposta
.
getSize
()
+
4
,
0
);
...
...
This diff is collapsed.
Click to expand it.
src/submessages.cpp
+
20
−
16
View file @
3322ccda
...
@@ -13,8 +13,14 @@ void SubMessage::setParity(){
...
@@ -13,8 +13,14 @@ void SubMessage::setParity(){
int
i
,
j
,
bitsParity
[
8
];
int
i
,
j
,
bitsParity
[
8
];
// Alocação da matriz de bits
// Alocação da matriz de bits
bitsMessage
=
new
int
*
[
getSize
()];
bitsMessage
=
new
int
*
[
getSize
()
+
2
];
for
(
i
=
0
;
i
<
getSize
()
;
i
++
){
bitsMessage
[
0
]
=
new
int
[
8
];
bitsMessage
[
1
]
=
new
int
[
8
];
for
(
j
=
0
;
j
<
8
;
j
++
){
bitsMessage
[
0
][
j
]
=
((((
sizSeqTyp
>>
8
)
&
0x00FF
)
>>
(
7
-
j
))
&
0x01
);
bitsMessage
[
1
][
j
]
=
((((
sizSeqTyp
>>
0
)
&
0x00FF
)
>>
(
7
-
j
))
&
0x01
);
}
for
(
i
=
2
;
i
<
getSize
()
+
2
;
i
++
){
bitsMessage
[
i
]
=
new
int
[
8
];
bitsMessage
[
i
]
=
new
int
[
8
];
// Divide os dados em bits
// Divide os dados em bits
for
(
j
=
0
;
j
<
8
;
j
++
){
for
(
j
=
0
;
j
<
8
;
j
++
){
...
@@ -25,7 +31,7 @@ void SubMessage::setParity(){
...
@@ -25,7 +31,7 @@ void SubMessage::setParity(){
// Soma os bits verticalmente
// Soma os bits verticalmente
for
(
j
=
0
;
j
<
8
;
j
++
){
for
(
j
=
0
;
j
<
8
;
j
++
){
bitsParity
[
j
]
=
0
;
bitsParity
[
j
]
=
0
;
for
(
i
=
0
;
i
<
getSize
()
;
i
++
){
for
(
i
=
0
;
i
<
getSize
()
+
2
;
i
++
){
bitsParity
[
j
]
=
bitsParity
[
j
]
+
bitsMessage
[
i
][
j
];
bitsParity
[
j
]
=
bitsParity
[
j
]
+
bitsMessage
[
i
][
j
];
}
}
// Caso a soma vertical de uma coluna for par, bitsParity recebe 1,
// Caso a soma vertical de uma coluna for par, bitsParity recebe 1,
...
@@ -38,7 +44,7 @@ void SubMessage::setParity(){
...
@@ -38,7 +44,7 @@ void SubMessage::setParity(){
// Atribui os bits para parity (variável de paridade do objeto)
// Atribui os bits para parity (variável de paridade do objeto)
parity
=
(
parity
<<
1
)
|
bitsParity
[
j
];
parity
=
(
parity
<<
1
)
|
bitsParity
[
j
];
}
}
for
(
i
=
0
;
i
<
getSize
()
;
i
++
){
for
(
i
=
0
;
i
<
getSize
()
+
2
;
i
++
){
if
(
bitsMessage
[
i
]){
if
(
bitsMessage
[
i
]){
delete
(
bitsMessage
[
i
]);
delete
(
bitsMessage
[
i
]);
}
}
...
@@ -141,26 +147,26 @@ int SubMessage::checkParity(){
...
@@ -141,26 +147,26 @@ int SubMessage::checkParity(){
int
i
,
j
,
bitsParity
[
8
];
int
i
,
j
,
bitsParity
[
8
];
unsigned
char
parityTest
;
unsigned
char
parityTest
;
cout
<<
"AQUI"
<<
endl
;
// Alocação da matriz de bits
// Alocação da matriz de bits
cout
<<
"this-getSize = "
<<
getSize
()
<<
endl
;
bitsMessage
=
new
int
*
[
getSize
()
+
2
];
// bitsMessage = (int**) malloc(sizeof(int*)*getSize());
bitsMessage
[
0
]
=
new
int
[
8
];
bitsMessage
=
new
int
*
[
getSize
()];
bitsMessage
[
1
]
=
new
int
[
8
];
//bitsMessage = (int**) realloc(bitsMessage,sizeof(int*)*getSize());
for
(
j
=
0
;
j
<
8
;
j
++
){
cout
<<
"AQUI2"
<<
endl
;
bitsMessage
[
0
][
j
]
=
((((
sizSeqTyp
>>
8
)
&
0x00FF
)
>>
(
7
-
j
))
&
0x01
);
for
(
i
=
0
;
i
<
getSize
()
;
i
++
){
bitsMessage
[
1
][
j
]
=
((((
sizSeqTyp
>>
0
)
&
0x00FF
)
>>
(
7
-
j
))
&
0x01
);
}
for
(
i
=
2
;
i
<
getSize
()
+
2
;
i
++
){
bitsMessage
[
i
]
=
new
int
[
8
];
bitsMessage
[
i
]
=
new
int
[
8
];
// Divide os dados em bits
// Divide os dados em bits
for
(
j
=
0
;
j
<
8
;
j
++
){
for
(
j
=
0
;
j
<
8
;
j
++
){
bitsMessage
[
i
][
j
]
=
((
data
[
i
]
>>
(
7
-
j
))
&
0x01
);
bitsMessage
[
i
][
j
]
=
((
data
[
i
]
>>
(
7
-
j
))
&
0x01
);
}
}
}
}
cout
<<
"AQUI 3"
<<
endl
;
// Soma os bits verticalmente
// Soma os bits verticalmente
for
(
j
=
0
;
j
<
8
;
j
++
){
for
(
j
=
0
;
j
<
8
;
j
++
){
bitsParity
[
j
]
=
0
;
bitsParity
[
j
]
=
0
;
for
(
i
=
0
;
i
<
getSize
()
;
i
++
){
for
(
i
=
0
;
i
<
getSize
()
+
2
;
i
++
){
bitsParity
[
j
]
=
bitsParity
[
j
]
+
bitsMessage
[
i
][
j
];
bitsParity
[
j
]
=
bitsParity
[
j
]
+
bitsMessage
[
i
][
j
];
}
}
// Caso a soma vertical de uma coluna for par, bitsParity recebe 1,
// Caso a soma vertical de uma coluna for par, bitsParity recebe 1,
...
@@ -173,13 +179,11 @@ cout << "AQUI 3" << endl;
...
@@ -173,13 +179,11 @@ cout << "AQUI 3" << endl;
// Atribui os bits para parity (variável de paridade do objeto)
// Atribui os bits para parity (variável de paridade do objeto)
parityTest
=
(
parityTest
<<
1
)
|
bitsParity
[
j
];
parityTest
=
(
parityTest
<<
1
)
|
bitsParity
[
j
];
}
}
cout
<<
"AQUI 4"
<<
endl
;
for
(
i
=
0
;
i
<
getSize
()
+
2
;
i
++
){
for
(
i
=
0
;
i
<
getSize
()
;
i
++
){
if
(
bitsMessage
[
i
]){
if
(
bitsMessage
[
i
]){
delete
(
bitsMessage
[
i
]);
delete
(
bitsMessage
[
i
]);
}
}
}
}
cout
<<
"AQUI 5"
<<
endl
;
delete
(
bitsMessage
);
delete
(
bitsMessage
);
cout
<<
"AQUI 6"
<<
endl
;
cout
<<
"AQUI 6"
<<
endl
;
if
(
parityTest
==
parity
){
if
(
parityTest
==
parity
){
...
...
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