diff --git a/acl_cpp_vc2012.sln b/acl_cpp_vc2012.sln index 1a8effd2a..8682bb910 100644 --- a/acl_cpp_vc2012.sln +++ b/acl_cpp_vc2012.sln @@ -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 diff --git a/lib_fiber/c/src/define.h b/lib_fiber/c/src/define.h index cfc58ffa3..e90b40c1e 100644 --- a/lib_fiber/c/src/define.h +++ b/lib_fiber/c/src/define.h @@ -13,6 +13,8 @@ # define HAS_KQUEUE #elif defined(_WIN32) || defined(_WIN64) # if(_MSC_VER >= 1300) +# undef FD_SETSIZE +# define FD_SETSIZE 10240 # include # include # else diff --git a/lib_fiber/samples/client2/client2_vc2012.vcxproj b/lib_fiber/samples/client2/client2_vc2012.vcxproj new file mode 100644 index 000000000..4d925b781 --- /dev/null +++ b/lib_fiber/samples/client2/client2_vc2012.vcxproj @@ -0,0 +1,191 @@ + + + + + DebugDll + Win32 + + + Debug + Win32 + + + ReleaseDll + Win32 + + + Release + Win32 + + + + {A08F48F5-D359-4332-8743-F9D85887AEF6} + Win32Proj + client2 + client2 + + + + Application + true + v110 + MultiByte + + + Application + true + v110 + MultiByte + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + + + + + + + + + + + + + + + + + true + .\ + + + true + .\ + + + true + .\ + + + false + .\ + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + ..\..\c\include; ..\..\..\lib_acl\include;..\ + MultiThreadedDebug + + + Console + true + ..\..\c;..\..\..\lib_acl; + lib_fiber.lib;lib_acl_vc2012d.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions) + true + ..\..\c\include; ..\..\..\lib_acl\include;..\ + MultiThreadedDebugDLL + + + Console + true + ..\..\c;..\..\..\lib_acl; + lib_acl_d.lib;lib_fiber.lib;ws2_32.lib;%(AdditionalDependencies) + + + + + + + copy ..\..\..\lib_acl\lib_acl_d.dll .\ /Y +copy ..\..\c\lib_fiber.dll .\ /Y + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;ACL_DLL;FIBER_DLL;%(PreprocessorDefinitions) + true + ..\..\c\include; ..\..\..\lib_acl\include;..\ + MultiThreadedDLL + + + Console + true + ..\..\c;..\..\..\lib_acl; + lib_acl.lib;lib_fiber.lib;%(AdditionalDependencies) + + + + + + + copy ..\..\..\lib_acl\lib_acl.dll .\ /Y +copy ..\..\c\lib_fiber.dll .\ /Y + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + ..\..\c\include; ..\..\..\lib_acl\include;..\ + MultiThreaded + + + Console + true + true + true + ..\..\c;..\..\..\lib_acl; + lib_fiber.lib;lib_acl_vc2012.lib;%(AdditionalDependencies) + + + + + + + + + + + + \ No newline at end of file diff --git a/lib_fiber/samples/client2/client2_vc2012.vcxproj.filters b/lib_fiber/samples/client2/client2_vc2012.vcxproj.filters new file mode 100644 index 000000000..5baf4c123 --- /dev/null +++ b/lib_fiber/samples/client2/client2_vc2012.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + + + 头文件 + + + \ No newline at end of file diff --git a/lib_fiber/samples/client2/main.c b/lib_fiber/samples/client2/main.c index 960a5b161..b3212b68e 100644 --- a/lib_fiber/samples/client2/main.c +++ b/lib_fiber/samples/client2/main.c @@ -1,13 +1,23 @@ #include #include +#include #include #include +#if !defined(_WIN32) && !defined(_WIN64) #include #include +#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"); diff --git a/lib_fiber/samples/server2/main.c b/lib_fiber/samples/server2/main.c index 2f58f9fc9..19fb1afb5 100644 --- a/lib_fiber/samples/server2/main.c +++ b/lib_fiber/samples/server2/main.c @@ -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