FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CSNode/BufferTest.cpp at main · elfpipe/CSNode · GitHub
elfpipe
CSNode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CSNode
/
BufferTest.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (53 loc) · 1.78 KB
Breadcrumbs
CSNode
/
BufferTest.cpp
Copy path
File metadata and controls
60 lines (53 loc) · 1.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
include
<
stdio.h
>
/*
printf, scanf, puts, NULL
*/
#
include
<
stdlib.h
>
/*
srand, rand
*/
#
include
<
time.h
>
#
include
<
fcntl.h
>
#
include
<
unistd.h
>
#
include
"
Buffer.cpp
"
#
include
<
iostream
>
using
namespace
std
;
int
main
() {
Buffer buffer;
//
srand (time(NULL));
//
const int bufSize = 4096;
//
char input[bufSize];
//
for(int i = 0; i < 10000; i++) {
//
int f = rand() % bufSize;
//
printf("fill : %d\r", i);
//
buffer.fill(input, f);
//
int bytes;
//
while((bytes = buffer.readBytes(input, 0)) > 0)
//
; //printf("read : %d\n", bytes);
//
}
//
printf("\n");
for
(
int
i =
0
; i <
1000000
; i++) {
int
fd =
open
(
"
../calculator/calculator
"
,
O_RDONLY
);
if
(!fd) {
perror
(
"
open
"
);
continue
; }
//
calculate file size
int
size =
lseek
(fd,
0
,
SEEK_END
);
lseek
(fd,
0
,
SEEK_SET
);
char
sizebuf[
128
];
sprintf
(sizebuf,
"
%d
"
, size);
int
totalSent =
0
, totalRead =
0
, bytes;
const
int
bufSize =
4096
;
char
input[bufSize];
while
(totalSent == totalRead && totalRead < size && (bytes =
read
(fd, input, bufSize)) >
0
) {
if
(bytes <
0
)
perror
(
"
read
"
);
totalRead += bytes;
cout <<
"
-
"
;
//
first fill the buffer (in case it was already non-empty)
buffer.
fill
(input, bytes);
//
...then extract from it
cout <<
"
'
"
;
while
((bytes = buffer.
readBytes
(input, bufSize)) >
0
) {
//
cout << ",";
//
bytes = send(connection->connectionSocket, buffer, bytes, 0);
//
if(bytes < 0) perror("send");
totalSent += bytes;
cout <<
"
.
"
;
}
cout <<
"
_
"
;
}
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL