From a5dc3e8f1f4b2d293e48f0be01bf997091a534a0 Mon Sep 17 00:00:00 2001 From: Shane Bryldt Date: Tue, 4 Apr 2017 11:00:17 -0600 Subject: [PATCH] FS-10167: Fixed some issues on library destruction. Added another of the test apps for libblade under windows. Fixed console input under tests. --- libs/libblade/libblade.sln | 18 +++ libs/libblade/src/blade_stack.c | 11 +- libs/libblade/test/bladec.c | 60 +-------- libs/libblade/test/bladec.vcxproj | 215 ++++++++++++++++++++++++++++++ libs/libblade/test/blades.c | 62 +-------- 5 files changed, 250 insertions(+), 116 deletions(-) create mode 100644 libs/libblade/test/bladec.vcxproj diff --git a/libs/libblade/libblade.sln b/libs/libblade/libblade.sln index 54989dbc28..e8d040b564 100644 --- a/libs/libblade/libblade.sln +++ b/libs/libblade/libblade.sln @@ -19,6 +19,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libconfig", "..\win32\libco EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blades", "test\blades.vcxproj", "{636D5B57-FC64-4A18-8D42-54209F8886BD}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bladec", "test\bladec.vcxproj", "{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -159,6 +161,22 @@ Global {636D5B57-FC64-4A18-8D42-54209F8886BD}.ReleaseDLL|x64.Build.0 = Release|x64 {636D5B57-FC64-4A18-8D42-54209F8886BD}.ReleaseDLL|x86.ActiveCfg = Release|Win32 {636D5B57-FC64-4A18-8D42-54209F8886BD}.ReleaseDLL|x86.Build.0 = Release|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Debug|x64.ActiveCfg = Debug|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Debug|x64.Build.0 = Debug|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Debug|x86.ActiveCfg = Debug|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Debug|x86.Build.0 = Debug|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.DebugDLL|x64.ActiveCfg = Debug|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.DebugDLL|x64.Build.0 = Debug|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.DebugDLL|x86.ActiveCfg = Debug|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.DebugDLL|x86.Build.0 = Debug|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Release|x64.ActiveCfg = Release|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Release|x64.Build.0 = Release|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Release|x86.ActiveCfg = Release|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.Release|x86.Build.0 = Release|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x64.ActiveCfg = Release|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x64.Build.0 = Release|x64 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x86.ActiveCfg = Release|Win32 + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}.ReleaseDLL|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libs/libblade/src/blade_stack.c b/libs/libblade/src/blade_stack.c index 3ffb6ed65f..536d52ef26 100644 --- a/libs/libblade/src/blade_stack.c +++ b/libs/libblade/src/blade_stack.c @@ -309,7 +309,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) ks_assert(bh); - for (it = ks_hash_first(bh->requests, KS_UNLOCKED); it; it = ks_hash_next(&it)) { + while ((it = ks_hash_first(bh->requests, KS_UNLOCKED))) { void *key = NULL; blade_request_t *value = NULL; @@ -333,7 +333,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) // @todo call onshutdown and onunload callbacks for modules from DSOs, which will unregister transports and spaces, and will disconnect remaining // unattached connections - for (it = ks_hash_first(bh->events, KS_UNLOCKED); it; it = ks_hash_next(&it)) { + while ((it = ks_hash_first(bh->events, KS_UNLOCKED))) { void *key = NULL; blade_event_callback_t *value = NULL; @@ -341,7 +341,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) blade_handle_event_unregister(bh, (const char *)key); } - for (it = ks_hash_first(bh->spaces, KS_UNLOCKED); it; it = ks_hash_next(&it)) { + while ((it = ks_hash_first(bh->spaces, KS_UNLOCKED))) { void *key = NULL; blade_space_t *value = NULL; @@ -457,13 +457,12 @@ KS_DECLARE(ks_status_t) blade_handle_space_unregister(blade_space_t *bs) ks_assert(path); ks_hash_write_lock(bh->spaces); - bs = ks_hash_search(bh->spaces, (void *)path, KS_UNLOCKED); - if (bs) ks_hash_remove(bh->spaces, (void *)path); + ks_hash_remove(bh->spaces, (void *)path); ks_hash_write_unlock(bh->spaces); if (bs) { - blade_space_destroy(&bs); ks_log(KS_LOG_DEBUG, "Space Unregistered: %s\n", path); + blade_space_destroy(&bs); } return KS_STATUS_SUCCESS; diff --git a/libs/libblade/test/bladec.c b/libs/libblade/test/bladec.c index ebc0384a21..5d4b79cafb 100644 --- a/libs/libblade/test/bladec.c +++ b/libs/libblade/test/bladec.c @@ -1,20 +1,9 @@ #include "blade.h" #include "tap.h" -#ifdef _WIN32 -#define STDIO_FD(_fs) _fileno(_fs) -#define READ(_fd, _buffer, _count) _read(_fd, _buffer, _count) -#else -#define STDIO_FD(_fs) fileno(_fs) -#define READ(_fd, _buffer, _count) read(_fd, _buffer, _count) -#endif - #define CONSOLE_INPUT_MAX 512 ks_bool_t g_shutdown = KS_FALSE; -char g_console_input[CONSOLE_INPUT_MAX]; -size_t g_console_input_length = 0; -size_t g_console_input_eol = 0; void loop(blade_handle_t *bh); void process_console_input(blade_handle_t *bh, char *line); @@ -141,56 +130,19 @@ void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_co } } -void buffer_console_input(void) -{ - ssize_t bytes = 0; - struct pollfd poll[1]; - poll[0].fd = STDIO_FD(stdin); - poll[0].events = POLLIN | POLLERR; - - if (ks_poll(poll, 1, 1) > 0) { - if (poll[0].revents & POLLIN) { - if ((bytes = READ(poll[0].fd, g_console_input + g_console_input_length, CONSOLE_INPUT_MAX - g_console_input_length)) <= 0) { - // @todo error - return; - } - g_console_input_length += bytes; - } - } -} - void loop(blade_handle_t *bh) { + char buf[CONSOLE_INPUT_MAX]; while (!g_shutdown) { - ks_bool_t eol = KS_FALSE; - buffer_console_input(); + if (!fgets(buf, CONSOLE_INPUT_MAX, stdin)) break; - for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) { - char c = g_console_input[g_console_input_eol]; - if (c == '\r' || c == '\n') { - eol = KS_TRUE; + for (int index = 0; buf[index]; ++index) { + if (buf[index] == '\r' || buf[index] == '\n') { + buf[index] = '\0'; break; } } - if (eol) { - g_console_input[g_console_input_eol] = '\0'; - process_console_input(bh, g_console_input); - g_console_input_eol++; - for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) { - char c = g_console_input[g_console_input_eol]; - if (c != '\r' && c != '\n') break; - } - if (g_console_input_eol == g_console_input_length) g_console_input_eol = g_console_input_length = 0; - else { - memcpy(g_console_input, g_console_input + g_console_input_eol, g_console_input_length - g_console_input_eol); - g_console_input_length -= g_console_input_eol; - g_console_input_eol = 0; - } - } - if (g_console_input_length == CONSOLE_INPUT_MAX) { - // @todo lines must not exceed 512 bytes, treat as error and ignore buffer until next new line? - ks_assert(0); - } + process_console_input(bh, buf); } } diff --git a/libs/libblade/test/bladec.vcxproj b/libs/libblade/test/bladec.vcxproj new file mode 100644 index 0000000000..d3b5d1a924 --- /dev/null +++ b/libs/libblade/test/bladec.vcxproj @@ -0,0 +1,215 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F} + Win32Proj + bladec + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\ + $(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath) + $(LibraryPath) + + + true + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath) + $(LibraryPath) + + + false + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\ + $(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath) + $(LibraryPath) + + + false + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath) + $(LibraryPath) + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;. + 4090 + true + false + + + Console + true + + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;. + 4090 + true + false + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;. + 4090 + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;. + 4090 + true + + + Console + true + true + true + + + + + + + + + {70d178d8-1100-4152-86c0-809a91cff832} + + + {1a234565-926d-49b2-83e4-d56e0c38c9f2} + + + {a185b162-6cb6-4502-b03f-b56f7699a8d9} + + + {d331904d-a00a-4694-a5a3-fcff64ab5dbe} + + + {b4b62169-5ad4-4559-8707-3d933ac5db39} + + + {a89d6d18-6203-4149-9051-f8e798e7a3e7} + + + + + + \ No newline at end of file diff --git a/libs/libblade/test/blades.c b/libs/libblade/test/blades.c index 10f3f5d97c..e84f70c3f5 100644 --- a/libs/libblade/test/blades.c +++ b/libs/libblade/test/blades.c @@ -1,20 +1,9 @@ #include "blade.h" #include "tap.h" -#ifdef _WIN32 -#define STDIO_FD(_fs) _fileno(_fs) -#define READ(_fd, _buffer, _count) _read(_fd, _buffer, _count) -#else -#define STDIO_FD(_fs) fileno(_fs) -#define READ(_fd, _buffer, _count) read(_fd, _buffer, _count) -#endif - #define CONSOLE_INPUT_MAX 512 ks_bool_t g_shutdown = KS_FALSE; -char g_console_input[CONSOLE_INPUT_MAX]; -size_t g_console_input_length = 0; -size_t g_console_input_eol = 0; void loop(blade_handle_t *bh); void process_console_input(blade_handle_t *bh, char *line); @@ -102,58 +91,19 @@ int main(int argc, char **argv) return 0; } - - -void buffer_console_input(void) -{ - ssize_t bytes = 0; - struct pollfd poll[1]; - poll[0].fd = STDIO_FD(stdin); - poll[0].events = POLLIN | POLLERR; - - if (ks_poll(poll, 1, 1) > 0) { - if (poll[0].revents & POLLIN) { - if ((bytes = READ(poll[0].fd, g_console_input + g_console_input_length, CONSOLE_INPUT_MAX - g_console_input_length)) <= 0) { - // @todo error - return; - } - g_console_input_length += bytes; - } - } -} - void loop(blade_handle_t *bh) { + char buf[CONSOLE_INPUT_MAX]; while (!g_shutdown) { - ks_bool_t eol = KS_FALSE; - buffer_console_input(); + if (!fgets(buf, CONSOLE_INPUT_MAX, stdin)) break; - for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) { - char c = g_console_input[g_console_input_eol]; - if (c == '\r' || c == '\n') { - eol = KS_TRUE; + for (int index = 0; buf[index]; ++index) { + if (buf[index] == '\r' || buf[index] == '\n') { + buf[index] = '\0'; break; } } - if (eol) { - g_console_input[g_console_input_eol] = '\0'; - process_console_input(bh, g_console_input); - g_console_input_eol++; - for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) { - char c = g_console_input[g_console_input_eol]; - if (c != '\r' && c != '\n') break; - } - if (g_console_input_eol == g_console_input_length) g_console_input_eol = g_console_input_length = 0; - else { - memcpy(g_console_input, g_console_input + g_console_input_eol, g_console_input_length - g_console_input_eol); - g_console_input_length -= g_console_input_eol; - g_console_input_eol = 0; - } - } - if (g_console_input_length == CONSOLE_INPUT_MAX) { - // @todo lines must not exceed 512 bytes, treat as error and ignore buffer until next new line? - ks_assert(0); - } + process_console_input(bh, buf); } }