]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10167: Fixed some issues on library destruction. Added another of the test apps...
authorShane Bryldt <astaelan@gmail.com>
Tue, 4 Apr 2017 17:00:17 +0000 (11:00 -0600)
committerShane Bryldt <astaelan@gmail.com>
Tue, 4 Apr 2017 17:00:44 +0000 (11:00 -0600)
libs/libblade/libblade.sln
libs/libblade/src/blade_stack.c
libs/libblade/test/bladec.c
libs/libblade/test/bladec.vcxproj [new file with mode: 0644]
libs/libblade/test/blades.c

index 54989dbc28a6118706194d11a33a0a30dc5cea1b..e8d040b564065a1bc142eefe7e5a717836dcabda 100644 (file)
@@ -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
index 3ffb6ed65f6bd423d6deabb74c44662056b0a570..536d52ef262116a366afc26ecfca9f305e036a4a 100644 (file)
@@ -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;
index ebc0384a21bed3df3bf5e11c029de7acb4aab056..5d4b79cafbdca96e92f111d7500e227c968daffb 100644 (file)
@@ -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 (file)
index 0000000..d3b5d1a
--- /dev/null
@@ -0,0 +1,215 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" 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">
+    <ProjectGuid>{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>bladec</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</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" />
+    <Import Project="..\..\..\w32\openssl-version.props" />
+    <Import Project="..\..\..\w32\sodium.props" />
+    <Import Project="..\..\..\w32\config.props" />
+  </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" />
+    <Import Project="..\..\..\w32\openssl-version.props" />
+    <Import Project="..\..\..\w32\sodium.props" />
+    <Import Project="..\..\..\w32\config.props" />
+  </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" />
+    <Import Project="..\..\..\w32\openssl-version.props" />
+    <Import Project="..\..\..\w32\sodium.props" />
+    <Import Project="..\..\..\w32\config.props" />
+  </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" />
+    <Import Project="..\..\..\w32\openssl-version.props" />
+    <Import Project="..\..\..\w32\sodium.props" />
+    <Import Project="..\..\..\w32\config.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+    <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath)</IncludePath>
+    <LibraryPath>$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath)</IncludePath>
+    <LibraryPath>$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+    <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath)</IncludePath>
+    <LibraryPath>$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+    <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath)</IncludePath>
+    <LibraryPath>$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;.</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <MinimalRebuild>false</MinimalRebuild>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <MinimalRebuild>false</MinimalRebuild>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;.</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <SDLCheck>true</SDLCheck>
+      <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.</AdditionalIncludeDirectories>
+      <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="tap.c" />
+    <ClCompile Include="bladec.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\libks\libks.vcxproj">
+      <Project>{70d178d8-1100-4152-86c0-809a91cff832}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\win32\libconfig\libconfig.2015.vcxproj">
+      <Project>{1a234565-926d-49b2-83e4-d56e0c38c9f2}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\win32\libsodium\libsodium.2015.vcxproj">
+      <Project>{a185b162-6cb6-4502-b03f-b56f7699a8d9}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\win32\openssl\libeay32.2015.vcxproj">
+      <Project>{d331904d-a00a-4694-a5a3-fcff64ab5dbe}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\win32\openssl\ssleay32.2015.vcxproj">
+      <Project>{b4b62169-5ad4-4559-8707-3d933ac5db39}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\libblade.vcxproj">
+      <Project>{a89d6d18-6203-4149-9051-f8e798e7a3e7}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
index 10f3f5d97cfd5eed031b80b89c7e5b7747711990..e84f70c3f52521acd31efe756258b27332148652 100644 (file)
@@ -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);
        }
 }