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
7b93c43d
Commit
7b93c43d
authored
9 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Put function added in client
parent
e7e63434
No related branches found
No related tags found
1 merge request
!1
Lento
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
client.cpp
+30
-4
30 additions, 4 deletions
client.cpp
definitions.h
+3
-1
3 additions, 1 deletion
definitions.h
dirFunctions.cpp
+12
-0
12 additions, 0 deletions
dirFunctions.cpp
dirFunctions.h
+5
-1
5 additions, 1 deletion
dirFunctions.h
with
52 additions
and
7 deletions
.gitignore
+
2
−
1
View file @
7b93c43d
*.o
cacoclient
cacoserver
*.txt
This diff is collapsed.
Click to expand it.
client.cpp
+
30
−
4
View file @
7b93c43d
...
...
@@ -42,11 +42,35 @@ int main(){
receiveProtocol
.
receive
(
sockt
,
OUTPUT
,
WAIT_STOP
,
true
);
cout
<<
receiveProtocol
.
getDataAsString
()
<<
endl
;
}
else
if
(
command
==
"put"
){
sendProtocol
.
setData
(
vector
<
BYTE
>
(
line
.
begin
(),
line
.
end
()),
PUT
);
sendProtocol
.
transmit
(
sockt
,
WAIT_STOP
);
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
if
(
fexists
(
args
))
{
int
size
=
filesize
(
args
);
cout
<<
"ARQUIVO: "
<<
args
<<
"|"
<<
size
<<
endl
;
sendProtocol
.
setData
(
vector
<
BYTE
>
(
args
.
begin
(),
args
.
end
()),
PUT
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
int
error
=
receiveProtocol
.
receive
(
sockt
,
OK
,
WAIT_STOP
,
false
);
if
(
error
<
0
)
continue
;
sendProtocol
.
reset
();
sendProtocol
.
setData
(
vector
<
BYTE
>
(
size
),
SIZE
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
error
=
receiveProtocol
.
receive
(
sockt
,
OK
,
WAIT_STOP
,
false
);
if
(
error
<
0
)
continue
;
sendProtocol
.
reset
();
ifstream
putFile
(
args
);
stringstream
buffer
;
buffer
<<
putFile
.
rdbuf
();
sendProtocol
.
setData
(
vector
<
BYTE
>
(
buffer
.
str
().
begin
(),
buffer
.
str
().
begin
()),
PUT
);
sendProtocol
.
transmit
(
sockt
,
SLIDING
);
}
else
{
cout
<<
"ERROR: arquivo não existe
\n
"
;
}
}
else
if
(
command
==
"get"
){
sendProtocol
.
setData
(
vector
<
BYTE
>
(
line
.
begin
(),
line
.
end
()),
GET
);
sendProtocol
.
transmit
(
sockt
,
WAIT_STOP
);
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
sendProtocol
.
setData
(
vector
<
BYTE
>
(
args
.
begin
(),
args
.
end
()),
GET
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
int
error
=
receiveProtocol
.
receive
()
sockt
,
SIZE
,
WAIT_STOP
,
false
;
if
(
error
<
0
)
continue
;
int
fileSize
=
(
int
)
receiveProtocol
.
getDataAsString
();
}
else
if
(
command
==
"help"
){
printCommandsList
();
}
else
{
...
...
@@ -58,6 +82,8 @@ int main(){
}
catch
(
out_of_range
e
){
cerr
<<
"Error: Esse comando requer argumentos."
<<
endl
;
}
sendProtocol
.
reset
();
receiveProtocol
.
reset
();
}
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
definitions.h
+
3
−
1
View file @
7b93c43d
...
...
@@ -6,6 +6,8 @@
#include
<vector>
#include
<bitset>
#include
<cstdlib>
#include
<fstream>
#include
<sstream>
using
namespace
std
;
...
...
@@ -16,7 +18,7 @@ using namespace std;
//Delimiter indicating beginning of a message
#define BEGIN 0x7E
//Socket device
#define DEVICE "
lo
"
#define DEVICE "
eth0
"
//Message types
#define NACK 0
#define ACK 1
...
...
This diff is collapsed.
Click to expand it.
dirFunctions.cpp
+
12
−
0
View file @
7b93c43d
...
...
@@ -4,6 +4,8 @@
#include
<string.h>
#include
<vector>
#include
<stdio.h>
//popen
#include
<sys/stat.h>
#include
<fstream>
using
namespace
std
;
...
...
@@ -28,3 +30,13 @@ string ls(string args){
pclose
(
lsOut
);
return
output
;
}
bool
fexists
(
string
path
)
{
struct
stat
buffer
;
return
(
stat
(
path
.
c_str
(),
&
buffer
)
==
0
);
}
int
filesize
(
string
path
)
{
ifstream
in
(
path
,
ifstream
::
ate
|
ifstream
::
binary
);
return
in
.
tellg
();
}
This diff is collapsed.
Click to expand it.
dirFunctions.h
+
5
−
1
View file @
7b93c43d
...
...
@@ -9,4 +9,8 @@ void cd(string path);
string
ls
(
string
path
);
bool
fexists
(
string
path
);
int
filesize
(
string
path
);
#endif
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