Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ademco_hb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
ademco_hb
Commits
e266a4a0
Commit
e266a4a0
authored
Aug 04, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix warnings
parent
4de8781f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
25 deletions
+30
-25
bench_client.cpp
examples/bench_client/bench_client.cpp
+2
-1
dll_demo.cpp
examples/dll_demo/dll_demo.cpp
+3
-3
server_demo.cpp
examples/server_demo/server_demo.cpp
+13
-12
server_demo_libevent.cpp
examples/server_demo_libevent/server_demo_libevent.cpp
+12
-9
No files found.
examples/bench_client/bench_client.cpp
View file @
e266a4a0
...
...
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <time.h>
#include <string>
...
...
@@ -232,7 +233,7 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
printf
(
"All disconnected
\n
"
);
double
encodeSpeed
=
totalEncodeTime
*
1.0
/
totalMsgWritten
;
double
decodeSpeed
=
totalDecodeTime
*
1.0
/
totalMsgRead
;
printf
(
"Read %.2f MiB %
lld packets, Write %.2f MiB %lld
packets
\n
"
printf
(
"Read %.2f MiB %
"
PRId64
" packets, Write %.2f MiB %"
PRId64
"
packets
\n
"
"Average msg size is %.2f bytes
\n
"
"Throughput is %.2f MiB/s %.2f packets/s
\n
"
"Encode average time %.2f us, %.2f packets/s
\n
"
...
...
examples/dll_demo/dll_demo.cpp
View file @
e266a4a0
...
...
@@ -24,21 +24,21 @@ int main()
// 解析完整数据包
{
char
raw
[]
=
"
\n
C5C30053
\"
HENG-BO
\"
0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019
\r
"
;
int
res
=
parse
(
raw
,
strlen
(
raw
),
&
cb_commited
);
int
res
=
parse
(
raw
,
(
int
)
strlen
(
raw
),
&
cb_commited
);
assert
(
res
==
0
);
}
// 解析长度不足的数据包
{
char
raw_not_enough
[]
=
"
\n
C5C30053
\"
HENG-BO
\"
0000R000000L000000"
;
int
res
=
parse
(
raw_not_enough
,
strlen
(
raw_not_enough
),
&
cb_commited
);
int
res
=
parse
(
raw_not_enough
,
(
int
)
strlen
(
raw_not_enough
),
&
cb_commited
);
assert
(
res
==
1
);
}
// 解析到错误数据包
{
char
raw_error
[]
=
"abcdeadfasdfasdfasd"
;
int
res
=
parse
(
raw_error
,
strlen
(
raw_error
),
&
cb_commited
);
int
res
=
parse
(
raw_error
,
(
int
)
strlen
(
raw_error
),
&
cb_commited
);
assert
(
res
==
2
);
}
...
...
examples/server_demo/server_demo.cpp
View file @
e266a4a0
...
...
@@ -125,7 +125,7 @@ int main(int argc, char** argv)
FD_ZERO
(
&
rfd
);
FD_SET
(
serverSock
,
&
rfd
);
timeval
timeout
=
{
1
,
0
};
int
nfds
=
select
(
serverSock
+
1
,
&
rfd
,
(
fd_set
*
)
0
,
(
fd_set
*
)
0
,
&
timeout
);
int
nfds
=
select
(
(
int
)(
serverSock
+
1
)
,
&
rfd
,
(
fd_set
*
)
0
,
(
fd_set
*
)
0
,
&
timeout
);
printf
(
"do_accept, select ret=%d
\n
"
,
nfds
);
if
(
nfds
>
0
)
{
FD_CLR
(
serverSock
,
&
rfd
);
...
...
@@ -134,7 +134,7 @@ int main(int argc, char** argv)
if
(
ret
!=
0
)
{
exit
(
0
);
}
printf
(
"Got connection from %s:%d, fd=%d
\n
"
,
inet_ntoa
(
sForeignAddrIn
.
sin_addr
),
sForeignAddrIn
.
sin_port
,
clientSock
);
printf
(
"Got connection from %s:%d, fd=%d
\n
"
,
inet_ntoa
(
sForeignAddrIn
.
sin_addr
),
sForeignAddrIn
.
sin_port
,
(
int
)
clientSock
);
}
};
...
...
@@ -160,7 +160,7 @@ int main(int argc, char** argv)
char
ack
[
1024
];
auto
len
=
ap
.
make_ack
(
ack
,
sizeof
(
ack
),
ap
.
seq_
.
value_
,
ap
.
acct_
.
acct
(),
ap
.
ademcoData_
.
ademco_id_
);
printf
(
"S:%s
\n
"
,
ap
.
toString
().
data
());
send
(
clientSock
,
ack
,
len
,
0
);
send
(
clientSock
,
ack
,
(
int
)
len
,
0
);
break
;
}
...
...
@@ -178,7 +178,7 @@ int main(int argc, char** argv)
auto
len
=
ap
.
make_ack
(
ack
,
sizeof
(
ack
),
ap
.
seq_
.
value_
,
ap
.
acct_
.
acct
(),
ap
.
ademcoData_
.
ademco_id_
);
printf
(
"S:%s
\n
"
,
ap
.
toString
().
data
());
// send to machine via network
send
(
clientSock
,
ack
,
len
,
0
);
send
(
clientSock
,
ack
,
(
int
)
len
,
0
);
}
break
;
...
...
@@ -211,7 +211,7 @@ int main(int argc, char** argv)
fd_set
fd_read
;
FD_ZERO
(
&
fd_read
);
FD_SET
(
clientSock
,
&
fd_read
);
int
nfds
=
select
(
clientSock
+
1
,
&
fd_read
,
(
fd_set
*
)
0
,
(
fd_set
*
)
0
,
&
tv
);
int
nfds
=
select
(
int
(
clientSock
+
1
)
,
&
fd_read
,
(
fd_set
*
)
0
,
(
fd_set
*
)
0
,
&
tv
);
if
(
nfds
<=
0
)
{
return
;
}
...
...
@@ -221,7 +221,7 @@ int main(int argc, char** argv)
char
*
temp
=
clientBuffer
.
buff
+
clientBuffer
.
wpos
;
size_t
dwLenToRead
=
BUFF_SIZE
-
clientBuffer
.
wpos
;
int
bytes_transfered
=
recv
(
clientSock
,
temp
,
dwLenToRead
,
0
);
int
bytes_transfered
=
recv
(
clientSock
,
temp
,
(
int
)
dwLenToRead
,
0
);
if
(
-
1
==
bytes_transfered
)
{
if
(
EAGAIN
==
errno
)
{
...
...
@@ -230,14 +230,14 @@ int main(int argc, char** argv)
}
if
(
bytes_transfered
<=
0
)
{
printf
(
"Client %d offline
\n
"
,
clientSock
);
printf
(
"Client %d offline
\n
"
,
(
int
)
clientSock
);
close
(
clientSock
);
clientSock
=
INVALID_SOCKET
;
clientBuffer
.
clear
();
}
else
{
clientBuffer
.
wpos
+=
bytes_transfered
;
auto
result
=
do_handle
();
while
(
1
)
{
unsigned
in
t
bytes_not_commited
=
clientBuffer
.
wpos
-
clientBuffer
.
rpos
;
size_
t
bytes_not_commited
=
clientBuffer
.
wpos
-
clientBuffer
.
rpos
;
if
(
bytes_not_commited
==
0
)
{
if
(
clientBuffer
.
wpos
==
BUFF_SIZE
)
{
clientBuffer
.
clear
();
...
...
@@ -276,11 +276,11 @@ int main(int argc, char** argv)
auto
xdata
=
makeXData
(
pwd
,
6
);
auto
len
=
ap
.
make_hb
(
buf
,
sizeof
(
buf
),
1
,
clientAcct
,
clientAdemcoId
,
0
,
e
,
0
,
xdata
);
printf
(
"S:%s
\n
"
,
ap
.
toString
().
data
());
send
(
clientSock
,
buf
,
len
,
0
);
send
(
clientSock
,
buf
,
(
int
)
len
,
0
);
}
else
{
auto
len
=
ap
.
make_hb
(
buf
,
sizeof
(
buf
),
1
,
clientAcct
,
clientAdemcoId
,
0
,
e
,
0
);
printf
(
"S:%s
\n
"
,
ap
.
toString
().
data
());
send
(
clientSock
,
buf
,
len
,
0
);
send
(
clientSock
,
buf
,
(
int
)
len
,
0
);
}
}
...
...
@@ -298,10 +298,11 @@ int main(int argc, char** argv)
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
evntsWaiting4Send
.
push_back
(
EVENT_ARM
);
}
else
if
(
cmd
==
'd'
||
cmd
==
'D'
)
{
int
ret
=
0
;
do
{
printf
(
"Input 6 digit password:"
);
scanf
(
"%s"
,
pwd
);
}
while
(
strlen
(
pwd
)
!=
6
);
ret
=
scanf
(
"%s"
,
pwd
);
}
while
(
ret
!=
1
||
strlen
(
pwd
)
!=
6
);
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
evntsWaiting4Send
.
push_back
(
EVENT_DISARM
);
}
else
if
(
cmd
==
'e'
||
cmd
==
'E'
)
{
...
...
examples/server_demo_libevent/server_demo_libevent.cpp
View file @
e266a4a0
...
...
@@ -472,17 +472,20 @@ int main(int argc, char** argv)
break
;
case
'D'
:
do
{
printf
(
"Input 6 digit password:"
);
scanf
(
"%s"
,
userInput
.
pwd
);
}
while
(
strlen
(
userInput
.
pwd
)
!=
6
);
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
events
.
push_back
(
EVENT_DISARM
);
threads_to_handled_event
=
thread_count
;
}
fire_command
();
int
ret
=
0
;
do
{
printf
(
"Input 6 digit password:"
);
ret
=
scanf
(
"%s"
,
userInput
.
pwd
);
}
while
(
ret
!=
1
||
strlen
(
userInput
.
pwd
)
!=
6
);
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
events
.
push_back
(
EVENT_DISARM
);
threads_to_handled_event
=
thread_count
;
}
fire_command
();
break
;
}
case
'E'
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment