diff --git a/examples/bench_client/bench_client.cpp b/examples/bench_client/bench_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..46ace7c6b67d7c1890f88679232ba92aedd4b31e --- /dev/null +++ b/examples/bench_client/bench_client.cpp @@ -0,0 +1,284 @@ +/** +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\ntimeout 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; +} diff --git a/examples/bench_client/bench_client.vcxproj b/examples/bench_client/bench_client.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..165f84ef12c03f033d16b03477e21af95569276e --- /dev/null +++ b/examples/bench_client/bench_client.vcxproj @@ -0,0 +1,159 @@ +<?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 diff --git a/examples/bench_client/bench_client.vcxproj.filters b/examples/bench_client/bench_client.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..4ce01ac4d504c1be0ab5c0fc51fe76cf8be24cd7 --- /dev/null +++ b/examples/bench_client/bench_client.vcxproj.filters @@ -0,0 +1,22 @@ +<?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 diff --git a/examples/bench_client/bench_client.vcxproj.user b/examples/bench_client/bench_client.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..51606474fa12a557d316445bc557610c7d4af15e --- /dev/null +++ b/examples/bench_client/bench_client.vcxproj.user @@ -0,0 +1,7 @@ +<?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 diff --git a/examples/build.sh b/examples/build.sh index d2a03b22462f5c6f4739a2881c14ce88a2cb9631..edc558b604d51c368d670c2ce50dd15075a05845 100755 --- a/examples/build.sh +++ b/examples/build.sh @@ -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 ../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 ../bench_client/bench_client.cpp -I../../include `pkg-config --cflags --libs libevent` -levent_core -levent_pthreads -lpthread -o bench_client diff --git a/examples/examples.sln b/examples/examples.sln index 313edc51a3cc9b60bc79e8e064a88945e86dc405..d45601b7beda124e1f055ad47f930443dcda44ec 100644 --- a/examples/examples.sln +++ b/examples/examples.sln @@ -25,98 +25,154 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ademco_java", "javademo\cpp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server_demo_libevent", "server_demo_libevent\server_demo_libevent.vcxproj", "{AD6D6F3B-B39D-4F70-9940-3AB4FC870974}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bench_client", "bench_client\bench_client.vcxproj", "{4C31BDDD-3959-443D-AD05-3757C6456EE8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|ARM64 = Release|ARM64 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|ARM.ActiveCfg = Debug|Win32 + {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|ARM64.ActiveCfg = Debug|Win32 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|x64.ActiveCfg = Debug|x64 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|x64.Build.0 = Debug|x64 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|x86.ActiveCfg = Debug|Win32 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Debug|x86.Build.0 = Debug|Win32 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|Any CPU.ActiveCfg = Release|Win32 + {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|ARM.ActiveCfg = Release|Win32 + {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|ARM64.ActiveCfg = Release|Win32 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|x64.ActiveCfg = Release|x64 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|x64.Build.0 = Release|x64 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|x86.ActiveCfg = Release|Win32 {01B919A1-174A-45E5-A2B5-B509BD66E91A}.Release|x86.Build.0 = Release|Win32 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|ARM.ActiveCfg = Debug|Win32 + {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|ARM64.ActiveCfg = Debug|Win32 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|x64.ActiveCfg = Debug|x64 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|x64.Build.0 = Debug|x64 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|x86.ActiveCfg = Debug|Win32 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Debug|x86.Build.0 = Debug|Win32 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|Any CPU.ActiveCfg = Release|Win32 + {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|ARM.ActiveCfg = Release|Win32 + {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|ARM64.ActiveCfg = Release|Win32 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|x64.ActiveCfg = Release|x64 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|x64.Build.0 = Release|x64 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|x86.ActiveCfg = Release|Win32 {EF267749-DA49-433D-BF4E-742D4BC7F1DA}.Release|x86.Build.0 = Release|Win32 {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|ARM.ActiveCfg = Debug|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|ARM.Build.0 = Debug|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|ARM64.Build.0 = Debug|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|x64.ActiveCfg = Debug|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|x64.Build.0 = Debug|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|x86.ActiveCfg = Debug|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Debug|x86.Build.0 = Debug|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|Any CPU.ActiveCfg = Release|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|Any CPU.Build.0 = Release|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|ARM.ActiveCfg = Release|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|ARM.Build.0 = Release|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|ARM64.ActiveCfg = Release|Any CPU + {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|ARM64.Build.0 = Release|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|x64.ActiveCfg = Release|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|x64.Build.0 = Release|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|x86.ActiveCfg = Release|Any CPU {1A55F763-0E67-42AD-A72E-09CB49DE7434}.Release|x86.Build.0 = Release|Any CPU {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|ARM.ActiveCfg = Debug|Win32 + {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|ARM64.ActiveCfg = Debug|Win32 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x64.ActiveCfg = Debug|x64 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x64.Build.0 = Debug|x64 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x86.ActiveCfg = Debug|Win32 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Debug|x86.Build.0 = Debug|Win32 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|Any CPU.ActiveCfg = Release|Win32 + {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|ARM.ActiveCfg = Release|Win32 + {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|ARM64.ActiveCfg = Release|Win32 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x64.ActiveCfg = Release|x64 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x64.Build.0 = Release|x64 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x86.ActiveCfg = Release|Win32 {36640D95-55AB-4DCF-9062-91A53203E6A9}.Release|x86.Build.0 = Release|Win32 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|ARM.ActiveCfg = Debug|Win32 + {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|ARM64.ActiveCfg = Debug|Win32 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|x64.ActiveCfg = Debug|x64 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|x64.Build.0 = Debug|x64 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|x86.ActiveCfg = Debug|Win32 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Debug|x86.Build.0 = Debug|Win32 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|Any CPU.ActiveCfg = Release|Win32 + {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|ARM.ActiveCfg = Release|Win32 + {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|ARM64.ActiveCfg = Release|Win32 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|x64.ActiveCfg = Release|x64 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|x64.Build.0 = Release|x64 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|x86.ActiveCfg = Release|Win32 {76899E2F-3026-4262-8D0A-EE7CED1020CF}.Release|x86.Build.0 = Release|Win32 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|ARM.ActiveCfg = Debug|Win32 + {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|ARM64.ActiveCfg = Debug|Win32 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|x64.ActiveCfg = Debug|x64 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|x64.Build.0 = Debug|x64 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|x86.ActiveCfg = Debug|Win32 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Debug|x86.Build.0 = Debug|Win32 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|Any CPU.ActiveCfg = Release|Win32 + {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|ARM.ActiveCfg = Release|Win32 + {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|ARM64.ActiveCfg = Release|Win32 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|x64.ActiveCfg = Release|x64 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|x64.Build.0 = Release|x64 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|x86.ActiveCfg = Release|Win32 {EA5A04AA-EE49-4059-81A0-765402A210E7}.Release|x86.Build.0 = Release|Win32 {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|ARM.ActiveCfg = Debug|Win32 + {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|ARM64.ActiveCfg = Debug|Win32 {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|x64.ActiveCfg = Debug|x64 {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|x64.Build.0 = Debug|x64 {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|x86.ActiveCfg = Debug|Win32 {B323151B-AD89-4545-B95E-E2442A7961BB}.Debug|x86.Build.0 = Debug|Win32 {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|Any CPU.ActiveCfg = Release|Win32 + {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|ARM.ActiveCfg = Release|Win32 + {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|ARM64.ActiveCfg = Release|Win32 {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|x64.ActiveCfg = Release|x64 {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|x64.Build.0 = Release|x64 {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|x86.ActiveCfg = Release|Win32 {B323151B-AD89-4545-B95E-E2442A7961BB}.Release|x86.Build.0 = Release|Win32 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|ARM.ActiveCfg = Debug|Win32 + {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|ARM64.ActiveCfg = Debug|Win32 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|x64.ActiveCfg = Debug|x64 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|x64.Build.0 = Debug|x64 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|x86.ActiveCfg = Debug|Win32 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Debug|x86.Build.0 = Debug|Win32 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|Any CPU.ActiveCfg = Release|Win32 + {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|ARM.ActiveCfg = Release|Win32 + {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|ARM64.ActiveCfg = Release|Win32 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|x64.ActiveCfg = Release|x64 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|x64.Build.0 = Release|x64 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|x86.ActiveCfg = Release|Win32 {AD6D6F3B-B39D-4F70-9940-3AB4FC870974}.Release|x86.Build.0 = Release|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|ARM.ActiveCfg = Debug|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|ARM64.ActiveCfg = Debug|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|x64.ActiveCfg = Debug|x64 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|x64.Build.0 = Debug|x64 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|x86.ActiveCfg = Debug|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Debug|x86.Build.0 = Debug|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|Any CPU.ActiveCfg = Release|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|ARM.ActiveCfg = Release|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|ARM64.ActiveCfg = Release|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|x64.ActiveCfg = Release|x64 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|x64.Build.0 = Release|x64 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|x86.ActiveCfg = Release|Win32 + {4C31BDDD-3959-443D-AD05-3757C6456EE8}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/examples/server_demo_libevent/server_demo_libevent.cpp b/examples/server_demo_libevent/server_demo_libevent.cpp index dcc4d6ac916f540c579b96d656428956b8b1915a..c5cede13c13ea4ff0eb157493cadfb333eda73d9 100644 --- a/examples/server_demo_libevent/server_demo_libevent.cpp +++ b/examples/server_demo_libevent/server_demo_libevent.cpp @@ -41,8 +41,8 @@ struct Client { int fd = 0; evbuffer* output = nullptr; std::string acct = {}; - int ademco_id = 0; - int seq = 0; + size_t ademco_id = 0; + uint16_t seq = 0; }; std::unordered_map<int, Client> clients = {}; @@ -64,9 +64,9 @@ void usage(const char* name) void handle_ademco_msg(AdemcoPacket& packet, bufferevent* bev) { - int fd = bufferevent_getfd(bev); + int fd = (int)bufferevent_getfd(bev); 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=%06zX :%s\n", fd, client.acct.data(), client.ademco_id, packet.toString().data()); auto output = bufferevent_get_output(bev); switch (packet.id_.eid_) { case AdemcoId::id_null: @@ -80,7 +80,7 @@ void handle_ademco_msg(AdemcoPacket& packet, bufferevent* bev) char buf[1024]; size_t n = packet.make_ack(buf, sizeof(buf), packet.seq_.value_, packet.acct_.acct(), packet.ademcoData_.ademco_id_); 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=%06zX :%s\n", fd, client.acct.data(), client.ademco_id, packet.toString().data()); } break; default: @@ -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); } evbuffer_add(client.second.output, buf, n); - printf("S#%d acct=%s ademco_id=%06X :%s\n", + printf("S#%d acct=%s ademco_id=%06zX :%s\n", 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) 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); if (events & BEV_EVENT_EOF) { } else if (events & (BEV_EVENT_WRITING)) { @@ -184,9 +184,9 @@ void accept_cb(evconnlistener* listener, evutil_socket_t fd, sockaddr* addr, int } Client client; - client.fd = fd; + client.fd = (int)fd; client.output = bufferevent_get_output(bev); - clients[fd] = client; + clients[(int)fd] = client; bufferevent_setcb(bev, readcb, nullptr, eventcb, nullptr); bufferevent_enable(bev, EV_WRITE | EV_READ);