diff --git a/modules/algorithm/src/optimal.cpp b/modules/algorithm/src/optimal.cpp index 3ac2329..055e55f 100644 --- a/modules/algorithm/src/optimal.cpp +++ b/modules/algorithm/src/optimal.cpp @@ -527,7 +527,7 @@ std::vector lsqnonlinRKF(const FuncNds &funcs, const std::vector #else -std::vector lsqnonlinRKF(const FuncNds &, const std::vector &, const OptimalOptions &) +std::vector lsqnonlinRKF(const FuncNds &, const std::vector &, RobustMode, const OptimalOptions &) { RMVL_Error(RMVL_StsBadFunc, "this function must be used with libopencv_core.so, please recompile " "RMVL by setting \"WITH_OPENCV=ON\" and \"WITH_EIGEN3=ON\" in CMake"); diff --git a/modules/algorithm/test/test_dsp.cpp b/modules/algorithm/test/test_dsp.cpp index f60c648..84ba09f 100644 --- a/modules/algorithm/test/test_dsp.cpp +++ b/modules/algorithm/test/test_dsp.cpp @@ -27,8 +27,8 @@ TEST(DSPTest, dft) auto X = rm::dft(x); auto Gx = rm::Gx(X, rm::GxType::Amp); // 获取幅度谱最大值对应的频率 - int max_it = std::max_element(Gx.begin(), Gx.end()) - Gx.begin(); - EXPECT_EQ(max_it, f); + std::ptrdiff_t max_it = std::max_element(Gx.begin(), Gx.end()) - Gx.begin(); + EXPECT_EQ(max_it, static_cast(f)); } } // namespace rm_test diff --git a/modules/core/src/io.cpp b/modules/core/src/io.cpp index 2225eba..3d6bace 100644 --- a/modules/core/src/io.cpp +++ b/modules/core/src/io.cpp @@ -11,8 +11,8 @@ #ifndef _WIN32 #include -#include #include +#include #endif #include "io_impl.hpp" @@ -94,27 +94,27 @@ PipeServer::Impl::Impl(std::string_view name) : _name("\\\\.\\pipe\\"s + name.da PipeClient::Impl::Impl(std::string_view name) { + std::string pipe_name = "\\\\.\\pipe\\"s + name.data(); _handle = CreateFileA( - ("\\\\.\\pipe\\"s + name.data()).c_str(), // 命名管道名称 - GENERIC_READ | GENERIC_WRITE, // 读写权限 - 0, // 不共享 - nullptr, // 默认安全属性 - OPEN_EXISTING, // 打开已存在的管道 - 0, // 默认属性 - nullptr); // 无模板文件 + pipe_name.c_str(), // 命名管道名称 + GENERIC_READ | GENERIC_WRITE, // 读写权限 + 0, // 不共享 + nullptr, // 默认安全属性 + OPEN_EXISTING, // 打开已存在的管道 + 0, // 默认属性 + nullptr); // 无模板文件 if (_handle == INVALID_HANDLE_VALUE) { ERROR_("Failed to open named pipe"); return; } - DWORD mode = PIPE_READMODE_MESSAGE; - if (!SetNamedPipeHandleState(_handle, &mode, nullptr, nullptr)) - { - ERROR_("Failed to set named pipe handle state"); - CloseHandle(_handle); - return; - } - return; +} + +PipeServer::Impl::~Impl() +{ + if (!DisconnectNamedPipe(_handle)) + ERROR_("Failed to disconnect named pipe"); + closePipe(_handle); } bool PipeServer::Impl::read(std::string &data) { return readPipe(_handle, data); } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 81ee577..1abf60b 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -4,12 +4,15 @@ * @brief 数据 IO 与通信模块单元测试 * @version 1.0 * @date 2024-09-18 - * + * * @copyright Copyright 2024 (c), zhaoxi - * + * */ #include +#ifdef _WIN32 +#include +#endif #include @@ -36,6 +39,22 @@ TEST(IOTest, corners_io) TEST(IOTest, pipe_io) { +#ifdef _WIN32 + std::thread t([&]() { + rm::PipeServer server("test_pipe"); + EXPECT_TRUE(server.write("Hello")); + std::string msg{}; + EXPECT_TRUE(server.read(msg)); + EXPECT_EQ(msg, "world"); + }); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + rm::PipeClient client("test_pipe"); + std::string msg{}; + EXPECT_TRUE(client.read(msg)); + EXPECT_EQ(msg, "Hello"); + EXPECT_TRUE(client.write("world")); + t.join(); +#else rm::PipeServer server("test_pipe"); rm::PipeClient client("test_pipe"); EXPECT_TRUE(server.write("hello")); @@ -45,7 +64,7 @@ TEST(IOTest, pipe_io) EXPECT_TRUE(client.write("world")); EXPECT_TRUE(server.read(data)); EXPECT_EQ(data, "world"); +#endif } - } // namespace rm_test