diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e239e23..7bb5829b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ endif() # Project configuration # -project(uvw VERSION 2.2.0) +project(uvw VERSION 2.3.0) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) diff --git a/cmake/in/deps.in b/cmake/in/deps.in index 05516257..c4ec76fb 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.33.0 + GIT_TAG v1.34.0 SOURCE_DIR @LIBUV_DEPS_DIR@ CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/conanfile.py b/conanfile.py index 078b1e96..fde7aee9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -14,7 +14,7 @@ class UVMConan(ConanFile): exports = "LICENSE" exports_sources = "src/*" no_copy_source = True - requires = "libuv/1.32.0@bincrafters/stable" + requires = "libuv/1.34.0@bincrafters/stable" def package(self): self.copy(pattern="LICENSE", dst="licenses") diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index 780cfa40..84ab7f84 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -53,7 +53,8 @@ enum class UVFsType: std::underlying_type_t { OPENDIR = UV_FS_OPENDIR, READDIR = UV_FS_READDIR, CLOSEDIR = UV_FS_CLOSEDIR, - STATFS = UV_FS_STATFS + STATFS = UV_FS_STATFS, + MKSTEMP = UV_FS_MKSTEMP }; @@ -152,6 +153,7 @@ enum class UVSymLinkFlags: int { * * `FsRequest::Type::READDIR` * * `FsRequest::Type::CLOSEDIR` * * `FsRequest::Type::STATFS` + * * `FsRequest::Type::MKSTEMP` * * It will be emitted by FsReq and/or FileReq according with their * functionalities. @@ -288,6 +290,23 @@ struct FsEvent { }; +/** + * @brief FsEvent event specialization for `FsRequest::Type::MKSTEMP`. + * + * It will be emitted by FsReq and/or FileReq according with their + * functionalities. + */ +template<> +struct FsEvent { + FsEvent(const char *pathname, std::size_t desc) noexcept + : path{pathname}, descriptor{desc} + {} + + const char * path; /*!< The created file path. */ + std::size_t descriptor; /*!< The file descriptor as an integer. */ +}; + + /** * @brief FsEvent event specialization for `FsRequest::Type::SCANDIR`. * @@ -974,7 +993,7 @@ public: * * @return A `std::pair` composed as it follows: * * A boolean value that is true in case of success, false otherwise. - * * The actual path of the newly created directoy. + * * The actual path of the newly created directory. */ std::pair mkdtempSync(std::string tpl) { auto req = get(); @@ -982,6 +1001,52 @@ public: return std::make_pair(!(req->result < 0), req->path); } + /** + * @brief Async [mkstemp](https://linux.die.net/man/3/mkstemp). + * + * Emit a `FsEvent` event when completed.
+ * Emit an ErrorEvent event in case of errors. + * + * @param tpl Template, as described in the official documentation. + */ + void mkstemp(std::string tpl) { + cleanupAndInvoke(&uv_fs_mkstemp, parent(), get(), tpl.data(), &fsResultCallback); + } + + /** + * @brief Sync [mkstemp](https://linux.die.net/man/3/mkstemp). + * + * Returns a composed value where: + * + * * The first parameter indicates the created file path. + * * The second parameter is the file descriptor as an integer. + * + * See the official + * [documentation](http://docs.libuv.org/en/v1.x/fs.html#c.uv_fs_mkstemp) + * for further details. + * + * @param tpl Template, as described in the official documentation. + * + * @return A pair where: + + * * The first parameter is a boolean value that is true in case of success, + * false otherwise. + * * The second parameter is a composed value (see above). + */ + std::pair> mkstempSync(std::string tpl) { + std::pair> ret{false, {}}; + auto req = get(); + cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data()); + ret.first = !(req->result < 0); + + if(ret.first) { + ret.second.first = req->path; + ret.second.second = static_cast(req->result); + } + + return ret; + } + /** * @brief Async [rmdir](http://linux.die.net/man/2/rmdir). * diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index 0d31f6a3..6c9a3466 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -1004,11 +1004,19 @@ struct Utilities { * [`gettimeofday`](https://linux.die.net/man/2/gettimeofday) * @return The current time. */ - static TimeVal64 timeOfDay() { + static TimeVal64 timeOfDay() noexcept { uv_timeval64_t ret; uv_gettimeofday(&ret); return ret; } + + /** + * @brief Causes the calling thread to sleep for a while. + * @param msec Number of milliseconds to sleep. + */ + static void sleep(unsigned int msec) noexcept { + uv_sleep(msec); + } };