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
4e4458f6
Commit
4e4458f6
authored
Jul 28, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add bench_client
parent
5ad43113
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
538 additions
and
9 deletions
+538
-9
bench_client.cpp
examples/bench_client/bench_client.cpp
+284
-0
bench_client.vcxproj
examples/bench_client/bench_client.vcxproj
+159
-0
bench_client.vcxproj.filters
examples/bench_client/bench_client.vcxproj.filters
+22
-0
bench_client.vcxproj.user
examples/bench_client/bench_client.vcxproj.user
+7
-0
build.sh
examples/build.sh
+1
-0
examples.sln
examples/examples.sln
+56
-0
server_demo_libevent.cpp
examples/server_demo_libevent/server_demo_libevent.cpp
+9
-9
No files found.
examples/bench_client/bench_client.cpp
0 → 100644
View file @
4e4458f6
/**
Ping Pong Client
*/
#ifndef _WIN32
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#else
# ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
# endif
# ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
# define _WINSOCK_DEPRECATED_NO_WARNINGS
# endif
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#endif
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <string>
#include <algorithm>
#include <chrono>
#include <event2/listener.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02010100
#error "This version of Libevent is not supported; Get 2.1.1-alpha or later."
#endif
#define DISABLE_JLIB_LOG2
#include <ademco_packet.h>
using
namespace
ademco
;
int
session_count
=
0
;
int
session_connected
=
0
;
int
timeout
=
0
;
int64_t
totalBytesRead
=
0
;
int64_t
totalBytesWrite
=
0
;
int64_t
totalMsgRead
=
0
;
int64_t
totalMsgWritten
=
0
;
int64_t
totalEncodeTime
=
0
;
int64_t
totalDecodeTime
=
0
;
struct
Session
{
int
id
=
0
;
std
::
string
acct
=
{};
size_t
ademco_id
=
0
;
uint16_t
seq
=
0
;
AdemcoPacket
packet
=
{};
size_t
lastTimePacketSize
=
0
;
int64_t
bytesRead
=
0
;
int64_t
bytesWritten
=
0
;
int64_t
msgRead
=
0
;
int64_t
msgWritten
=
0
;
int64_t
encodeTime
=
0
;
int64_t
decodeTime
=
0
;
};
void
handle_ademco_msg
(
Session
*
session
,
bufferevent
*
bev
)
{
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
session
->
packet
.
id_
.
eid_
)
{
case
AdemcoId
:
:
id_ack
:
if
(
session
->
packet
.
seq_
.
value_
==
session
->
seq
)
{
if
(
++
session
->
seq
==
10000
)
{
session
->
seq
=
1
;
}
}
{
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
seq
,
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
output
,
buf
,
session
->
lastTimePacketSize
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
encodeTime
+=
us
;
}
break
;
default:
break
;
}
}
void
readcb
(
struct
bufferevent
*
bev
,
void
*
user_data
)
{
auto
input
=
bufferevent_get_input
(
bev
);
auto
session
=
(
Session
*
)
user_data
;
while
(
1
)
{
size_t
len
=
evbuffer_get_length
(
input
);
if
(
len
<
9
)
{
return
;
}
char
buff
[
1024
]
=
{
0
};
evbuffer_copyout
(
input
,
buff
,
std
::
min
(
len
,
sizeof
(
buff
)));
size_t
cb_commited
=
0
;
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
auto
res
=
session
->
packet
.
parse
(
buff
,
1024
,
cb_commited
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
decodeTime
+=
us
;
bool
done
=
false
;
switch
(
res
)
{
case
ademco
:
:
ParseResult
::
RESULT_OK
:
evbuffer_drain
(
input
,
cb_commited
);
session
->
bytesRead
+=
cb_commited
;
session
->
msgRead
++
;
handle_ademco_msg
(
session
,
bev
);
break
;
case
ademco
:
:
ParseResult
::
RESULT_NOT_ENOUGH
:
done
=
true
;
break
;
case
ademco
:
:
ParseResult
::
RESULT_DATA_ERROR
:
fprintf
(
stderr
,
"error while parsing data
\n
"
);
evbuffer_drain
(
input
,
len
);
done
=
true
;
break
;
}
if
(
done
)
{
break
;
}
}
}
void
writecb
(
struct
bufferevent
*
bev
,
void
*
user_data
)
{
auto
session
=
(
Session
*
)
user_data
;
if
(
0
==
evbuffer_get_length
(
bufferevent_get_output
(
bev
)))
{
session
->
bytesWritten
+=
session
->
lastTimePacketSize
;
session
->
msgWritten
++
;
}
}
void
timer_cb
(
evutil_socket_t
fd
,
short
what
,
void
*
arg
)
{
auto
bev
=
(
bufferevent
*
)
arg
;
Session
*
session
=
nullptr
;
bufferevent_getcb
(
bev
,
nullptr
,
nullptr
,
nullptr
,
(
void
**
)
&
session
);
printf
(
"client #%d timeout
\n
"
,
session
->
id
);
//auto bev = (bufferevent*)arg;
//bufferevent_free(bev);
//evutil_closesocket(fd);
//bufferevent_disable(bev, EV_WRITE);
// SHUT_WR
shutdown
(
fd
,
1
);
}
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
{
auto
session
=
(
Session
*
)
user_data
;
printf
(
"eventcb #%d events=%04X
\n
"
,
session
->
id
,
events
);
if
(
events
&
BEV_EVENT_CONNECTED
)
{
printf
(
"client #%d connected
\n
"
,
session
->
id
);
if
(
++
session_connected
==
session_count
)
{
printf
(
"All connected
\n
"
);
}
{
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
seq
,
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
}
auto
base
=
bufferevent_get_base
(
bev
);
auto
timer
=
event_new
(
base
,
bufferevent_getfd
(
bev
),
EV_TIMEOUT
,
timer_cb
,
bev
);
if
(
!
timer
)
{
fprintf
(
stderr
,
"create timer failed
\n
"
);
event_base_loopbreak
(
base
);
return
;
}
struct
timeval
tv
=
{
timeout
,
0
};
event_add
(
timer
,
&
tv
);
return
;
}
else
if
(
events
&
(
BEV_EVENT_EOF
))
{
printf
(
"Connection #%d closed.
\n
"
,
session
->
id
);
}
else
if
(
events
&
BEV_EVENT_ERROR
)
{
printf
(
"Got an error on the connection #%d: %s
\n
"
,
session
->
id
,
strerror
(
errno
));
}
totalBytesRead
+=
session
->
bytesRead
;
totalBytesWrite
+=
session
->
bytesWritten
;
totalMsgRead
+=
session
->
msgRead
;
totalMsgWritten
+=
session
->
msgWritten
;
totalEncodeTime
+=
session
->
encodeTime
;
totalDecodeTime
+=
session
->
decodeTime
;
delete
session
;
if
(
--
session_connected
==
0
)
{
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
"
"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
"
"Decode average time %.2f us, %.2f packets/s
\n
"
,
totalBytesRead
/
1024.0
/
1024
,
totalMsgRead
,
totalBytesWrite
/
1024.0
/
1024
,
totalMsgWritten
,
(
totalBytesRead
+
totalBytesWrite
)
*
1.0
/
(
totalMsgRead
+
totalMsgWritten
),
totalBytesRead
*
1.0
/
(
timeout
*
1024.0
*
1024
),
totalMsgRead
*
1.0
/
timeout
,
encodeSpeed
,
1000000.0
/
encodeSpeed
,
decodeSpeed
,
1000000.0
/
decodeSpeed
);
}
bufferevent_free
(
bev
);
}
int
main
(
int
argc
,
char
**
argv
)
{
#ifdef _WIN32
WSADATA
wsa_data
;
WSAStartup
(
0x0201
,
&
wsa_data
);
#endif
if
(
argc
<
5
)
{
printf
(
"Usage: %s ip port session_count timeout
\n
timeout is in seconds
\n
"
,
argv
[
0
]);
return
1
;
}
auto
ip
=
argv
[
1
];
int
port
=
atoi
(
argv
[
2
]);
if
(
port
<=
0
||
port
>
65535
)
{
puts
(
"Invalid port"
);
return
1
;
}
session_count
=
atoi
(
argv
[
3
]);
if
(
session_count
<=
0
)
{
puts
(
"Invalid session_count"
);
return
1
;
}
timeout
=
atoi
(
argv
[
4
]);
if
(
timeout
<=
0
)
{
puts
(
"Invalid timeout"
);
return
1
;
}
printf
(
"using libevent %s
\n
"
,
event_get_version
());
printf
(
"starting %s to %s:%d with %d sessions, timeout=%ds
\n
"
,
argv
[
0
],
ip
,
port
,
session_count
,
timeout
);
sockaddr_in
sin
=
{
0
};
sin
.
sin_family
=
AF_INET
;
sin
.
sin_addr
.
s_addr
=
inet_addr
(
ip
);
sin
.
sin_port
=
htons
(
port
);
auto
base
=
event_base_new
();
if
(
!
base
)
{
fprintf
(
stderr
,
"init libevent failed
\n
"
);
return
-
1
;
}
for
(
int
i
=
0
;
i
<
session_count
;
i
++
)
{
auto
bev
=
bufferevent_socket_new
(
base
,
-
1
,
BEV_OPT_CLOSE_ON_FREE
);
if
(
!
bev
)
{
fprintf
(
stderr
,
"allocate bufferevent failed
\n
"
);
return
1
;
}
auto
session
=
new
Session
();
session
->
id
=
i
;
session
->
acct
=
std
::
string
(
"861234567890"
)
+
std
::
to_string
(
i
);
session
->
ademco_id
=
i
;
session
->
seq
=
1
;
bufferevent_setcb
(
bev
,
readcb
,
writecb
,
eventcb
,
session
);
bufferevent_enable
(
bev
,
EV_READ
|
EV_WRITE
);
if
(
bufferevent_socket_connect
(
bev
,
(
sockaddr
*
)(
&
sin
),
sizeof
(
sin
))
<
0
)
{
fprintf
(
stderr
,
"error starting connection
\n
"
);
return
-
1
;
}
}
event_base_dispatch
(
base
);
return
0
;
}
examples/bench_client/bench_client.vcxproj
0 → 100644
View file @
4e4458f6
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup
Label=
"ProjectConfigurations"
>
<ProjectConfiguration
Include=
"Debug|Win32"
>
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<VCProjectVersion>
16.0
</VCProjectVersion>
<Keyword>
Win32Proj
</Keyword>
<ProjectGuid>
{4c31bddd-3959-443d-ad05-3757c6456ee8}
</ProjectGuid>
<RootNamespace>
benchclient
</RootNamespace>
<WindowsTargetPlatformVersion>
10.0
</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
<ImportGroup
Label=
"Shared"
>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<LinkIncremental>
true
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<LinkIncremental>
false
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LinkIncremental>
true
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<LinkIncremental>
false
</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<AdditionalIncludeDirectories>
$(SolutionDir)..\include;$(DEVLIBS)\libevent-2.1.12-stable-install\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<AdditionalLibraryDirectories>
$(DEVLIBS)\libevent-2.1.12-stable-install\lib;%(AdditionalLibraryDirectories)
</AdditionalLibraryDirectories>
<AdditionalDependencies>
event_core.lib;%(AdditionalDependencies)
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<AdditionalIncludeDirectories>
$(SolutionDir)..\include;$(DEVLIBS)\libevent-2.1.12-stable-install\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<AdditionalLibraryDirectories>
$(DEVLIBS)\libevent-2.1.12-stable-install\lib;%(AdditionalLibraryDirectories)
</AdditionalLibraryDirectories>
<AdditionalDependencies>
event_core.lib;%(AdditionalDependencies)
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<AdditionalIncludeDirectories>
$(SolutionDir)..\include;$(DEVLIBS)\libevent-2.1.12-stable-install-x64\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<AdditionalLibraryDirectories>
$(DEVLIBS)\libevent-2.1.12-stable-install-x64\lib;%(AdditionalLibraryDirectories)
</AdditionalLibraryDirectories>
<AdditionalDependencies>
event_core.lib;%(AdditionalDependencies)
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<AdditionalIncludeDirectories>
$(SolutionDir)..\include;$(DEVLIBS)\libevent-2.1.12-stable-install-x64\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<AdditionalDependencies>
event_core.lib;%(AdditionalDependencies)
</AdditionalDependencies>
<AdditionalLibraryDirectories>
$(DEVLIBS)\libevent-2.1.12-stable-install-x64\lib;%(AdditionalLibraryDirectories)
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"bench_client.cpp"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
\ No newline at end of file
examples/bench_client/bench_client.vcxproj.filters
0 → 100644
View file @
4e4458f6
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup>
<Filter
Include=
"Source Files"
>
<UniqueIdentifier>
{4FC737F1-C7A5-4376-A066-2A32D752A2FF}
</UniqueIdentifier>
<Extensions>
cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx
</Extensions>
</Filter>
<Filter
Include=
"Header Files"
>
<UniqueIdentifier>
{93995380-89BD-4b04-88EB-625FBE52EBFB}
</UniqueIdentifier>
<Extensions>
h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
</Extensions>
</Filter>
<Filter
Include=
"Resource Files"
>
<UniqueIdentifier>
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
</UniqueIdentifier>
<Extensions>
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"bench_client.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
examples/bench_client/bench_client.vcxproj.user
0 → 100644
View file @
4e4458f6
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LocalDebuggerCommandArguments>
192.168.1.168 12345 10 10
</LocalDebuggerCommandArguments>
<DebuggerFlavor>
WindowsLocalDebugger
</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
examples/build.sh
View file @
4e4458f6
...
@@ -6,5 +6,6 @@ g++ -std=c++11 ../bench/bench.cpp -I../../include -o bench
...
@@ -6,5 +6,6 @@ g++ -std=c++11 ../bench/bench.cpp -I../../include -o bench
g++
-std
=
c++11 ../demo/demo.cpp
-I
../../include
-o
demo
g++
-std
=
c++11 ../demo/demo.cpp
-I
../../include
-o
demo
g++
-std
=
c++11 ../server_demo/server_demo.cpp
-I
../../include
-lpthread
-o
server_demo
g++
-std
=
c++11 ../server_demo/server_demo.cpp
-I
../../include
-lpthread
-o
server_demo
g++
-std
=
c++11 ../server_demo_libevent/server_demo_libevent.cpp
-I
../../include
`
pkg-config
--cflags
--libs
libevent
`
-levent_core
-levent_pthreads
-lpthread
-o
server_demo_libevent
g++
-std
=
c++11 ../server_demo_libevent/server_demo_libevent.cpp
-I
../../include
`
pkg-config
--cflags
--libs
libevent
`
-levent_core
-levent_pthreads
-lpthread
-o
server_demo_libevent
g++
-std
=
c++11 ../bench_client/bench_client.cpp
-I
../../include
`
pkg-config
--cflags
--libs
libevent
`
-levent_core
-levent_pthreads
-lpthread
-o
bench_client
examples/examples.sln
View file @
4e4458f6
This diff is collapsed.
Click to expand it.
examples/server_demo_libevent/server_demo_libevent.cpp
View file @
4e4458f6
...
@@ -41,8 +41,8 @@ struct Client {
...
@@ -41,8 +41,8 @@ struct Client {
int
fd
=
0
;
int
fd
=
0
;
evbuffer
*
output
=
nullptr
;
evbuffer
*
output
=
nullptr
;
std
::
string
acct
=
{};
std
::
string
acct
=
{};
in
t
ademco_id
=
0
;
size_
t
ademco_id
=
0
;
in
t
seq
=
0
;
uint16_
t
seq
=
0
;
};
};
std
::
unordered_map
<
int
,
Client
>
clients
=
{};
std
::
unordered_map
<
int
,
Client
>
clients
=
{};
...
@@ -64,9 +64,9 @@ void usage(const char* name)
...
@@ -64,9 +64,9 @@ void usage(const char* name)
void
handle_ademco_msg
(
AdemcoPacket
&
packet
,
bufferevent
*
bev
)
void
handle_ademco_msg
(
AdemcoPacket
&
packet
,
bufferevent
*
bev
)
{
{
int
fd
=
bufferevent_getfd
(
bev
);
int
fd
=
(
int
)
bufferevent_getfd
(
bev
);
auto
&
client
=
clients
[
fd
];
auto
&
client
=
clients
[
fd
];
printf
(
"C#%d acct=%s ademco_id=%06X :%s
\n
"
,
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
packet
.
toString
().
data
());
printf
(
"C#%d acct=%s ademco_id=%06
z
X :%s
\n
"
,
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
packet
.
toString
().
data
());
auto
output
=
bufferevent_get_output
(
bev
);
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
packet
.
id_
.
eid_
)
{
switch
(
packet
.
id_
.
eid_
)
{
case
AdemcoId
:
:
id_null
:
case
AdemcoId
:
:
id_null
:
...
@@ -80,7 +80,7 @@ void handle_ademco_msg(AdemcoPacket& packet, bufferevent* bev)
...
@@ -80,7 +80,7 @@ void handle_ademco_msg(AdemcoPacket& packet, bufferevent* bev)
char
buf
[
1024
];
char
buf
[
1024
];
size_t
n
=
packet
.
make_ack
(
buf
,
sizeof
(
buf
),
packet
.
seq_
.
value_
,
packet
.
acct_
.
acct
(),
packet
.
ademcoData_
.
ademco_id_
);
size_t
n
=
packet
.
make_ack
(
buf
,
sizeof
(
buf
),
packet
.
seq_
.
value_
,
packet
.
acct_
.
acct
(),
packet
.
ademcoData_
.
ademco_id_
);
evbuffer_add
(
output
,
buf
,
n
);
evbuffer_add
(
output
,
buf
,
n
);
printf
(
"S#%d acct=%s ademco_id=%06X :%s
\n
"
,
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
packet
.
toString
().
data
());
printf
(
"S#%d acct=%s ademco_id=%06
z
X :%s
\n
"
,
fd
,
client
.
acct
.
data
(),
client
.
ademco_id
,
packet
.
toString
().
data
());
}
}
break
;
break
;
default:
default:
...
@@ -113,7 +113,7 @@ void commandcb(evutil_socket_t, short, void*)
...
@@ -113,7 +113,7 @@ void commandcb(evutil_socket_t, short, void*)
n
=
maker
.
make_hb
(
buf
,
sizeof
(
buf
),
client
.
second
.
seq
,
client
.
second
.
acct
,
client
.
second
.
ademco_id
,
0
,
e
,
0
);
n
=
maker
.
make_hb
(
buf
,
sizeof
(
buf
),
client
.
second
.
seq
,
client
.
second
.
acct
,
client
.
second
.
ademco_id
,
0
,
e
,
0
);
}
}
evbuffer_add
(
client
.
second
.
output
,
buf
,
n
);
evbuffer_add
(
client
.
second
.
output
,
buf
,
n
);
printf
(
"S#%d acct=%s ademco_id=%06X :%s
\n
"
,
printf
(
"S#%d acct=%s ademco_id=%06
z
X :%s
\n
"
,
client
.
second
.
fd
,
client
.
second
.
acct
.
data
(),
client
.
second
.
ademco_id
,
maker
.
toString
().
data
());
client
.
second
.
fd
,
client
.
second
.
acct
.
data
(),
client
.
second
.
ademco_id
,
maker
.
toString
().
data
());
}
}
}
}
...
@@ -153,7 +153,7 @@ void readcb(struct bufferevent* bev, void* user_data)
...
@@ -153,7 +153,7 @@ void readcb(struct bufferevent* bev, void* user_data)
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
void
eventcb
(
struct
bufferevent
*
bev
,
short
events
,
void
*
user_data
)
{
{
int
fd
=
bufferevent_getfd
(
bev
);
int
fd
=
(
int
)
bufferevent_getfd
(
bev
);
printf
(
"eventcb events=%04X
\n
"
,
events
);
printf
(
"eventcb events=%04X
\n
"
,
events
);
if
(
events
&
BEV_EVENT_EOF
)
{
if
(
events
&
BEV_EVENT_EOF
)
{
}
else
if
(
events
&
(
BEV_EVENT_WRITING
))
{
}
else
if
(
events
&
(
BEV_EVENT_WRITING
))
{
...
@@ -184,9 +184,9 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int
...
@@ -184,9 +184,9 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int
}
}
Client
client
;
Client
client
;
client
.
fd
=
fd
;
client
.
fd
=
(
int
)
fd
;
client
.
output
=
bufferevent_get_output
(
bev
);
client
.
output
=
bufferevent_get_output
(
bev
);
clients
[
fd
]
=
client
;
clients
[
(
int
)
fd
]
=
client
;
bufferevent_setcb
(
bev
,
readcb
,
nullptr
,
eventcb
,
nullptr
);
bufferevent_setcb
(
bev
,
readcb
,
nullptr
,
eventcb
,
nullptr
);
bufferevent_enable
(
bev
,
EV_WRITE
|
EV_READ
);
bufferevent_enable
(
bev
,
EV_WRITE
|
EV_READ
);
...
...
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