uvw is now a C++17 only library (close #155)
This commit is contained in:
parent
6ce60d4088
commit
749581309e
24
.travis.yml
24
.travis.yml
@ -9,23 +9,21 @@ matrix:
|
|||||||
include:
|
include:
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
language: cpp
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
packages: ['g++-6']
|
packages: ['g++-7']
|
||||||
env: COMPILER=g++-6
|
env: COMPILER=g++-7
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
|
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
|
||||||
packages: ['clang-4.0', 'libstdc++-4.9-dev']
|
packages: ['clang-6.0', 'g++-7']
|
||||||
env: COMPILER=clang++-4.0
|
env: COMPILER=clang++-6.0
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8.3
|
osx_image: xcode10
|
||||||
compiler: clang
|
compiler: clang
|
||||||
language: cpp
|
|
||||||
env: COMPILER=clang++
|
env: COMPILER=clang++
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
@ -33,15 +31,15 @@ matrix:
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
sources: ['ubuntu-toolchain-r-test']
|
||||||
packages: ['g++-6']
|
packages: ['g++-7']
|
||||||
env:
|
env:
|
||||||
- C_COMPILER=gcc-6
|
- C_COMPILER=gcc-7
|
||||||
- COMPILER=g++-6
|
- COMPILER=g++-7
|
||||||
- CXXFLAGS="-O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
|
- CXXFLAGS="-O0 --coverage -fno-inline -fno-inline-small-functions -fno-default-inline"
|
||||||
before_script:
|
before_script:
|
||||||
- pip install --user cpp-coveralls
|
- pip install --user cpp-coveralls
|
||||||
after_success:
|
after_success:
|
||||||
- coveralls --gcov gcov-6 --gcov-options '\-lp' --root ${TRAVIS_BUILD_DIR} --build-root ${TRAVIS_BUILD_DIR}/build --extension cpp --extension hpp --exclude deps --include src
|
- coveralls --gcov gcov-7 --gcov-options '\-lp' --root ${TRAVIS_BUILD_DIR} --build-root ${TRAVIS_BUILD_DIR}/build --extension cpp --extension hpp --exclude deps --include src
|
||||||
- os: linux
|
- os: linux
|
||||||
dist: xenial
|
dist: xenial
|
||||||
sudo: true
|
sudo: true
|
||||||
@ -75,5 +73,5 @@ install:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p build && cd build
|
- mkdir -p build && cd build
|
||||||
- cmake .. -DBUILD_TESTING=ON && make -j4
|
- cmake .. -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF && make -j4
|
||||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j4 -R uvw
|
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j4 -R uvw
|
||||||
|
|||||||
5
AUTHORS
5
AUTHORS
@ -1,10 +1,10 @@
|
|||||||
# Author
|
# Author
|
||||||
|
|
||||||
Michele Caini aka skypjack
|
skypjack
|
||||||
|
|
||||||
# Collaborators
|
# Collaborators
|
||||||
|
|
||||||
Paolo Monteverde aka morbo84
|
morbo84
|
||||||
|
|
||||||
# Contributors
|
# Contributors
|
||||||
|
|
||||||
@ -21,3 +21,4 @@ Miigon
|
|||||||
slyshykO
|
slyshykO
|
||||||
bmagistro
|
bmagistro
|
||||||
richardbmx
|
richardbmx
|
||||||
|
wnsgml972
|
||||||
|
|||||||
@ -16,7 +16,7 @@ endif()
|
|||||||
# Project configuration
|
# Project configuration
|
||||||
#
|
#
|
||||||
|
|
||||||
project(uvw VERSION 1.18.0)
|
project(uvw VERSION 2.0.0)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
@ -30,7 +30,7 @@ message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
|
|||||||
message("* Copyright (c) 2016-2019 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
|
message("* Copyright (c) 2016-2019 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
|
||||||
message("*")
|
message("*")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
|
|||||||
@ -10,11 +10,11 @@ platform:
|
|||||||
- Win32
|
- Win32
|
||||||
|
|
||||||
configuration:
|
configuration:
|
||||||
- Release
|
- Debug
|
||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
- cd %BUILD_DIR%
|
- cd %BUILD_DIR%
|
||||||
- cmake .. -DBUILD_TESTING=ON -G"Visual Studio 15 2017"
|
- cmake .. -DBUILD_TESTING=ON -Dlibuv_buildtests=OFF -G"Visual Studio 15 2017"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
parallel: true
|
parallel: true
|
||||||
|
|||||||
@ -17,7 +17,7 @@ ExternalProject_Add(
|
|||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
libuv
|
libuv
|
||||||
GIT_REPOSITORY https://github.com/libuv/libuv.git
|
GIT_REPOSITORY https://github.com/libuv/libuv.git
|
||||||
GIT_TAG v1.30.0
|
GIT_TAG v1.30.1
|
||||||
SOURCE_DIR @LIBUV_DEPS_DIR@
|
SOURCE_DIR @LIBUV_DEPS_DIR@
|
||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_COMMAND ""
|
BUILD_COMMAND ""
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace uvw {
|
|||||||
* Custom wrapper around error constants of `libuv`.
|
* Custom wrapper around error constants of `libuv`.
|
||||||
*/
|
*/
|
||||||
struct ErrorEvent {
|
struct ErrorEvent {
|
||||||
template<typename U, typename = std::enable_if_t<std::is_integral<U>::value>>
|
template<typename U, typename = std::enable_if_t<std::is_integral_v<U>>>
|
||||||
explicit ErrorEvent(U val) noexcept
|
explicit ErrorEvent(U val) noexcept
|
||||||
: ec{static_cast<int>(val)}
|
: ec{static_cast<int>(val)}
|
||||||
{}
|
{}
|
||||||
@ -218,7 +218,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Emitter() noexcept {
|
virtual ~Emitter() noexcept {
|
||||||
static_assert(std::is_base_of<Emitter<T>, T>::value, "!");
|
static_assert(std::is_base_of_v<Emitter<T>, T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename F>
|
template<typename F>
|
||||||
F * sym(std::string name) {
|
F * sym(std::string name) {
|
||||||
static_assert(std::is_function<F>::value, "!");
|
static_assert(std::is_function_v<F>);
|
||||||
F *func;
|
F *func;
|
||||||
auto err = uv_dlsym(get(), name.data(), reinterpret_cast<void**>(&func));
|
auto err = uv_dlsym(get(), name.data(), reinterpret_cast<void**>(&func));
|
||||||
if(err) { func = nullptr; }
|
if(err) { func = nullptr; }
|
||||||
|
|||||||
@ -236,7 +236,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates resources of handles' types.
|
* @brief Creates resources of any type.
|
||||||
*
|
*
|
||||||
* This should be used as a default method to create resources.<br/>
|
* This should be used as a default method to create resources.<br/>
|
||||||
* The arguments are the ones required for the specific resource.
|
* The arguments are the ones required for the specific resource.
|
||||||
@ -246,27 +246,14 @@ public:
|
|||||||
* @return A pointer to the newly created resource.
|
* @return A pointer to the newly created resource.
|
||||||
*/
|
*/
|
||||||
template<typename R, typename... Args>
|
template<typename R, typename... Args>
|
||||||
std::enable_if_t<std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>
|
std::shared_ptr<R> resource(Args&&... args) {
|
||||||
resource(Args&&... args) {
|
if constexpr(std::is_base_of_v<BaseHandle, R>) {
|
||||||
auto ptr = R::create(shared_from_this(), std::forward<Args>(args)...);
|
auto ptr = R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||||
ptr = ptr->init() ? ptr : nullptr;
|
ptr = ptr->init() ? ptr : nullptr;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
} else {
|
||||||
|
return R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||||
/**
|
}
|
||||||
* @brief Creates resources of types other than handles' ones.
|
|
||||||
*
|
|
||||||
* This should be used as a default method to create resources.<br/>
|
|
||||||
* The arguments are the ones required for the specific resource.
|
|
||||||
*
|
|
||||||
* Use it as `loop->resource<uvw::WorkReq>()`.
|
|
||||||
*
|
|
||||||
* @return A pointer to the newly created resource.
|
|
||||||
*/
|
|
||||||
template<typename R, typename... Args>
|
|
||||||
std::enable_if_t<not std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>
|
|
||||||
resource(Args&&... args) {
|
|
||||||
return R::create(shared_from_this(), std::forward<Args>(args)...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -28,18 +28,15 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename... Args>
|
template<typename F, typename... Args>
|
||||||
auto invoke(F &&f, Args&&... args)
|
auto invoke(F &&f, Args&&... args) {
|
||||||
-> std::enable_if_t<not std::is_void<std::result_of_t<F(Args...)>>::value> {
|
if constexpr(std::is_void_v<std::invoke_result_t<F, Args...>>) {
|
||||||
auto err = std::forward<F>(f)(std::forward<Args>(args)...);
|
std::forward<F>(f)(std::forward<Args>(args)...);
|
||||||
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
|
this->leak();
|
||||||
else { this->leak(); }
|
} else {
|
||||||
}
|
auto err = std::forward<F>(f)(std::forward<Args>(args)...);
|
||||||
|
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
|
||||||
template<typename F, typename... Args>
|
else { this->leak(); }
|
||||||
auto invoke(F &&f, Args&&... args)
|
}
|
||||||
-> std::enable_if_t<std::is_void<std::result_of_t<F(Args...)>>::value> {
|
|
||||||
std::forward<F>(f)(std::forward<Args>(args)...);
|
|
||||||
this->leak();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -192,7 +192,7 @@ public:
|
|||||||
template<typename F>
|
template<typename F>
|
||||||
static void once(F &&f) noexcept {
|
static void once(F &&f) noexcept {
|
||||||
using CallbackType = void(*)(void);
|
using CallbackType = void(*)(void);
|
||||||
static_assert(std::is_convertible<F, CallbackType>::value, "!");
|
static_assert(std::is_convertible_v<F, CallbackType>);
|
||||||
CallbackType cb = f;
|
CallbackType cb = f;
|
||||||
uv_once(guard(), cb);
|
uv_once(guard(), cb);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,36 +23,21 @@ class UnderlyingType {
|
|||||||
protected:
|
protected:
|
||||||
struct ConstructorAccess { explicit ConstructorAccess(int) {} };
|
struct ConstructorAccess { explicit ConstructorAccess(int) {} };
|
||||||
|
|
||||||
|
template<typename R = U>
|
||||||
auto get() noexcept {
|
auto get() noexcept {
|
||||||
return &resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto get() const noexcept {
|
|
||||||
return &resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
auto get() noexcept {
|
|
||||||
static_assert(not std::is_same<R, U>::value, "!");
|
|
||||||
return reinterpret_cast<R *>(&resource);
|
return reinterpret_cast<R *>(&resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename R = U>
|
||||||
|
auto get() const noexcept {
|
||||||
|
return reinterpret_cast<const R *>(&resource);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename R, typename... P>
|
template<typename R, typename... P>
|
||||||
auto get(UnderlyingType<P...> &other) noexcept {
|
auto get(UnderlyingType<P...> &other) noexcept {
|
||||||
return reinterpret_cast<R *>(&other.resource);
|
return reinterpret_cast<R *>(&other.resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
auto get() const noexcept {
|
|
||||||
static_assert(not std::is_same<R, U>::value, "!");
|
|
||||||
return reinterpret_cast<const R *>(&resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename R, typename... P>
|
|
||||||
auto get(const UnderlyingType<P...> &other) const noexcept {
|
|
||||||
return reinterpret_cast<const R *>(&other.resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UnderlyingType(ConstructorAccess, std::shared_ptr<Loop> ref) noexcept
|
explicit UnderlyingType(ConstructorAccess, std::shared_ptr<Loop> ref) noexcept
|
||||||
: pLoop{std::move(ref)}, resource{}
|
: pLoop{std::move(ref)}, resource{}
|
||||||
@ -62,7 +47,7 @@ public:
|
|||||||
UnderlyingType(UnderlyingType &&) = delete;
|
UnderlyingType(UnderlyingType &&) = delete;
|
||||||
|
|
||||||
virtual ~UnderlyingType() {
|
virtual ~UnderlyingType() {
|
||||||
static_assert(std::is_base_of<UnderlyingType<T, U>, T>::value, "!");
|
static_assert(std::is_base_of_v<UnderlyingType<T, U>, T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnderlyingType & operator=(const UnderlyingType &) = delete;
|
UnderlyingType & operator=(const UnderlyingType &) = delete;
|
||||||
|
|||||||
@ -13,14 +13,6 @@
|
|||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// MSVC doesn't have C++14 relaxed constexpr support yet. Hence the jugglery.
|
|
||||||
#define CONSTEXPR_SPECIFIER
|
|
||||||
#else
|
|
||||||
#define CONSTEXPR_SPECIFIER constexpr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace uvw {
|
namespace uvw {
|
||||||
|
|
||||||
|
|
||||||
@ -100,10 +92,8 @@ public:
|
|||||||
* @return A valid instance of Flags instantiated from values `V`.
|
* @return A valid instance of Flags instantiated from values `V`.
|
||||||
*/
|
*/
|
||||||
template<E... V>
|
template<E... V>
|
||||||
static CONSTEXPR_SPECIFIER Flags<E> from() {
|
static constexpr Flags<E> from() {
|
||||||
auto flags = Flags<E>{};
|
return (Flags<E>{} | ... | V);
|
||||||
int _[] = { 0, (flags = flags | V, 0)... };
|
|
||||||
return void(_), flags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,14 +117,14 @@ public:
|
|||||||
constexpr Flags(const Flags &f) noexcept: flags{f.flags} { }
|
constexpr Flags(const Flags &f) noexcept: flags{f.flags} { }
|
||||||
constexpr Flags(Flags &&f) noexcept: flags{std::move(f.flags)} { }
|
constexpr Flags(Flags &&f) noexcept: flags{std::move(f.flags)} { }
|
||||||
|
|
||||||
~Flags() noexcept { static_assert(std::is_enum<E>::value, "!"); }
|
~Flags() noexcept { static_assert(std::is_enum_v<E>); }
|
||||||
|
|
||||||
CONSTEXPR_SPECIFIER Flags & operator=(const Flags &f) noexcept {
|
constexpr Flags & operator=(const Flags &f) noexcept {
|
||||||
flags = f.flags;
|
flags = f.flags;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSTEXPR_SPECIFIER Flags & operator=(Flags &&f) noexcept {
|
constexpr Flags & operator=(Flags &&f) noexcept {
|
||||||
flags = std::move(f.flags);
|
flags = std::move(f.flags);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,14 +83,12 @@ TEST(TCP, SockPeer) {
|
|||||||
uvw::Addr addr = handle.sock();
|
uvw::Addr addr = handle.sock();
|
||||||
|
|
||||||
ASSERT_EQ(addr.ip, address);
|
ASSERT_EQ(addr.ip, address);
|
||||||
ASSERT_EQ(addr.port, decltype(addr.port){port});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client->once<uvw::ConnectEvent>([&address](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
|
client->once<uvw::ConnectEvent>([&address](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
|
||||||
uvw::Addr addr = handle.peer();
|
uvw::Addr addr = handle.peer();
|
||||||
|
|
||||||
ASSERT_EQ(addr.ip, address);
|
ASSERT_EQ(addr.ip, address);
|
||||||
ASSERT_NE(addr.port, decltype(addr.port){0});
|
|
||||||
|
|
||||||
handle.close();
|
handle.close();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user