From ea4b6c84d0e344c81ce893232fdc55b3d8682bf3 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 10 Aug 2019 22:55:15 +0200 Subject: [PATCH] now working with libuv v1.31.x --- README.md | 7 ++--- cmake/in/deps.in | 2 +- src/uvw/fs.hpp | 63 +++++++++++++++++++++++++++++++++++++- src/uvw/util.hpp | 1 + test/CMakeLists.txt | 2 -- test/uvw/file_req.cpp | 2 -- test/uvw/fs_req.cpp | 22 -------------- test/uvw/pipe.cpp | 10 ------- test/uvw/poll.cpp | 12 -------- test/uvw/process.cpp | 10 ------- test/uvw/stream.cpp | 11 ------- test/uvw/thread.cpp | 70 ------------------------------------------- 12 files changed, 66 insertions(+), 146 deletions(-) delete mode 100644 test/uvw/poll.cpp delete mode 100644 test/uvw/thread.cpp diff --git a/README.md b/README.md index eef28e19..25b5d240 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ exist a valid `libuv` wrapper in C++. That's all. To be able to use `uvw`, users must provide the following system-wide tools: -* A full-featured compiler that supports at least C++14. +* A full-featured compiler that supports at least C++17. * `libuv` (which version depends on the tag of `uvw` in use). The requirements below are mandatory to compile the tests and to extract the @@ -169,10 +169,7 @@ for the latest version. The documentation is mostly inspired by the official [libuv API documentation](http://docs.libuv.org/en/v1.x/) for obvious -reasons.
-If you are mainly interested in the way `uvw` imports `libuv` in a `cmake` based -project, I suggest you to take a look at -[this](https://github.com/skypjack/libuv_cmake) repository instead. +reasons. ## Tests diff --git a/cmake/in/deps.in b/cmake/in/deps.in index 1ee28244..ba0e7e7f 100644 --- a/cmake/in/deps.in +++ b/cmake/in/deps.in @@ -17,7 +17,7 @@ ExternalProject_Add( ExternalProject_Add( libuv GIT_REPOSITORY https://github.com/libuv/libuv.git - GIT_TAG v1.30.1 + GIT_TAG v1.31.0 SOURCE_DIR @LIBUV_DEPS_DIR@ CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index 457e88af..780cfa40 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -52,7 +52,8 @@ enum class UVFsType: std::underlying_type_t { LCHOWN = UV_FS_LCHOWN, OPENDIR = UV_FS_OPENDIR, READDIR = UV_FS_READDIR, - CLOSEDIR = UV_FS_CLOSEDIR + CLOSEDIR = UV_FS_CLOSEDIR, + STATFS = UV_FS_STATFS }; @@ -76,6 +77,7 @@ enum class UVFileOpenFlags: int { DSYNC = UV_FS_O_DSYNC, EXCL = UV_FS_O_EXCL, EXLOCK = UV_FS_O_EXLOCK, + FILEMAP = UV_FS_O_FILEMAP, NOATIME = UV_FS_O_NOATIME, NOCTTY = UV_FS_O_NOCTTY, NOFOLLOW = UV_FS_O_NOFOLLOW, @@ -149,6 +151,7 @@ enum class UVSymLinkFlags: int { * * `FsRequest::Type::OPENDIR` * * `FsRequest::Type::READDIR` * * `FsRequest::Type::CLOSEDIR` + * * `FsRequest::Type::STATFS` * * It will be emitted by FsReq and/or FileReq according with their * functionalities. @@ -268,6 +271,23 @@ struct FsEvent { }; +/** + * @brief FsEvent event specialization for `FsRequest::Type::STATFS`. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ +template<> +struct FsEvent { + FsEvent(const char *pathname, Statfs curr) noexcept + : path{pathname}, statfs{std::move(curr)} + {} + + const char * path; /*!< The path affecting the request. */ + Statfs statfs; /*!< An initialized instance of Statfs. */ +}; + + /** * @brief FsEvent event specialization for `FsRequest::Type::SCANDIR`. * @@ -352,6 +372,12 @@ protected: else { ptr->publish(FsEvent{req->path, req->statbuf}); } } + static void fsStatfsCallback(uv_fs_t *req) { + auto ptr = Request::reserve(req); + if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); } + else { ptr->publish(FsEvent{req->path, *static_cast(req->ptr)}); } + } + template void cleanupAndInvoke(Args&&... args) { uv_fs_req_cleanup(this->get()); @@ -461,6 +487,7 @@ public: * * `FileReq::FileOpen::DSYNC` * * `FileReq::FileOpen::EXCL` * * `FileReq::FileOpen::EXLOCK` + * * `FileReq::FileOpen::FILEMAP` * * `FileReq::FileOpen::NOATIME` * * `FileReq::FileOpen::NOCTTY` * * `FileReq::FileOpen::NOFOLLOW` @@ -500,6 +527,7 @@ public: * * `FileReq::FileOpen::DSYNC` * * `FileReq::FileOpen::EXCL` * * `FileReq::FileOpen::EXLOCK` + * * `FileReq::FileOpen::FILEMAP` * * `FileReq::FileOpen::NOATIME` * * `FileReq::FileOpen::NOCTTY` * * `FileReq::FileOpen::NOFOLLOW` @@ -1106,6 +1134,39 @@ public: return std::make_pair(!(req->result < 0), req->statbuf); } + /** + * @brief Async [statfs](http://linux.die.net/man/2/statfs). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * Any fields in the resulting object that are not supported by the + * underlying operating system are set to zero. + * + * @param path Path, as described in the official documentation. + */ + void stasfs(std::string path) { + cleanupAndInvoke(&uv_fs_statfs, parent(), get(), path.data(), &fsStatfsCallback); + } + + /** + * @brief Sync [statfs](http://linux.die.net/man/2/statfs). + * + * Any fields in the resulting object that are not supported by the + * underlying operating system are set to zero. + * + * @param path Path, as described in the official documentation. + * + * @return A `std::pair` composed as it follows: + * * A boolean value that is true in case of success, false otherwise. + * * An initialized instance of Statfs. + */ + std::pair statfsSync(std::string path) { + auto req = get(); + cleanupAndInvokeSync(&uv_fs_statfs, parent(), req, path.data()); + return std::make_pair(!(req->result < 0), *static_cast(req->ptr)); + } + /** * @brief Async [rename](http://linux.die.net/man/2/rename). * diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index fd20449c..3da5ca68 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -197,6 +197,7 @@ constexpr FileHandle StdERR{2}; /*!< Placeholder for stderr descriptor. */ using TimeSpec = uv_timespec_t; /*!< Library equivalent for uv_timespec_t. */ using Stat = uv_stat_t; /*!< Library equivalent for uv_stat_t. */ +using Statfs = uv_statfs_t; /*!< Library equivalent for uv_statfs_t. */ using Uid = uv_uid_t; /*!< Library equivalent for uv_uid_t. */ using Gid = uv_gid_t; /*!< Library equivalent for uv_gid_t. */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index baeca7a7..371f7771 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,7 +60,6 @@ ADD_UVW_TEST(idle uvw/idle.cpp) ADD_UVW_LIB_TEST(lib uvw/lib.cpp) ADD_UVW_TEST(loop uvw/loop.cpp) ADD_UVW_DIR_TEST(pipe uvw/pipe.cpp) -ADD_UVW_TEST(poll uvw/poll.cpp) ADD_UVW_TEST(prepare uvw/prepare.cpp) ADD_UVW_TEST(process uvw/process.cpp) ADD_UVW_TEST(request uvw/request.cpp) @@ -68,7 +67,6 @@ ADD_UVW_TEST(resource uvw/resource.cpp) ADD_UVW_TEST(signal uvw/signal.cpp) ADD_UVW_TEST(stream uvw/stream.cpp) ADD_UVW_TEST(tcp uvw/tcp.cpp) -ADD_UVW_TEST(thread uvw/thread.cpp) ADD_UVW_TEST(timer uvw/timer.cpp) ADD_UVW_TEST(tty uvw/tty.cpp) ADD_UVW_TEST(udp uvw/udp.cpp) diff --git a/test/uvw/file_req.cpp b/test/uvw/file_req.cpp index cd8cd030..5108c4c9 100644 --- a/test/uvw/file_req.cpp +++ b/test/uvw/file_req.cpp @@ -198,7 +198,6 @@ TEST(FileReq, RWSync) { } - TEST(FileReq, Stat) { const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/test.file"}; @@ -228,7 +227,6 @@ TEST(FileReq, Stat) { } - TEST(FileReq, StatSync) { const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/test.file"}; diff --git a/test/uvw/fs_req.cpp b/test/uvw/fs_req.cpp index ab358043..3fb76101 100644 --- a/test/uvw/fs_req.cpp +++ b/test/uvw/fs_req.cpp @@ -100,18 +100,6 @@ TEST(FsReq, MkdtempAndRmdirSync) { } -/* -TEST(FsReq, Scandir) { - // TODO -} - - -TEST(FsReq, ScandirSync) { - // TODO -} -*/ - - TEST(FsReq, Stat) { const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"}; @@ -267,16 +255,6 @@ TEST(FsReq, RenameSync) { } -TEST(FsReq, CopyFile) { - // TODO -} - - -TEST(FsReq, CopyFileSync) { - // TODO -} - - TEST(FsReq, Access) { const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"}; diff --git a/test/uvw/pipe.cpp b/test/uvw/pipe.cpp index 2d924ca4..5735b758 100644 --- a/test/uvw/pipe.cpp +++ b/test/uvw/pipe.cpp @@ -119,13 +119,3 @@ TEST(Pipe, Shutdown) { loop->run(); } - - -TEST(Pipe, TODO) { - auto loop = uvw::Loop::getDefault(); - auto handle = uvw::PipeHandle::create(loop); - - handle = nullptr; - - // TODO -} diff --git a/test/uvw/poll.cpp b/test/uvw/poll.cpp deleted file mode 100644 index 843acce5..00000000 --- a/test/uvw/poll.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - - -TEST(Poll, StartAndStopReadableWritable) { - auto loop = uvw::Loop::getDefault(); - auto handle = uvw::PollHandle::create(loop, 0); - - handle = nullptr; - - // TODO -} diff --git a/test/uvw/process.cpp b/test/uvw/process.cpp index ad8842d0..33348736 100644 --- a/test/uvw/process.cpp +++ b/test/uvw/process.cpp @@ -36,13 +36,3 @@ TEST(Process, StdIO) { pipe->close(); loop->run(); } - - -TEST(Process, TODO) { - auto loop = uvw::Loop::getDefault(); - auto handle = uvw::ProcessHandle::create(loop); - - handle = nullptr; - - // TODO -} diff --git a/test/uvw/stream.cpp b/test/uvw/stream.cpp index 9af36719..f9c89ad6 100644 --- a/test/uvw/stream.cpp +++ b/test/uvw/stream.cpp @@ -11,14 +11,3 @@ struct FakeStreamHandle: uvw::StreamHandle { template bool init(Args&&...) { return true; } }; - - -TEST(Stream, TODO) { - auto loop = uvw::Loop::getDefault(); - auto handle = FakeStreamHandle::create(loop); - - handle = nullptr; - - // TODO - -} diff --git a/test/uvw/thread.cpp b/test/uvw/thread.cpp deleted file mode 100644 index 845096c8..00000000 --- a/test/uvw/thread.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include - - -TEST(Thread, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource([](std::shared_ptr){}); - - resource->run(); - - // TODO -} - - -TEST(ThreadLocalStorage, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(); - - // TODO -} - - -TEST(Once, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(); - - // TODO -} - - -TEST(Mutex, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(); - - // TODO -} - - -TEST(RWLock, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(); - - // TODO -} - - -TEST(Semaphore, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(1); - - // TODO -} - - -TEST(Condition, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(); - - // TODO -} - - -TEST(Barrier, TODO) { - auto loop = uvw::Loop::getDefault(); - auto resource = loop->resource(1); - - // TODO -}