fiber client2 sample can run on Windows.

This commit is contained in:
zsxxsz 2018-01-21 15:41:19 +08:00
parent de8be9ca0f
commit 588c871124
6 changed files with 285 additions and 7 deletions

View File

@ -729,6 +729,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinEchod", "lib_fiber\sampl
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server2", "lib_fiber\samples\server2\server2_vc2012.vcxproj", "{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client2", "lib_fiber\samples\client2\client2_vc2012.vcxproj", "{A08F48F5-D359-4332-8743-F9D85887AEF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@ -3628,6 +3630,31 @@ Global
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|Win32.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|Win32.Build.0 = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|x64.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Win32.ActiveCfg = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Win32.Build.0 = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|x64.ActiveCfg = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Win32.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Win32.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|x64.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Mixed Platforms.Build.0 = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Win32.ActiveCfg = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Win32.Build.0 = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|x64.ActiveCfg = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Mixed Platforms.Build.0 = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Win32.ActiveCfg = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Win32.Build.0 = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|x64.ActiveCfg = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Mixed Platforms.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Mixed Platforms.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Win32.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Win32.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|x64.ActiveCfg = DebugDll|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -3758,5 +3785,6 @@ Global
{BFCE4280-B6E5-414A-A8CD-F827A4A19B6F} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
{F74A61AD-A309-47A5-A7C6-BAC888660BBC} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
{A08F48F5-D359-4332-8743-F9D85887AEF6} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
EndGlobalSection
EndGlobal

View File

@ -13,6 +13,8 @@
# define HAS_KQUEUE
#elif defined(_WIN32) || defined(_WIN64)
# if(_MSC_VER >= 1300)
# undef FD_SETSIZE
# define FD_SETSIZE 10240
# include <winsock2.h>
# include <mswsock.h>
# else

View File

@ -0,0 +1,191 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugDll|Win32">
<Configuration>DebugDll</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ReleaseDll|Win32">
<Configuration>ReleaseDll</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A08F48F5-D359-4332-8743-F9D85887AEF6}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>client2</RootNamespace>
<ProjectName>client2</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</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 Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="PropertySheets">
<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>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>.\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>.\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>.\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>.\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_acl_d.lib;lib_fiber.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\lib_acl\lib_acl_d.dll .\ /Y
copy ..\..\c\lib_fiber.dll .\ /Y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_acl.lib;lib_fiber.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
<Command>copy ..\..\..\lib_acl\lib_acl.dll .\ /Y
copy ..\..\c\lib_fiber.dll .\ /Y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\c\include; ..\..\..\lib_acl\include;..\</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\stamp.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<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="main.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\stamp.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,13 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#if !defined(_WIN32) && !defined(_WIN64)
#include <unistd.h>
#include <signal.h>
#endif
#include "lib_acl.h"
#include "fiber/lib_fiber.h"
#include "stamp.h"
#if defined(_WIN32) || defined(_WIN64)
# define snprintf _snprintf
#else
# define SOCKET int
# define INVALID_SOCKET -1
#endif
static char __server_ip[64];
static int __server_port = 9001;
@ -25,15 +35,19 @@ static int __read_data = 1;
static int __stack_size = 32000;
static struct timeval __begin;
static void echo_client(int fd)
static void echo_client(SOCKET fd)
{
char buf[8192];
int ret, i;
const char *str = "hello world\r\n";
for (i = 0; i < __max_loop; i++) {
#if defined(_WIN32) || defined(_WIN64)
if (acl_fiber_send(fd, str, strlen(str), 0) <= 0) {
#else
if (write(fd, str, strlen(str)) <= 0) {
printf("write error: %s\r\n", strerror(errno));
#endif
printf("write error: %s\r\n", acl_last_serror());
break;
}
@ -47,25 +61,33 @@ static void echo_client(int fd)
continue;
}
#if defined(_WIN32) || defined(_WIN64)
ret = acl_fiber_recv(fd, buf, sizeof(buf), 0);
#else
ret = read(fd, buf, sizeof(buf));
#endif
if (ret <= 0) {
printf("read error: %s\r\n", strerror(errno));
printf("read error: %s\r\n", acl_last_serror());
break;
}
__total_count++;
}
#if defined(_WIN32) || defined(_WIN64)
acl_fiber_close(fd);
#else
close(fd);
#endif
}
static void fiber_connect(ACL_FIBER *fiber acl_unused, void *ctx acl_unused)
{
int fd = socket(AF_INET, SOCK_STREAM, 0);
SOCKET fd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sa;
socklen_t len = (socklen_t) sizeof(sa);
assert(fd >= 0);
assert(fd != INVALID_SOCKET);
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
@ -76,11 +98,15 @@ static void fiber_connect(ACL_FIBER *fiber acl_unused, void *ctx acl_unused)
acl_fiber_delay(__fiber_delay);
if (connect(fd, (const struct sockaddr *) &sa, len) < 0) {
#if defined(_WIN32) || defined(_WIN64)
acl_fiber_close(fd);
#else
close(fd);
#endif
printf("fiber-%d: connect %s:%d error %s\r\n",
acl_fiber_self(), __server_ip, __server_port,
strerror(errno));
acl_last_serror());
__total_error_clients++;
} else {
@ -139,8 +165,12 @@ int main(int argc, char *argv[])
{
int ch, event_mode = FIBER_EVENT_KERNEL;
acl_lib_init();
acl_msg_stdout_enable(1);
#if !defined(_WIN32) && !defined(_WIN64)
signal(SIGPIPE, SIG_IGN);
#endif
snprintf(__server_ip, sizeof(__server_ip), "%s", "127.0.0.1");

View File

@ -20,7 +20,7 @@
#else
# define SOCKET int
# define INVALID_SOCKET -1
# define POLL poll
# define POLL poll
# define CLOSE close
# define LISTEN listen
# define ACCEPT accept