From 857d652ddf8cb72f573bb32d1db7a40da1bdcae5 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 22 Aug 2018 23:37:37 +0200 Subject: [PATCH] now working with libuv v1.23.x --- CMakeLists.txt | 2 +- cmake/in/deps.in | 2 +- src/uvw/fs.hpp | 52 +++++++++++++++++++++++++++++++--------------- src/uvw/idle.hpp | 5 +++-- src/uvw/stream.hpp | 3 ++- src/uvw/util.hpp | 52 ++++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 90 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd1e2777..0ba2f88f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ endif() # Project configuration # -project(uvw VERSION 1.10.1) +project(uvw VERSION 1.11.0) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) diff --git a/cmake/in/deps.in b/cmake/in/deps.in index 8eb0ae90..df9927cc 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.22.0 + GIT_TAG v1.23.0 SOURCE_DIR @LIBUV_DEPS_DIR@ CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index 30373c3a..492bb2a9 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -47,9 +47,9 @@ enum class UVFsType: std::underlying_type_t { READLINK = UV_FS_READLINK, CHOWN = UV_FS_CHOWN, FCHOWN = UV_FS_FCHOWN, - LCHOWN = UV_FS_LCHOWN, REALPATH = UV_FS_REALPATH, - COPYFILE = UV_FS_COPYFILE + COPYFILE = UV_FS_COPYFILE, + LCHOWN = UV_FS_LCHOWN }; @@ -140,9 +140,9 @@ enum class UVSymLinkFlags: int { * * `FsRequest::Type::READLINK` * * `FsRequest::Type::CHOWN` * * `FsRequest::Type::FCHOWN` - * * `FsRequest::Type::LCHOWN` * * `FsRequest::Type::REALPATH` * * `FsRequest::Type::COPYFILE` + * * `FsRequest::Type::LCHOWN` * * It will be emitted by FsReq and/or FileReq according with their * functionalities. @@ -797,20 +797,6 @@ public: return !(req->result < 0); } - /** - * @brief Gets the OS dependent handle. - * - * For a file descriptor in the C runtime, get the OS-dependent handle. On - * UNIX, returns the file descriptor as-is. On Windows, this calls a system - * function.
- * Note that the return value is still owned by the C runtime, any attempts - * to close it or to use it after closing the file descriptor may lead to - * malfunction. - */ - OSFileDescriptor handle() const noexcept { - return uv_get_osfhandle(file); - } - /** * @brief Cast operator to FileHandle. * @@ -1427,4 +1413,36 @@ public: }; +/*! @brief Helper functions. */ +struct FsHelper { + /** + * @brief Gets the OS dependent handle. + * + * For a file descriptor in the C runtime, get the OS-dependent handle. On + * UNIX, returns the file descriptor as-is. On Windows, this calls a system + * function.
+ * Note that the return value is still owned by the C runtime, any attempts + * to close it or to use it after closing the file descriptor may lead to + * malfunction. + */ + static OSFileDescriptor handle(FileHandle file) noexcept { + return uv_get_osfhandle(file); + } + + /** + * @brief Gets the file descriptor. + * + * For a OS-dependent handle, get the file descriptor in the C runtime. On + * UNIX, returns the file descriptor as-is. On Windows, this calls a system + * function.
+ * Note that the return value is still owned by the C runtime, any attempts + * to close it or to use it after closing the handle may lead to + * malfunction. + */ + static FileHandle open(OSFileDescriptor descriptor) noexcept { + return uv_open_osfhandle(descriptor); + } +}; + + } diff --git a/src/uvw/idle.hpp b/src/uvw/idle.hpp index abfcdfce..13b2a1b3 100644 --- a/src/uvw/idle.hpp +++ b/src/uvw/idle.hpp @@ -29,8 +29,9 @@ struct IdleEvent {}; * idle handles, the loop will perform a zero timeout poll instead of blocking * for I/O. * - * **Note**: despite the name, idle handles will emit events on every loop - * iteration, not when the loop is actually _idle_. + * @note + * Despite the name, idle handles will emit events on every loop iteration, not + * when the loop is actually _idle_. * * To create an `IdleHandle` through a `Loop`, no arguments are required. */ diff --git a/src/uvw/stream.hpp b/src/uvw/stream.hpp index 8ae28ec1..f1e929b4 100644 --- a/src/uvw/stream.hpp +++ b/src/uvw/stream.hpp @@ -212,7 +212,8 @@ public: * it more than once, it may fail.
* It is suggested to only call this function once per ListenEvent event. * - * **Note**: both the handles must be running on the same loop. + * @note + * Both the handles must be running on the same loop. * * @param ref An initialized handle to be used to accept the connection. */ diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index 17ff8f64..40cc556f 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -544,6 +545,48 @@ struct Utilities { } }; + /** + * @brief Retrieves the scheduling priority of a process. + * + * The returned value is between -20 (high priority) and 19 (low priority). + * A value that is out of range is returned in case of errors. + * + * @note + * On Windows, the result won't equal necessarily the exact value of the + * priority because of a mapping to a Windows priority class. + * + * @param pid A valid process id. + * @return The scheduling priority of the process. + */ + static int osPriority(PidType pid) { + int prio = 0; + + if(uv_os_getpriority(pid, &prio)) { + prio = UV_PRIORITY_LOW + 1; + } + + return prio; + } + + /** + * @brief Sets the scheduling priority of a process. + * + * The returned value range is between -20 (high priority) and 19 (low + * priority). + * + * @note + * On Windows, the priority is mapped to a Windows priority class. When + * retrieving the process priority, the result won't equal necessarily the + * exact value of the priority. + * + * @param pid A valid process id. + * @param prio The scheduling priority to set to the process. + * @return True in case of success, false otherwise. + */ + static bool osPriority(PidType pid, int prio) { + return 0 == uv_os_setpriority(pid, prio); + } + /** * @brief Gets the type of the handle given a category. * @param category A properly initialized handle category. @@ -719,10 +762,11 @@ struct Utilities { * * If any of the function pointers is _null_, the invokation will fail. * - * **Note**: there is no protection against changing the allocator multiple - * times. If the user changes it they are responsible for making sure the - * allocator is changed while no memory was allocated with the previous - * allocator, or that they are compatible. + * @note + * There is no protection against changing the allocator multiple times. If + * the user changes it they are responsible for making sure the allocator is + * changed while no memory was allocated with the previous allocator, or + * that they are compatible. * * @param mallocFunc Replacement function for _malloc_. * @param reallocFunc Replacement function for _realloc_.