Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68ed09d929 | ||
|
|
1c930cdcb5 |
@ -4,13 +4,13 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
void listen(uvw::Loop &loop) {
|
void listen(uvw::Loop &loop) {
|
||||||
std::shared_ptr<uvw::TcpHandle> tcp = loop.resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &srv) {
|
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
|
||||||
std::shared_ptr<uvw::TcpHandle> client = srv.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
client->on<uvw::CloseEvent>([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TcpHandle &) { ptr->close(); });
|
client->on<uvw::CloseEvent>([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TCPHandle &) { ptr->close(); });
|
||||||
client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); });
|
client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); });
|
||||||
|
|
||||||
srv.accept(*client);
|
srv.accept(*client);
|
||||||
client->read();
|
client->read();
|
||||||
@ -21,11 +21,11 @@ void listen(uvw::Loop &loop) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void conn(uvw::Loop &loop) {
|
void conn(uvw::Loop &loop) {
|
||||||
auto tcp = loop.resource<uvw::TcpHandle>();
|
auto tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* handle errors */ });
|
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* handle errors */ });
|
||||||
|
|
||||||
tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TcpHandle &tcp) {
|
tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &tcp) {
|
||||||
auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
|
auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
|
||||||
tcp.write(std::move(dataWrite), 2);
|
tcp.write(std::move(dataWrite), 2);
|
||||||
tcp.close();
|
tcp.close();
|
||||||
@ -45,4 +45,4 @@ int main() {
|
|||||||
std::cout << "Done!\n";
|
std::cout << "Done!\n";
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
|
|||||||
message("* Copyright (c) 2016-2018 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
|
message("* Copyright (c) 2016-2018 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
|
||||||
message("*")
|
message("*")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
@ -67,7 +67,8 @@ if(DOXYGEN_FOUND)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
enable_testing()
|
set(BUILD_TESTING OFF)
|
||||||
|
|
||||||
set(GOOGLETEST_DEPS_DIR ${PROJECT_DEPS_DIR}/googletest)
|
set(GOOGLETEST_DEPS_DIR ${PROJECT_DEPS_DIR}/googletest)
|
||||||
set(LIBUV_DEPS_DIR ${PROJECT_DEPS_DIR}/libuv)
|
set(LIBUV_DEPS_DIR ${PROJECT_DEPS_DIR}/libuv)
|
||||||
|
|
||||||
@ -83,6 +84,9 @@ if(BUILD_TESTING)
|
|||||||
add_subdirectory(${LIBUV_DEPS_DIR})
|
add_subdirectory(${LIBUV_DEPS_DIR})
|
||||||
include_directories(${LIBUV_DEPS_DIR}/include)
|
include_directories(${LIBUV_DEPS_DIR}/include)
|
||||||
|
|
||||||
|
set(BUILD_TESTING ON)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
42
README.md
42
README.md
@ -30,14 +30,14 @@ As an example, a *handle* should be initialized before any other operation and c
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
void listen(uvw::Loop &loop) {
|
void listen(uvw::Loop &loop) {
|
||||||
std::shared_ptr<uvw::TcpHandle> tcp = loop.resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &srv) {
|
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
|
||||||
std::shared_ptr<uvw::TcpHandle> client = srv.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
client->on<uvw::CloseEvent>([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TcpHandle &) { ptr->close(); });
|
|
||||||
client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); });
|
|
||||||
|
|
||||||
|
auto ptr = srv.shared_from_this();
|
||||||
|
client->on<uvw::CloseEvent>([ptr](const uvw::CloseEvent &, uvw::TCPHandle &) { ptr->close(); });
|
||||||
|
client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); });
|
||||||
srv.accept(*client);
|
srv.accept(*client);
|
||||||
client->read();
|
client->read();
|
||||||
});
|
});
|
||||||
@ -47,11 +47,11 @@ void listen(uvw::Loop &loop) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void conn(uvw::Loop &loop) {
|
void conn(uvw::Loop &loop) {
|
||||||
auto tcp = loop.resource<uvw::TcpHandle>();
|
auto tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* handle errors */ });
|
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* handle errors */ });
|
||||||
|
|
||||||
tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TcpHandle &tcp) {
|
tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &tcp) {
|
||||||
auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
|
auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
|
||||||
tcp.write(std::move(dataWrite), 2);
|
tcp.write(std::move(dataWrite), 2);
|
||||||
tcp.close();
|
tcp.close();
|
||||||
@ -78,7 +78,7 @@ The main reason for which `uvw` has been written is the fact that it does not ex
|
|||||||
|
|
||||||
To be able to use `uvw`, users must provide the following system-wide tools:
|
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++11.
|
||||||
* `libuv` (which version depends on the tag of `uvw` in use).
|
* `libuv` (which version depends on the tag of `uvw` in use).
|
||||||
|
|
||||||
The requirements below are mandatory to compile the tests and to extract the documentation:
|
The requirements below are mandatory to compile the tests and to extract the documentation:
|
||||||
@ -202,7 +202,7 @@ Available modes are: `DEFAULT`, `ONCE`, `NOWAIT`. Please refer to the documentat
|
|||||||
In order to create a resource and to bind it to the given loop, just do the following:
|
In order to create a resource and to bind it to the given loop, just do the following:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto tcp = loop.resource<uvw::TcpHandle>();
|
auto tcp = loop.resource<uvw::TCPHandle>();
|
||||||
```
|
```
|
||||||
|
|
||||||
The line above will create and initialize a tcp handle, then a shared pointer to that resource will be returned.<br/>
|
The line above will create and initialize a tcp handle, then a shared pointer to that resource will be returned.<br/>
|
||||||
@ -210,7 +210,7 @@ Users should check if pointers have been correctly initialized: in case of error
|
|||||||
Another way to create a resource is:
|
Another way to create a resource is:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto tcp = TcpHandle::create(loop);
|
auto tcp = TCPHandle::create(loop);
|
||||||
tcp->init();
|
tcp->init();
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ There exist two methods to attach an event to a resource:
|
|||||||
* `resource.once<EventType>(listener)`: the listener will be automatically removed after the first event of the given type.
|
* `resource.once<EventType>(listener)`: the listener will be automatically removed after the first event of the given type.
|
||||||
* `resource.on<EventType>(listener)`: to be used for long-running listeners.
|
* `resource.on<EventType>(listener)`: to be used for long-running listeners.
|
||||||
|
|
||||||
Both of them return an object of type `ResourceType::Connection` (as an example, `TcpHandle::Connection`).<br/>
|
Both of them return an object of type `ResourceType::Connection` (as an example, `TCPHandle::Connection`).<br/>
|
||||||
A connection object can be used later as an argument to the `erase` member function of the resource to remove the listener.<br/>
|
A connection object can be used later as an argument to the `erase` member function of the resource to remove the listener.<br/>
|
||||||
There exists also the `clear` member function to drop all the listeners at once.
|
There exists also the `clear` member function to drop all the listeners at once.
|
||||||
|
|
||||||
@ -283,14 +283,14 @@ The code below shows how to create a simple tcp server using `uvw`:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto tcp = loop.resource<uvw::TcpHandle>();
|
auto tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* something went wrong */ });
|
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* something went wrong */ });
|
||||||
|
|
||||||
tcp->on<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &srv) {
|
tcp->on<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
|
||||||
std::shared_ptr<uvw::TcpHandle> client = srv.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();
|
||||||
client->once<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); });
|
client->once<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); });
|
||||||
client->on<uvw::DataEvent>([](const uvw::DataEvent &, uvw::TcpHandle &) { /* data received */ });
|
client->on<uvw::DataEvent>([](const uvw::DataEvent &, uvw::TCPHandle &) { /* data received */ });
|
||||||
srv.accept(*client);
|
srv.accept(*client);
|
||||||
client->read();
|
client->read();
|
||||||
});
|
});
|
||||||
@ -299,7 +299,7 @@ tcp->bind("127.0.0.1", 4242);
|
|||||||
tcp->listen();
|
tcp->listen();
|
||||||
```
|
```
|
||||||
|
|
||||||
Note also that `uvw::TcpHandle` already supports _IPv6_ out-of-the-box. The statement above is equivalent to `tcp->bind<uvw::IPv4>("127.0.0.1", 4242)`.<br/>
|
Note also that `uvw::TCPHandle` already supports _IPv6_ out-of-the-box. The statement above is equivalent to `tcp->bind<uvw::IPv4>("127.0.0.1", 4242)`.<br/>
|
||||||
It's suffice to explicitly specify `uvw::IPv6` as the underlying protocol to use it.
|
It's suffice to explicitly specify `uvw::IPv6` as the underlying protocol to use it.
|
||||||
|
|
||||||
The API reference is the recommended documentation for further details about resources and their methods.
|
The API reference is the recommended documentation for further details about resources and their methods.
|
||||||
@ -319,7 +319,7 @@ That being said, _going raw_ is a matter of using the `raw` member functions:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto tcp = loop.resource<uvw::TcpHandle>();
|
auto tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
uv_loop_t *raw = loop->raw();
|
uv_loop_t *raw = loop->raw();
|
||||||
uv_tcp_t *handle = tcp->raw();
|
uv_tcp_t *handle = tcp->raw();
|
||||||
|
|||||||
@ -14,7 +14,7 @@ configuration:
|
|||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
- cd %BUILD_DIR%
|
- cd %BUILD_DIR%
|
||||||
- cmake .. -G"Visual Studio 15 2017"
|
- cmake .. -DBUILD_TESTING=ON -G"Visual Studio 15 2017"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
parallel: true
|
parallel: true
|
||||||
|
|||||||
@ -89,7 +89,7 @@ class GetAddrInfoReq final: public Request<GetAddrInfoReq, uv_getaddrinfo_t> {
|
|||||||
invoke(&uv_getaddrinfo, parent(), get(), &addrInfoCallback, node, service, hints);
|
invoke(&uv_getaddrinfo, parent(), get(), &addrInfoCallback, node, service, hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nodeAddrInfoSync(const char *node, const char *service, addrinfo *hints = nullptr) {
|
auto nodeAddrInfoSync(const char *node, const char *service, addrinfo *hints = nullptr) -> std::pair<int, std::unique_ptr<addrinfo, void(*)(addrinfo *)>> {
|
||||||
auto req = get();
|
auto req = get();
|
||||||
auto err = uv_getaddrinfo(parent(), req, nullptr, node, service, hints);
|
auto err = uv_getaddrinfo(parent(), req, nullptr, node, service, hints);
|
||||||
auto data = std::unique_ptr<addrinfo, void(*)(addrinfo *)>{req->addrinfo, [](addrinfo *addr){ uv_freeaddrinfo(addr); }};
|
auto data = std::unique_ptr<addrinfo, void(*)(addrinfo *)>{req->addrinfo, [](addrinfo *addr){ uv_freeaddrinfo(addr); }};
|
||||||
|
|||||||
@ -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 V = typename std::enable_if<std::is_integral<U>::value>::type>
|
||||||
explicit ErrorEvent(U val) noexcept
|
explicit ErrorEvent(U val) noexcept
|
||||||
: ec{static_cast<int>(val)}
|
: ec{static_cast<int>(val)}
|
||||||
{}
|
{}
|
||||||
@ -99,7 +99,7 @@ class Emitter {
|
|||||||
using Connection = typename ListenerList::iterator;
|
using Connection = typename ListenerList::iterator;
|
||||||
|
|
||||||
bool empty() const noexcept override {
|
bool empty() const noexcept override {
|
||||||
auto pred = [](auto &&element){ return element.first; };
|
auto pred = [](const Element &element){ return element.first; };
|
||||||
|
|
||||||
return std::all_of(onceL.cbegin(), onceL.cend(), pred) &&
|
return std::all_of(onceL.cbegin(), onceL.cend(), pred) &&
|
||||||
std::all_of(onL.cbegin(), onL.cend(), pred);
|
std::all_of(onL.cbegin(), onL.cend(), pred);
|
||||||
@ -107,7 +107,7 @@ class Emitter {
|
|||||||
|
|
||||||
void clear() noexcept override {
|
void clear() noexcept override {
|
||||||
if(publishing) {
|
if(publishing) {
|
||||||
auto func = [](auto &&element){ element.first = true; };
|
auto func = [](Element &element){ element.first = true; };
|
||||||
std::for_each(onceL.begin(), onceL.end(), func);
|
std::for_each(onceL.begin(), onceL.end(), func);
|
||||||
std::for_each(onL.begin(), onL.end(), func);
|
std::for_each(onL.begin(), onL.end(), func);
|
||||||
} else {
|
} else {
|
||||||
@ -117,18 +117,18 @@ class Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Connection once(Listener f) {
|
Connection once(Listener f) {
|
||||||
return onceL.emplace(onceL.cend(), false, std::move(f));
|
return onceL.emplace(onceL.end(), false, std::move(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection on(Listener f) {
|
Connection on(Listener f) {
|
||||||
return onL.emplace(onL.cend(), false, std::move(f));
|
return onL.emplace(onL.end(), false, std::move(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(Connection conn) noexcept {
|
void erase(Connection conn) noexcept {
|
||||||
conn->first = true;
|
conn->first = true;
|
||||||
|
|
||||||
if(!publishing) {
|
if(!publishing) {
|
||||||
auto pred = [](auto &&element){ return element.first; };
|
auto pred = [](const Element &element){ return element.first; };
|
||||||
onceL.remove_if(pred);
|
onceL.remove_if(pred);
|
||||||
onL.remove_if(pred);
|
onL.remove_if(pred);
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ class Emitter {
|
|||||||
ListenerList currentL;
|
ListenerList currentL;
|
||||||
onceL.swap(currentL);
|
onceL.swap(currentL);
|
||||||
|
|
||||||
auto func = [&event, &ref](auto &&element) {
|
auto func = [&event, &ref](Element &element) {
|
||||||
return element.first ? void() : element.second(event, ref);
|
return element.first ? void() : element.second(event, ref);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ class Emitter {
|
|||||||
|
|
||||||
publishing = false;
|
publishing = false;
|
||||||
|
|
||||||
onL.remove_if([](auto &&element){ return element.first; });
|
onL.remove_if([](const Element &element){ return element.first; });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -178,7 +178,7 @@ class Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!handlers[type]) {
|
if(!handlers[type]) {
|
||||||
handlers[type] = std::make_unique<Handler<E>>();
|
handlers[type] = std::unique_ptr<Handler<E>>(new(std::nothrow) Handler<E>);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<Handler<E>&>(*handlers[type]);
|
return static_cast<Handler<E>&>(*handlers[type]);
|
||||||
@ -283,7 +283,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void clear() noexcept {
|
void clear() noexcept {
|
||||||
std::for_each(handlers.begin(), handlers.end(),
|
std::for_each(handlers.begin(), handlers.end(),
|
||||||
[](auto &&hdlr){ if(hdlr) { hdlr->clear(); } });
|
[](std::unique_ptr<BaseHandler> &hdlr){ if(hdlr) { hdlr->clear(); } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -307,7 +307,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool empty() const noexcept {
|
bool empty() const noexcept {
|
||||||
return std::all_of(handlers.cbegin(), handlers.cend(),
|
return std::all_of(handlers.cbegin(), handlers.cend(),
|
||||||
[](auto &&hdlr){ return !hdlr || hdlr->empty(); });
|
[](const std::unique_ptr<BaseHandler> &hdlr){ return !hdlr || hdlr->empty(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVFsType: std::underlying_type_t<uv_fs_type> {
|
enum class UVFsType: typename std::underlying_type<uv_fs_type>::type {
|
||||||
UNKNOWN = UV_FS_UNKNOWN,
|
UNKNOWN = UV_FS_UNKNOWN,
|
||||||
CUSTOM = UV_FS_CUSTOM,
|
CUSTOM = UV_FS_CUSTOM,
|
||||||
OPEN = UV_FS_OPEN,
|
OPEN = UV_FS_OPEN,
|
||||||
@ -53,7 +53,7 @@ enum class UVFsType: std::underlying_type_t<uv_fs_type> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum class UVDirentTypeT: std::underlying_type_t<uv_dirent_type_t> {
|
enum class UVDirentTypeT: typename std::underlying_type<uv_dirent_type_t>::type {
|
||||||
UNKNOWN = UV_DIRENT_UNKNOWN,
|
UNKNOWN = UV_DIRENT_UNKNOWN,
|
||||||
FILE = UV_DIRENT_FILE,
|
FILE = UV_DIRENT_FILE,
|
||||||
DIR = UV_DIRENT_DIR,
|
DIR = UV_DIRENT_DIR,
|
||||||
@ -220,7 +220,7 @@ struct FsEvent<details::UVFsType::SENDFILE> {
|
|||||||
template<>
|
template<>
|
||||||
struct FsEvent<details::UVFsType::STAT> {
|
struct FsEvent<details::UVFsType::STAT> {
|
||||||
FsEvent(const char *pathname, Stat curr) noexcept
|
FsEvent(const char *pathname, Stat curr) noexcept
|
||||||
: path{pathname}, stat{std::move(curr)}
|
: path{pathname}, stat(std::move(curr))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const char * path; /*!< The path affecting the request. */
|
const char * path; /*!< The path affecting the request. */
|
||||||
@ -237,7 +237,7 @@ struct FsEvent<details::UVFsType::STAT> {
|
|||||||
template<>
|
template<>
|
||||||
struct FsEvent<details::UVFsType::FSTAT> {
|
struct FsEvent<details::UVFsType::FSTAT> {
|
||||||
FsEvent(const char *pathname, Stat curr) noexcept
|
FsEvent(const char *pathname, Stat curr) noexcept
|
||||||
: path{pathname}, stat{std::move(curr)}
|
: path{pathname}, stat(std::move(curr))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const char * path; /*!< The path affecting the request. */
|
const char * path; /*!< The path affecting the request. */
|
||||||
@ -254,7 +254,7 @@ struct FsEvent<details::UVFsType::FSTAT> {
|
|||||||
template<>
|
template<>
|
||||||
struct FsEvent<details::UVFsType::LSTAT> {
|
struct FsEvent<details::UVFsType::LSTAT> {
|
||||||
FsEvent(const char *pathname, Stat curr) noexcept
|
FsEvent(const char *pathname, Stat curr) noexcept
|
||||||
: path{pathname}, stat{std::move(curr)}
|
: path{pathname}, stat(std::move(curr))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const char * path; /*!< The path affecting the request. */
|
const char * path; /*!< The path affecting the request. */
|
||||||
@ -809,7 +809,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<char[]> data{nullptr};
|
std::unique_ptr<char[]> data{nullptr};
|
||||||
uv_buf_t buffer{};
|
uv_buf_t buffer;
|
||||||
uv_file file{BAD_FD};
|
uv_file file{BAD_FD};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -16,14 +16,14 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVFsEventFlags: std::underlying_type_t<uv_fs_event_flags> {
|
enum class UVFsEventFlags: typename std::underlying_type<uv_fs_event_flags>::type {
|
||||||
WATCH_ENTRY = UV_FS_EVENT_WATCH_ENTRY,
|
WATCH_ENTRY = UV_FS_EVENT_WATCH_ENTRY,
|
||||||
STAT = UV_FS_EVENT_STAT,
|
STAT = UV_FS_EVENT_STAT,
|
||||||
RECURSIVE = UV_FS_EVENT_RECURSIVE
|
RECURSIVE = UV_FS_EVENT_RECURSIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum class UVFsEvent: std::underlying_type_t<uv_fs_event> {
|
enum class UVFsEvent: typename std::underlying_type<uv_fs_event>::type {
|
||||||
RENAME = UV_RENAME,
|
RENAME = UV_RENAME,
|
||||||
CHANGE = UV_CHANGE
|
CHANGE = UV_CHANGE
|
||||||
};
|
};
|
||||||
@ -79,7 +79,7 @@ class FsEventHandle final: public Handle<FsEventHandle, uv_fs_event_t> {
|
|||||||
static void startCallback(uv_fs_event_t *handle, const char *filename, int events, int status) {
|
static void startCallback(uv_fs_event_t *handle, const char *filename, int events, int status) {
|
||||||
FsEventHandle &fsEvent = *(static_cast<FsEventHandle*>(handle->data));
|
FsEventHandle &fsEvent = *(static_cast<FsEventHandle*>(handle->data));
|
||||||
if(status) { fsEvent.publish(ErrorEvent{status}); }
|
if(status) { fsEvent.publish(ErrorEvent{status}); }
|
||||||
else { fsEvent.publish(FsEventEvent{filename, static_cast<std::underlying_type_t<details::UVFsEvent>>(events)}); }
|
else { fsEvent.publish(FsEventEvent{filename, static_cast<typename std::underlying_type<details::UVFsEvent>::type>(events)}); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace uvw {
|
|||||||
*/
|
*/
|
||||||
struct FsPollEvent {
|
struct FsPollEvent {
|
||||||
explicit FsPollEvent(Stat previous, Stat current) noexcept
|
explicit FsPollEvent(Stat previous, Stat current) noexcept
|
||||||
: prev{std::move(previous)}, curr{std::move(current)}
|
: prev(std::move(previous)), curr(std::move(current))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Stat prev; /*!< The old Stat struct. */
|
Stat prev; /*!< The old Stat struct. */
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public:
|
|||||||
*
|
*
|
||||||
* * An AsyncHandle handle is always active and cannot be deactivated,
|
* * An AsyncHandle handle is always active and cannot be deactivated,
|
||||||
* except by closing it with uv_close().
|
* except by closing it with uv_close().
|
||||||
* * A PipeHandle, TcpHandle, UDPHandle, etc. handle - basically any handle
|
* * A PipeHandle, TCPHandle, UDPHandle, etc. handle - basically any handle
|
||||||
* that deals with I/O - is active when it is doing something that involves
|
* that deals with I/O - is active when it is doing something that involves
|
||||||
* I/O, like reading, writing, connecting, accepting new connections, etc.
|
* I/O, like reading, writing, connecting, accepting new connections, etc.
|
||||||
* * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it
|
* * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it
|
||||||
@ -183,8 +183,8 @@ public:
|
|||||||
*
|
*
|
||||||
* Gets the size of the send buffer that the operating system uses for the
|
* Gets the size of the send buffer that the operating system uses for the
|
||||||
* socket.<br/>
|
* socket.<br/>
|
||||||
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
|
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
|
||||||
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
|
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
|
||||||
* Note that Linux will return double the size of the original set value.
|
* Note that Linux will return double the size of the original set value.
|
||||||
*
|
*
|
||||||
* @return The size of the send buffer, 0 in case of errors.
|
* @return The size of the send buffer, 0 in case of errors.
|
||||||
@ -200,8 +200,8 @@ public:
|
|||||||
*
|
*
|
||||||
* Sets the size of the send buffer that the operating system uses for the
|
* Sets the size of the send buffer that the operating system uses for the
|
||||||
* socket.<br/>
|
* socket.<br/>
|
||||||
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
|
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
|
||||||
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
|
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
|
||||||
* Note that Linux will set double the size.
|
* Note that Linux will set double the size.
|
||||||
*
|
*
|
||||||
* @return True in case of success, false otherwise.
|
* @return True in case of success, false otherwise.
|
||||||
@ -215,8 +215,8 @@ public:
|
|||||||
*
|
*
|
||||||
* Gets the size of the receive buffer that the operating system uses for
|
* Gets the size of the receive buffer that the operating system uses for
|
||||||
* the socket.<br/>
|
* the socket.<br/>
|
||||||
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
|
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
|
||||||
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
|
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
|
||||||
* Note that Linux will return double the size of the original set value.
|
* Note that Linux will return double the size of the original set value.
|
||||||
*
|
*
|
||||||
* @return The size of the receive buffer, 0 in case of errors.
|
* @return The size of the receive buffer, 0 in case of errors.
|
||||||
@ -232,8 +232,8 @@ public:
|
|||||||
*
|
*
|
||||||
* Sets the size of the receive buffer that the operating system uses for
|
* Sets the size of the receive buffer that the operating system uses for
|
||||||
* the socket.<br/>
|
* the socket.<br/>
|
||||||
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
|
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
|
||||||
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
|
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
|
||||||
* Note that Linux will set double the size.
|
* Note that Linux will set double the size.
|
||||||
*
|
*
|
||||||
* @return True in case of success, false otherwise.
|
* @return True in case of success, false otherwise.
|
||||||
@ -247,7 +247,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Supported handles:
|
* Supported handles:
|
||||||
*
|
*
|
||||||
* * TcpHandle
|
* * TCPHandle
|
||||||
* * PipeHandle
|
* * PipeHandle
|
||||||
* * TTYHandle
|
* * TTYHandle
|
||||||
* * UDPHandle
|
* * UDPHandle
|
||||||
|
|||||||
@ -21,12 +21,12 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVLoopOption: std::underlying_type_t<uv_loop_option> {
|
enum class UVLoopOption: typename std::underlying_type<uv_loop_option>::type {
|
||||||
BLOCK_SIGNAL = UV_LOOP_BLOCK_SIGNAL
|
BLOCK_SIGNAL = UV_LOOP_BLOCK_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum class UVRunMode: std::underlying_type_t<uv_run_mode> {
|
enum class UVRunMode: typename std::underlying_type<uv_run_mode>::type {
|
||||||
DEFAULT = UV_RUN_DEFAULT,
|
DEFAULT = UV_RUN_DEFAULT,
|
||||||
ONCE = UV_RUN_ONCE,
|
ONCE = UV_RUN_ONCE,
|
||||||
NOWAIT = UV_RUN_NOWAIT
|
NOWAIT = UV_RUN_NOWAIT
|
||||||
@ -74,7 +74,7 @@ struct BaseHandle {
|
|||||||
*
|
*
|
||||||
* * An AsyncHandle handle is always active and cannot be deactivated,
|
* * An AsyncHandle handle is always active and cannot be deactivated,
|
||||||
* except by closing it with uv_close().
|
* except by closing it with uv_close().
|
||||||
* * A PipeHandle, TcpHandle, UDPHandle, etc. handle - basically any handle
|
* * A PipeHandle, TCPHandle, UDPHandle, etc. handle - basically any handle
|
||||||
* that deals with I/O - is active when it is doing something that involves
|
* that deals with I/O - is active when it is doing something that involves
|
||||||
* I/O, like reading, writing, connecting, accepting new connections, etc.
|
* I/O, like reading, writing, connecting, accepting new connections, etc.
|
||||||
* * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it
|
* * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it
|
||||||
@ -230,7 +230,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void configure(Configure flag, Args&&... args) {
|
void configure(Configure flag, Args&&... args) {
|
||||||
auto option = static_cast<std::underlying_type_t<Configure>>(flag);
|
auto option = static_cast<typename std::underlying_type<Configure>::type>(flag);
|
||||||
auto err = uv_loop_configure(loop.get(), static_cast<uv_loop_option>(option), std::forward<Args>(args)...);
|
auto err = uv_loop_configure(loop.get(), static_cast<uv_loop_option>(option), std::forward<Args>(args)...);
|
||||||
if(err) { publish(ErrorEvent{err}); }
|
if(err) { publish(ErrorEvent{err}); }
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ 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>>
|
typename std::enable_if<std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>::type
|
||||||
resource(Args&&... args) {
|
resource(Args&&... args) {
|
||||||
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;
|
||||||
@ -264,7 +264,7 @@ 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<not std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>
|
typename std::enable_if<not std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>::type
|
||||||
resource(Args&&... args) {
|
resource(Args&&... args) {
|
||||||
return R::create(shared_from_this(), std::forward<Args>(args)...);
|
return R::create(shared_from_this(), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<Mode mode = Mode::DEFAULT>
|
template<Mode mode = Mode::DEFAULT>
|
||||||
bool run() noexcept {
|
bool run() noexcept {
|
||||||
auto utm = static_cast<std::underlying_type_t<Mode>>(mode);
|
auto utm = static_cast<typename std::underlying_type<Mode>::type>(mode);
|
||||||
auto uvrm = static_cast<uv_run_mode>(utm);
|
auto uvrm = static_cast<uv_run_mode>(utm);
|
||||||
return (uv_run(loop.get(), uvrm) == 0);
|
return (uv_run(loop.get(), uvrm) == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVChmodFlags: std::underlying_type_t<uv_poll_event> {
|
enum class UVChmodFlags: typename std::underlying_type<uv_poll_event>::type {
|
||||||
READABLE = UV_READABLE,
|
READABLE = UV_READABLE,
|
||||||
WRITABLE = UV_WRITABLE
|
WRITABLE = UV_WRITABLE
|
||||||
};
|
};
|
||||||
@ -90,13 +90,17 @@ public:
|
|||||||
* @param name A valid domain socket or named pipe.
|
* @param name A valid domain socket or named pipe.
|
||||||
*/
|
*/
|
||||||
void connect(std::string name) {
|
void connect(std::string name) {
|
||||||
auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
|
auto ptr = shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::ConnectReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto connectEventListener = [ptr](const ConnectEvent &event, const details::ConnectReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto connect = loop().resource<details::ConnectReq>();
|
auto connect = loop().resource<details::ConnectReq>();
|
||||||
connect->once<ErrorEvent>(listener);
|
connect->once<ErrorEvent>(errorEventListener);
|
||||||
connect->once<ConnectEvent>(listener);
|
connect->once<ConnectEvent>(connectEventListener);
|
||||||
connect->connect(&uv_pipe_connect, get(), name.data());
|
connect->connect(&uv_pipe_connect, get(), name.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVPollEvent: std::underlying_type_t<uv_poll_event> {
|
enum class UVPollEvent: typename std::underlying_type<uv_poll_event>::type {
|
||||||
READABLE = UV_READABLE,
|
READABLE = UV_READABLE,
|
||||||
WRITABLE = UV_WRITABLE,
|
WRITABLE = UV_WRITABLE,
|
||||||
DISCONNECT = UV_DISCONNECT,
|
DISCONNECT = UV_DISCONNECT,
|
||||||
@ -70,7 +70,7 @@ class PollHandle final: public Handle<PollHandle, uv_poll_t> {
|
|||||||
static void startCallback(uv_poll_t *handle, int status, int events) {
|
static void startCallback(uv_poll_t *handle, int status, int events) {
|
||||||
PollHandle &poll = *(static_cast<PollHandle*>(handle->data));
|
PollHandle &poll = *(static_cast<PollHandle*>(handle->data));
|
||||||
if(status) { poll.publish(ErrorEvent{status}); }
|
if(status) { poll.publish(ErrorEvent{status}); }
|
||||||
else { poll.publish(PollEvent{static_cast<std::underlying_type_t<Event>>(events)}); }
|
else { poll.publish(PollEvent{static_cast<typename std::underlying_type<Event>::type>(events)}); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -19,7 +19,7 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVProcessFlags: std::underlying_type_t<uv_process_flags> {
|
enum class UVProcessFlags: typename std::underlying_type<uv_process_flags>::type {
|
||||||
SETUID = UV_PROCESS_SETUID,
|
SETUID = UV_PROCESS_SETUID,
|
||||||
SETGID = UV_PROCESS_SETGID,
|
SETGID = UV_PROCESS_SETGID,
|
||||||
WINDOWS_VERBATIM_ARGUMENTS = UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
|
WINDOWS_VERBATIM_ARGUMENTS = UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
|
||||||
@ -28,7 +28,7 @@ enum class UVProcessFlags: std::underlying_type_t<uv_process_flags> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum class UVStdIOFlags: std::underlying_type_t<uv_stdio_flags> {
|
enum class UVStdIOFlags: typename std::underlying_type<uv_stdio_flags>::type {
|
||||||
IGNORE_STREAM = UV_IGNORE,
|
IGNORE_STREAM = UV_IGNORE,
|
||||||
CREATE_PIPE = UV_CREATE_PIPE,
|
CREATE_PIPE = UV_CREATE_PIPE,
|
||||||
INHERIT_FD = UV_INHERIT_FD,
|
INHERIT_FD = UV_INHERIT_FD,
|
||||||
@ -144,13 +144,13 @@ public:
|
|||||||
poStdio.reserve(poFdStdio.size() + poStreamStdio.size());
|
poStdio.reserve(poFdStdio.size() + poStreamStdio.size());
|
||||||
poStdio.insert(poStdio.begin(), poFdStdio.cbegin(), poFdStdio.cend());
|
poStdio.insert(poStdio.begin(), poFdStdio.cbegin(), poFdStdio.cend());
|
||||||
poStdio.insert(poStdio.end(), poStreamStdio.cbegin(), poStreamStdio.cend());
|
poStdio.insert(poStdio.end(), poStreamStdio.cbegin(), poStreamStdio.cend());
|
||||||
|
|
||||||
po.stdio_count = static_cast<decltype(po.stdio_count)>(poStdio.size());
|
po.stdio_count = static_cast<decltype(po.stdio_count)>(poStdio.size());
|
||||||
po.stdio = poStdio.data();
|
po.stdio = poStdio.data();
|
||||||
|
|
||||||
// fake initialization so as to have leak invoked
|
// fake initialization so as to have leak invoked
|
||||||
// see init member function for more details
|
// see init member function for more details
|
||||||
initialize([](auto...){ return 0; });
|
initialize([](uv_loop_t*, uv_process_t*){ return 0; });
|
||||||
|
|
||||||
invoke(&uv_spawn, parent(), get(), &po);
|
invoke(&uv_spawn, parent(), get(), &po);
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ public:
|
|||||||
|
|
||||||
auto actual = FileHandle::Type{fd};
|
auto actual = FileHandle::Type{fd};
|
||||||
|
|
||||||
auto it = std::find_if(poFdStdio.begin(), poFdStdio.end(), [actual](auto &&container){
|
auto it = std::find_if(poFdStdio.begin(), poFdStdio.end(), [actual](const uv_stdio_container_t &container){
|
||||||
return container.data.fd == actual;
|
return container.data.fd == actual;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ namespace uvw {
|
|||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
class Request: public Resource<T, U> {
|
class Request: public Resource<T, U> {
|
||||||
protected:
|
protected:
|
||||||
static auto reserve(U *req) {
|
static auto reserve(U *req) -> std::shared_ptr<T> {
|
||||||
auto ptr = static_cast<T*>(req->data)->shared_from_this();
|
auto ptr = static_cast<T*>(req->data)->shared_from_this();
|
||||||
ptr->reset();
|
ptr->reset();
|
||||||
return ptr;
|
return ptr;
|
||||||
@ -29,7 +29,7 @@ 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> {
|
-> typename std::enable_if<not std::is_void<typename std::result_of<F(Args...)>::type>::value>::type {
|
||||||
auto err = std::forward<F>(f)(std::forward<Args>(args)...);
|
auto err = std::forward<F>(f)(std::forward<Args>(args)...);
|
||||||
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
|
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
|
||||||
else { this->leak(); }
|
else { this->leak(); }
|
||||||
@ -37,7 +37,7 @@ 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<std::is_void<std::result_of_t<F(Args...)>>::value> {
|
-> typename std::enable_if<std::is_void<typename std::result_of<F(Args...)>::type>::value>::type {
|
||||||
std::forward<F>(f)(std::forward<Args>(args)...);
|
std::forward<F>(f)(std::forward<Args>(args)...);
|
||||||
this->leak();
|
this->leak();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class Resource: public UnderlyingType<T, U>, public Emitter<T>, public std::enab
|
|||||||
protected:
|
protected:
|
||||||
using ConstructorAccess = typename UnderlyingType<T, U>::ConstructorAccess;
|
using ConstructorAccess = typename UnderlyingType<T, U>::ConstructorAccess;
|
||||||
|
|
||||||
auto parent() const noexcept {
|
auto parent() const noexcept -> uv_loop_t * {
|
||||||
return this->loop().loop.get();
|
return this->loop().loop.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public:
|
|||||||
WriteReq(ConstructorAccess ca, std::shared_ptr<Loop> loop, std::unique_ptr<char[], Deleter> dt, unsigned int len)
|
WriteReq(ConstructorAccess ca, std::shared_ptr<Loop> loop, std::unique_ptr<char[], Deleter> dt, unsigned int len)
|
||||||
: Request<WriteReq, uv_write_t>{ca, std::move(loop)},
|
: Request<WriteReq, uv_write_t>{ca, std::move(loop)},
|
||||||
data{std::move(dt)},
|
data{std::move(dt)},
|
||||||
buf{uv_buf_init(data.get(), len)}
|
buf(uv_buf_init(data.get(), len))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void write(uv_stream_t *handle) {
|
void write(uv_stream_t *handle) {
|
||||||
@ -124,7 +124,7 @@ private:
|
|||||||
*
|
*
|
||||||
* Stream handles provide an abstraction of a duplex communication channel.
|
* Stream handles provide an abstraction of a duplex communication channel.
|
||||||
* StreamHandle is an intermediate type, `uvw` provides three stream
|
* StreamHandle is an intermediate type, `uvw` provides three stream
|
||||||
* implementations: TcpHandle, PipeHandle and TTYHandle.
|
* implementations: TCPHandle, PipeHandle and TTYHandle.
|
||||||
*/
|
*/
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
class StreamHandle: public Handle<T, U> {
|
class StreamHandle: public Handle<T, U> {
|
||||||
@ -174,13 +174,17 @@ public:
|
|||||||
* A ShutdownEvent event will be emitted after shutdown is complete.
|
* A ShutdownEvent event will be emitted after shutdown is complete.
|
||||||
*/
|
*/
|
||||||
void shutdown() {
|
void shutdown() {
|
||||||
auto listener = [ptr = this->shared_from_this()](const auto &event, const auto &) {
|
auto ptr = this->shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::ShutdownReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto shutdownEventListener = [ptr](const ShutdownEvent &event, const details::ShutdownReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto shutdown = this->loop().template resource<details::ShutdownReq>();
|
auto shutdown = this->loop().template resource<details::ShutdownReq>();
|
||||||
shutdown->template once<ErrorEvent>(listener);
|
shutdown->template once<ErrorEvent>(errorEventListener);
|
||||||
shutdown->template once<ShutdownEvent>(listener);
|
shutdown->template once<ShutdownEvent>(shutdownEventListener);
|
||||||
shutdown->shutdown(this->template get<uv_stream_t>());
|
shutdown->shutdown(this->template get<uv_stream_t>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,12 +264,16 @@ public:
|
|||||||
data.release(), [](char *ptr) { delete[] ptr; }
|
data.release(), [](char *ptr) { delete[] ptr; }
|
||||||
}, len);
|
}, len);
|
||||||
|
|
||||||
auto listener = [ptr = this->shared_from_this()](const auto &event, const auto &) {
|
auto ptr = this->shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::WriteReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto writeEventListener = [ptr](const WriteEvent &event, const details::WriteReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
req->template once<ErrorEvent>(listener);
|
req->template once<ErrorEvent>(errorEventListener);
|
||||||
req->template once<WriteEvent>(listener);
|
req->template once<WriteEvent>(writeEventListener);
|
||||||
req->write(this->template get<uv_stream_t>());
|
req->write(this->template get<uv_stream_t>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,12 +295,17 @@ public:
|
|||||||
data, [](char *) {}
|
data, [](char *) {}
|
||||||
}, len);
|
}, len);
|
||||||
|
|
||||||
auto listener = [ptr = this->shared_from_this()](const auto &event, const auto &) {
|
auto ptr = this->shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::WriteReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto writeEventListener = [ptr](const WriteEvent &event, const details::WriteReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
req->template once<ErrorEvent>(listener);
|
|
||||||
req->template once<WriteEvent>(listener);
|
req->template once<ErrorEvent>(errorEventListener);
|
||||||
|
req->template once<WriteEvent>(writeEventListener);
|
||||||
req->write(this->template get<uv_stream_t>());
|
req->write(this->template get<uv_stream_t>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +314,7 @@ public:
|
|||||||
*
|
*
|
||||||
* The pipe must be initialized with `ipc == true`.
|
* The pipe must be initialized with `ipc == true`.
|
||||||
*
|
*
|
||||||
* `send` must be a TcpHandle or PipeHandle handle, which is a server or a
|
* `send` must be a TCPHandle or PipeHandle handle, which is a server or a
|
||||||
* connection (listening or connected state). Bound sockets or pipes will be
|
* connection (listening or connected state). Bound sockets or pipes will be
|
||||||
* assumed to be servers.
|
* assumed to be servers.
|
||||||
*
|
*
|
||||||
@ -322,12 +335,16 @@ public:
|
|||||||
data.release(), [](char *ptr) { delete[] ptr; }
|
data.release(), [](char *ptr) { delete[] ptr; }
|
||||||
}, len);
|
}, len);
|
||||||
|
|
||||||
auto listener = [ptr = this->shared_from_this()](const auto &event, const auto &) {
|
auto ptr = this->shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::WriteReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto writeEventListener = [ptr](const WriteEvent &event, const details::WriteReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
req->template once<ErrorEvent>(listener);
|
req->template once<ErrorEvent>(errorEventListener);
|
||||||
req->template once<WriteEvent>(listener);
|
req->template once<WriteEvent>(writeEventListener);
|
||||||
req->write(this->template get<uv_stream_t>(), send.template get<uv_stream_t>());
|
req->write(this->template get<uv_stream_t>(), send.template get<uv_stream_t>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +353,7 @@ public:
|
|||||||
*
|
*
|
||||||
* The pipe must be initialized with `ipc == true`.
|
* The pipe must be initialized with `ipc == true`.
|
||||||
*
|
*
|
||||||
* `send` must be a TcpHandle or PipeHandle handle, which is a server or a
|
* `send` must be a TCPHandle or PipeHandle handle, which is a server or a
|
||||||
* connection (listening or connected state). Bound sockets or pipes will be
|
* connection (listening or connected state). Bound sockets or pipes will be
|
||||||
* assumed to be servers.
|
* assumed to be servers.
|
||||||
*
|
*
|
||||||
@ -357,12 +374,16 @@ public:
|
|||||||
data, [](char *) {}
|
data, [](char *) {}
|
||||||
}, len);
|
}, len);
|
||||||
|
|
||||||
auto listener = [ptr = this->shared_from_this()](const auto &event, const auto &) {
|
auto ptr = this->shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::WriteReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto writeEventListener = [ptr](const WriteEvent &event, const details::WriteReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
req->template once<ErrorEvent>(listener);
|
req->template once<ErrorEvent>(errorEventListener);
|
||||||
req->template once<WriteEvent>(listener);
|
req->template once<WriteEvent>(writeEventListener);
|
||||||
req->write(this->template get<uv_stream_t>(), send.template get<uv_stream_t>());
|
req->write(this->template get<uv_stream_t>(), send.template get<uv_stream_t>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace uvw {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVTcpFlags: std::underlying_type_t<uv_tcp_flags> {
|
enum class UVTCPFlags: typename std::underlying_type<uv_tcp_flags>::type {
|
||||||
IPV6ONLY = UV_TCP_IPV6ONLY
|
IPV6ONLY = UV_TCP_IPV6ONLY
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,13 +27,13 @@ enum class UVTcpFlags: std::underlying_type_t<uv_tcp_flags> {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The TcpHandle handle.
|
* @brief The TCPHandle handle.
|
||||||
*
|
*
|
||||||
* TCP handles are used to represent both TCP streams and servers.<br/>
|
* TCP handles are used to represent both TCP streams and servers.<br/>
|
||||||
* By default, _IPv4_ is used as a template parameter. The handle already
|
* By default, _IPv4_ is used as a template parameter. The handle already
|
||||||
* supports _IPv6_ out-of-the-box by using `uvw::IPv6`.
|
* supports _IPv6_ out-of-the-box by using `uvw::IPv6`.
|
||||||
*
|
*
|
||||||
* To create a `TcpHandle` through a `Loop`, arguments follow:
|
* To create a `TCPHandle` through a `Loop`, arguments follow:
|
||||||
*
|
*
|
||||||
* * An optional integer value that indicates the flags used to initialize
|
* * An optional integer value that indicates the flags used to initialize
|
||||||
* the socket.
|
* the socket.
|
||||||
@ -42,14 +42,14 @@ enum class UVTcpFlags: std::underlying_type_t<uv_tcp_flags> {
|
|||||||
* [documentation](http://docs.libuv.org/en/v1.x/tcp.html#c.uv_tcp_init_ex)
|
* [documentation](http://docs.libuv.org/en/v1.x/tcp.html#c.uv_tcp_init_ex)
|
||||||
* for further details.
|
* for further details.
|
||||||
*/
|
*/
|
||||||
class TcpHandle final: public StreamHandle<TcpHandle, uv_tcp_t> {
|
class TCPHandle final: public StreamHandle<TCPHandle, uv_tcp_t> {
|
||||||
public:
|
public:
|
||||||
using Time = std::chrono::duration<unsigned int>;
|
using Time = std::chrono::duration<unsigned int>;
|
||||||
using Bind = details::UVTcpFlags;
|
using Bind = details::UVTCPFlags;
|
||||||
using IPv4 = uvw::IPv4;
|
using IPv4 = uvw::IPv4;
|
||||||
using IPv6 = uvw::IPv6;
|
using IPv6 = uvw::IPv6;
|
||||||
|
|
||||||
explicit TcpHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, unsigned int f = {})
|
explicit TCPHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, unsigned int f = {})
|
||||||
: StreamHandle{ca, std::move(ref)}, tag{f ? FLAGS : DEFAULT}, flags{f}
|
: StreamHandle{ca, std::move(ref)}, tag{f ? FLAGS : DEFAULT}, flags{f}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Available flags are:
|
* Available flags are:
|
||||||
*
|
*
|
||||||
* * `TcpHandle::Bind::IPV6ONLY`: it disables dual-stack support and only
|
* * `TCPHandle::Bind::IPV6ONLY`: it disables dual-stack support and only
|
||||||
* IPv6 is used.
|
* IPv6 is used.
|
||||||
*
|
*
|
||||||
* @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
|
* @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
|
||||||
@ -143,7 +143,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Available flags are:
|
* Available flags are:
|
||||||
*
|
*
|
||||||
* * `TcpHandle::Bind::IPV6ONLY`: it disables dual-stack support and only
|
* * `TCPHandle::Bind::IPV6ONLY`: it disables dual-stack support and only
|
||||||
* IPv6 is used.
|
* IPv6 is used.
|
||||||
*
|
*
|
||||||
* @param ip The address to which to bind.
|
* @param ip The address to which to bind.
|
||||||
@ -167,7 +167,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Available flags are:
|
* Available flags are:
|
||||||
*
|
*
|
||||||
* * `TcpHandle::Bind::IPV6ONLY`: it disables dual-stack support and only
|
* * `TCPHandle::Bind::IPV6ONLY`: it disables dual-stack support and only
|
||||||
* IPv6 is used.
|
* IPv6 is used.
|
||||||
*
|
*
|
||||||
* @param addr A valid instance of Addr.
|
* @param addr A valid instance of Addr.
|
||||||
@ -210,13 +210,18 @@ public:
|
|||||||
* @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
|
* @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
|
||||||
*/
|
*/
|
||||||
void connect(const sockaddr &addr) {
|
void connect(const sockaddr &addr) {
|
||||||
auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
|
auto ptr = shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::ConnectReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto connectEventListener = [ptr](const ConnectEvent &event, const details::ConnectReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
auto req = loop().resource<details::ConnectReq>();
|
auto req = loop().resource<details::ConnectReq>();
|
||||||
req->once<ErrorEvent>(listener);
|
req->once<ErrorEvent>(errorEventListener);
|
||||||
req->once<ConnectEvent>(listener);
|
req->once<ConnectEvent>(connectEventListener);
|
||||||
req->connect(&uv_tcp_connect, get(), &addr);
|
req->connect(&uv_tcp_connect, get(), &addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ struct ResetModeMemo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum class UVTTYModeT: std::underlying_type_t<uv_tty_mode_t> {
|
enum class UVTTYModeT: typename std::underlying_type<uv_tty_mode_t>::type {
|
||||||
NORMAL = UV_TTY_MODE_NORMAL,
|
NORMAL = UV_TTY_MODE_NORMAL,
|
||||||
RAW = UV_TTY_MODE_RAW,
|
RAW = UV_TTY_MODE_RAW,
|
||||||
IO = UV_TTY_MODE_IO
|
IO = UV_TTY_MODE_IO
|
||||||
@ -50,7 +50,7 @@ enum class UVTTYModeT: std::underlying_type_t<uv_tty_mode_t> {
|
|||||||
* for further details.
|
* for further details.
|
||||||
*/
|
*/
|
||||||
class TTYHandle final: public StreamHandle<TTYHandle, uv_tty_t> {
|
class TTYHandle final: public StreamHandle<TTYHandle, uv_tty_t> {
|
||||||
static auto resetModeMemo() {
|
static auto resetModeMemo() -> std::shared_ptr<details::ResetModeMemo> {
|
||||||
static std::weak_ptr<details::ResetModeMemo> weak;
|
static std::weak_ptr<details::ResetModeMemo> weak;
|
||||||
auto shared = weak.lock();
|
auto shared = weak.lock();
|
||||||
if(!shared) { weak = shared = std::make_shared<details::ResetModeMemo>(); }
|
if(!shared) { weak = shared = std::make_shared<details::ResetModeMemo>(); }
|
||||||
@ -92,7 +92,7 @@ public:
|
|||||||
* @return True in case of success, false otherwise.
|
* @return True in case of success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool mode(Mode m) {
|
bool mode(Mode m) {
|
||||||
return (0 == uv_tty_set_mode(get(), static_cast<std::underlying_type_t<Mode>>(m)));
|
return (0 == uv_tty_set_mode(get(), static_cast<typename std::underlying_type<Mode>::type>(m)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -32,7 +32,7 @@ struct SendEvent {};
|
|||||||
*/
|
*/
|
||||||
struct UDPDataEvent {
|
struct UDPDataEvent {
|
||||||
explicit UDPDataEvent(Addr sndr, std::unique_ptr<const char[]> buf, std::size_t len, bool part) noexcept
|
explicit UDPDataEvent(Addr sndr, std::unique_ptr<const char[]> buf, std::size_t len, bool part) noexcept
|
||||||
: data{std::move(buf)}, length{len}, sender{std::move(sndr)}, partial{part}
|
: data{std::move(buf)}, length{len}, sender(std::move(sndr)), partial{part}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::unique_ptr<const char[]> data; /*!< A bunch of data read on the stream. */
|
std::unique_ptr<const char[]> data; /*!< A bunch of data read on the stream. */
|
||||||
@ -45,13 +45,13 @@ struct UDPDataEvent {
|
|||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVUdpFlags: std::underlying_type_t<uv_udp_flags> {
|
enum class UVUDPFlags: typename std::underlying_type<uv_udp_flags>::type {
|
||||||
IPV6ONLY = UV_UDP_IPV6ONLY,
|
IPV6ONLY = UV_UDP_IPV6ONLY,
|
||||||
REUSEADDR = UV_UDP_REUSEADDR
|
REUSEADDR = UV_UDP_REUSEADDR
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum class UVMembership: std::underlying_type_t<uv_membership> {
|
enum class UVMembership: typename std::underlying_type<uv_membership>::type {
|
||||||
LEAVE_GROUP = UV_LEAVE_GROUP,
|
LEAVE_GROUP = UV_LEAVE_GROUP,
|
||||||
JOIN_GROUP = UV_JOIN_GROUP
|
JOIN_GROUP = UV_JOIN_GROUP
|
||||||
};
|
};
|
||||||
@ -64,7 +64,7 @@ public:
|
|||||||
SendReq(ConstructorAccess ca, std::shared_ptr<Loop> loop, std::unique_ptr<char[], Deleter> dt, unsigned int len)
|
SendReq(ConstructorAccess ca, std::shared_ptr<Loop> loop, std::unique_ptr<char[], Deleter> dt, unsigned int len)
|
||||||
: Request<SendReq, uv_udp_send_t>{ca, std::move(loop)},
|
: Request<SendReq, uv_udp_send_t>{ca, std::move(loop)},
|
||||||
data{std::move(dt)},
|
data{std::move(dt)},
|
||||||
buf{uv_buf_init(data.get(), len)}
|
buf(uv_buf_init(data.get(), len))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void send(uv_udp_t *handle, const struct sockaddr* addr) {
|
void send(uv_udp_t *handle, const struct sockaddr* addr) {
|
||||||
@ -121,7 +121,7 @@ class UDPHandle final: public Handle<UDPHandle, uv_udp_t> {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using Membership = details::UVMembership;
|
using Membership = details::UVMembership;
|
||||||
using Bind = details::UVUdpFlags;
|
using Bind = details::UVUDPFlags;
|
||||||
using IPv4 = uvw::IPv4;
|
using IPv4 = uvw::IPv4;
|
||||||
using IPv6 = uvw::IPv6;
|
using IPv6 = uvw::IPv6;
|
||||||
|
|
||||||
@ -318,12 +318,16 @@ public:
|
|||||||
data.release(), [](char *ptr) { delete[] ptr; }
|
data.release(), [](char *ptr) { delete[] ptr; }
|
||||||
}, len);
|
}, len);
|
||||||
|
|
||||||
auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
|
auto ptr = shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::SendReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto sendEventListener = [ptr](const SendEvent &event, const details::SendReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
req->once<ErrorEvent>(listener);
|
req->once<ErrorEvent>(errorEventListener);
|
||||||
req->once<SendEvent>(listener);
|
req->once<SendEvent>(sendEventListener);
|
||||||
req->send(get(), &addr);
|
req->send(get(), &addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,12 +401,16 @@ public:
|
|||||||
data, [](char *) {}
|
data, [](char *) {}
|
||||||
}, len);
|
}, len);
|
||||||
|
|
||||||
auto listener = [ptr = shared_from_this()](const auto &event, const auto &) {
|
auto ptr = shared_from_this();
|
||||||
|
auto errorEventListener = [ptr](const ErrorEvent &event, const details::SendReq &) {
|
||||||
|
ptr->publish(event);
|
||||||
|
};
|
||||||
|
auto sendEventListener = [ptr](const SendEvent &event, const details::SendReq &) {
|
||||||
ptr->publish(event);
|
ptr->publish(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
req->once<ErrorEvent>(listener);
|
req->once<ErrorEvent>(errorEventListener);
|
||||||
req->once<SendEvent>(listener);
|
req->once<SendEvent>(sendEventListener);
|
||||||
req->send(get(), &addr);
|
req->send(get(), &addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,39 +23,39 @@ class UnderlyingType {
|
|||||||
protected:
|
protected:
|
||||||
struct ConstructorAccess { explicit ConstructorAccess(int) {} };
|
struct ConstructorAccess { explicit ConstructorAccess(int) {} };
|
||||||
|
|
||||||
auto get() noexcept {
|
auto get() noexcept -> U * {
|
||||||
return &resource;
|
return &resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get() const noexcept {
|
auto get() const noexcept -> const U * {
|
||||||
return &resource;
|
return &resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
auto get() noexcept {
|
auto get() noexcept -> R * {
|
||||||
static_assert(not std::is_same<R, U>::value, "!");
|
static_assert(not std::is_same<R, U>::value, "!");
|
||||||
return reinterpret_cast<R *>(&resource);
|
return reinterpret_cast<R *>(&resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename... P>
|
template<typename R, typename... P>
|
||||||
auto get(UnderlyingType<P...> &other) noexcept {
|
auto get(UnderlyingType<P...> &other) noexcept -> R * {
|
||||||
return reinterpret_cast<R *>(&other.resource);
|
return reinterpret_cast<R *>(&other.resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R>
|
template<typename R>
|
||||||
auto get() const noexcept {
|
auto get() const noexcept -> const R * {
|
||||||
static_assert(not std::is_same<R, U>::value, "!");
|
static_assert(not std::is_same<R, U>::value, "!");
|
||||||
return reinterpret_cast<const R *>(&resource);
|
return reinterpret_cast<const R *>(&resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename R, typename... P>
|
template<typename R, typename... P>
|
||||||
auto get(const UnderlyingType<P...> &other) const noexcept {
|
auto get(const UnderlyingType<P...> &other) const noexcept -> const R * {
|
||||||
return reinterpret_cast<const R *>(&other.resource);
|
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()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
UnderlyingType(const UnderlyingType &) = delete;
|
UnderlyingType(const UnderlyingType &) = delete;
|
||||||
|
|||||||
@ -13,21 +13,13 @@
|
|||||||
#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 {
|
||||||
|
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
|
||||||
enum class UVHandleType: std::underlying_type_t<uv_handle_type> {
|
enum class UVHandleType: typename std::underlying_type<uv_handle_type>::type {
|
||||||
UNKNOWN = UV_UNKNOWN_HANDLE,
|
UNKNOWN = UV_UNKNOWN_HANDLE,
|
||||||
ASYNC = UV_ASYNC,
|
ASYNC = UV_ASYNC,
|
||||||
CHECK = UV_CHECK,
|
CHECK = UV_CHECK,
|
||||||
@ -88,7 +80,7 @@ bool operator==(UVTypeWrapper<T> lhs, UVTypeWrapper<T> rhs) {
|
|||||||
*/
|
*/
|
||||||
template<typename E>
|
template<typename E>
|
||||||
class Flags final {
|
class Flags final {
|
||||||
using InnerType = std::underlying_type_t<E>;
|
using InnerType = typename std::underlying_type<E>::type;
|
||||||
|
|
||||||
constexpr InnerType toInnerType(E flag) const noexcept { return static_cast<InnerType>(flag); }
|
constexpr InnerType toInnerType(E flag) const noexcept { return static_cast<InnerType>(flag); }
|
||||||
|
|
||||||
@ -100,7 +92,7 @@ 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 Flags<E> from() {
|
||||||
auto flags = Flags<E>{};
|
auto flags = Flags<E>{};
|
||||||
int _[] = { 0, (flags = flags | V, 0)... };
|
int _[] = { 0, (flags = flags | V, 0)... };
|
||||||
return void(_), flags;
|
return void(_), flags;
|
||||||
@ -129,12 +121,12 @@ public:
|
|||||||
|
|
||||||
~Flags() noexcept { static_assert(std::is_enum<E>::value, "!"); }
|
~Flags() noexcept { static_assert(std::is_enum<E>::value, "!"); }
|
||||||
|
|
||||||
CONSTEXPR_SPECIFIER Flags & operator=(const Flags &f) noexcept {
|
Flags & operator=(const Flags &f) noexcept {
|
||||||
flags = f.flags;
|
flags = f.flags;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSTEXPR_SPECIFIER Flags & operator=(Flags &&f) noexcept {
|
Flags & operator=(Flags &&f) noexcept {
|
||||||
flags = std::move(f.flags);
|
flags = std::move(f.flags);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -237,7 +229,7 @@ struct Passwd {
|
|||||||
* @brief Gets the uid.
|
* @brief Gets the uid.
|
||||||
* @return The current effective uid (not the real uid).
|
* @return The current effective uid (not the real uid).
|
||||||
*/
|
*/
|
||||||
auto uid() const noexcept {
|
auto uid() const noexcept -> decltype(uv_passwd_t::uid) {
|
||||||
return (passwd ? passwd->uid : decltype(uv_passwd_t::uid){});
|
return (passwd ? passwd->uid : decltype(uv_passwd_t::uid){});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +237,7 @@ struct Passwd {
|
|||||||
* @brief Gets the gid.
|
* @brief Gets the gid.
|
||||||
* @return The gid of the current effective uid (not the real uid).
|
* @return The gid of the current effective uid (not the real uid).
|
||||||
*/
|
*/
|
||||||
auto gid() const noexcept {
|
auto gid() const noexcept -> decltype(uv_passwd_t::gid) {
|
||||||
return (passwd ? passwd->gid : decltype(uv_passwd_t::gid){});
|
return (passwd ? passwd->gid : decltype(uv_passwd_t::gid){});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +343,7 @@ struct IpTraits<IPv4> {
|
|||||||
using NameFuncType = int(*)(const Type *, char *, std::size_t);
|
using NameFuncType = int(*)(const Type *, char *, std::size_t);
|
||||||
static constexpr AddrFuncType addrFunc = &uv_ip4_addr;
|
static constexpr AddrFuncType addrFunc = &uv_ip4_addr;
|
||||||
static constexpr NameFuncType nameFunc = &uv_ip4_name;
|
static constexpr NameFuncType nameFunc = &uv_ip4_name;
|
||||||
static constexpr auto sinPort(const Type *addr) { return addr->sin_port; }
|
static constexpr auto sinPort(const Type *addr) -> decltype(addr->sin_port){ return addr->sin_port; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -362,7 +354,7 @@ struct IpTraits<IPv6> {
|
|||||||
using NameFuncType = int(*)(const Type *, char *, std::size_t);
|
using NameFuncType = int(*)(const Type *, char *, std::size_t);
|
||||||
static constexpr AddrFuncType addrFunc = &uv_ip6_addr;
|
static constexpr AddrFuncType addrFunc = &uv_ip6_addr;
|
||||||
static constexpr NameFuncType nameFunc = &uv_ip6_name;
|
static constexpr NameFuncType nameFunc = &uv_ip6_name;
|
||||||
static constexpr auto sinPort(const Type *addr) { return addr->sin6_port; }
|
static constexpr auto sinPort(const Type *addr) -> decltype(addr->sin6_port) { return addr->sin6_port; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -386,7 +378,7 @@ template<typename I, typename F, typename H>
|
|||||||
Addr address(F &&f, const H *handle) noexcept {
|
Addr address(F &&f, const H *handle) noexcept {
|
||||||
sockaddr_storage ssto;
|
sockaddr_storage ssto;
|
||||||
int len = sizeof(ssto);
|
int len = sizeof(ssto);
|
||||||
Addr addr{};
|
Addr addr;
|
||||||
|
|
||||||
int err = std::forward<F>(f)(handle, reinterpret_cast<sockaddr *>(&ssto), &len);
|
int err = std::forward<F>(f)(handle, reinterpret_cast<sockaddr *>(&ssto), &len);
|
||||||
|
|
||||||
@ -671,7 +663,7 @@ struct Utilities {
|
|||||||
int count;
|
int count;
|
||||||
|
|
||||||
if(0 == uv_cpu_info(&infos, &count)) {
|
if(0 == uv_cpu_info(&infos, &count)) {
|
||||||
std::for_each(infos, infos+count, [&cpuinfos](const auto &info) {
|
std::for_each(infos, infos+count, [&cpuinfos](const uv_cpu_info_t &info) {
|
||||||
cpuinfos.push_back({ info.model, info.speed, info.cpu_times });
|
cpuinfos.push_back({ info.model, info.speed, info.cpu_times });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -696,7 +688,7 @@ struct Utilities {
|
|||||||
int count{0};
|
int count{0};
|
||||||
|
|
||||||
if(0 == uv_interface_addresses(&ifaces, &count)) {
|
if(0 == uv_interface_addresses(&ifaces, &count)) {
|
||||||
std::for_each(ifaces, ifaces+count, [&interfaces](const auto &iface) {
|
std::for_each(ifaces, ifaces+count, [&interfaces](const uv_interface_address_t &iface) {
|
||||||
InterfaceAddress interfaceAddress;
|
InterfaceAddress interfaceAddress;
|
||||||
|
|
||||||
interfaceAddress.name = iface.name;
|
interfaceAddress.name = iface.name;
|
||||||
@ -853,7 +845,7 @@ struct Utilities {
|
|||||||
static RUsage rusage() noexcept {
|
static RUsage rusage() noexcept {
|
||||||
RUsage ru;
|
RUsage ru;
|
||||||
auto err = uv_getrusage(&ru);
|
auto err = uv_getrusage(&ru);
|
||||||
return err ? RUsage{} : ru;
|
return err ? RUsage() : ru;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -6,22 +6,23 @@
|
|||||||
|
|
||||||
|
|
||||||
void listen(uvw::Loop &loop) {
|
void listen(uvw::Loop &loop) {
|
||||||
std::shared_ptr<uvw::TcpHandle> tcp = loop.resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) {
|
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) {
|
||||||
std::cout << "error " << std::endl;
|
std::cout << "error " << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &srv) {
|
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
|
||||||
std::cout << "listen" << std::endl;
|
std::cout << "listen" << std::endl;
|
||||||
|
|
||||||
std::shared_ptr<uvw::TcpHandle> client = srv.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) {
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) {
|
||||||
std::cout << "error " << std::endl;
|
std::cout << "error " << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
client->on<uvw::CloseEvent>([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TcpHandle &) {
|
auto ptr = srv.shared_from_this();
|
||||||
|
client->on<uvw::CloseEvent>([ptr](const uvw::CloseEvent &, uvw::TCPHandle &) {
|
||||||
std::cout << "close" << std::endl;
|
std::cout << "close" << std::endl;
|
||||||
ptr->close();
|
ptr->close();
|
||||||
});
|
});
|
||||||
@ -34,12 +35,12 @@ void listen(uvw::Loop &loop) {
|
|||||||
uvw::Addr remote = client->peer();
|
uvw::Addr remote = client->peer();
|
||||||
std::cout << "remote: " << remote.ip << " " << remote.port << std::endl;
|
std::cout << "remote: " << remote.ip << " " << remote.port << std::endl;
|
||||||
|
|
||||||
client->on<uvw::DataEvent>([](const uvw::DataEvent &event, uvw::TcpHandle &) {
|
client->on<uvw::DataEvent>([](const uvw::DataEvent &event, uvw::TCPHandle &) {
|
||||||
std::cout.write(event.data.get(), event.length) << std::endl;
|
std::cout.write(event.data.get(), event.length) << std::endl;
|
||||||
std::cout << "data length: " << event.length << std::endl;
|
std::cout << "data length: " << event.length << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &handle) {
|
client->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &handle) {
|
||||||
std::cout << "end" << std::endl;
|
std::cout << "end" << std::endl;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
handle.loop().walk([&count](uvw::BaseHandle &) { ++count; });
|
handle.loop().walk([&count](uvw::BaseHandle &) { ++count; });
|
||||||
@ -50,7 +51,7 @@ void listen(uvw::Loop &loop) {
|
|||||||
client->read();
|
client->read();
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp->once<uvw::CloseEvent>([](const uvw::CloseEvent &, uvw::TcpHandle &) {
|
tcp->once<uvw::CloseEvent>([](const uvw::CloseEvent &, uvw::TCPHandle &) {
|
||||||
std::cout << "close" << std::endl;
|
std::cout << "close" << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -60,18 +61,18 @@ void listen(uvw::Loop &loop) {
|
|||||||
|
|
||||||
|
|
||||||
void conn(uvw::Loop &loop) {
|
void conn(uvw::Loop &loop) {
|
||||||
auto tcp = loop.resource<uvw::TcpHandle>();
|
auto tcp = loop.resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) {
|
tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) {
|
||||||
std::cout << "error " << std::endl;
|
std::cout << "error " << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp->once<uvw::WriteEvent>([](const uvw::WriteEvent &, uvw::TcpHandle &handle) {
|
tcp->once<uvw::WriteEvent>([](const uvw::WriteEvent &, uvw::TCPHandle &handle) {
|
||||||
std::cout << "write" << std::endl;
|
std::cout << "write" << std::endl;
|
||||||
handle.close();
|
handle.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) {
|
tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
|
||||||
std::cout << "connect" << std::endl;
|
std::cout << "connect" << std::endl;
|
||||||
|
|
||||||
auto dataTryWrite = std::unique_ptr<char[]>(new char[1]{ 'a' });
|
auto dataTryWrite = std::unique_ptr<char[]>(new char[1]{ 'a' });
|
||||||
@ -82,7 +83,7 @@ void conn(uvw::Loop &loop) {
|
|||||||
handle.write(std::move(dataWrite), 2);
|
handle.write(std::move(dataWrite), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp->once<uvw::CloseEvent>([](const uvw::CloseEvent &, uvw::TcpHandle &) {
|
tcp->once<uvw::CloseEvent>([](const uvw::CloseEvent &, uvw::TCPHandle &) {
|
||||||
std::cout << "close" << std::endl;
|
std::cout << "close" << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,9 @@ TEST(Async, Send) {
|
|||||||
|
|
||||||
bool checkAsyncEvent = false;
|
bool checkAsyncEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::AsyncHandle &) { FAIL(); });
|
||||||
|
|
||||||
handle->on<uvw::AsyncEvent>([&checkAsyncEvent](const auto &, auto &hndl) {
|
handle->on<uvw::AsyncEvent>([&checkAsyncEvent](const uvw::AsyncEvent &, uvw::AsyncHandle &hndl) {
|
||||||
ASSERT_FALSE(checkAsyncEvent);
|
ASSERT_FALSE(checkAsyncEvent);
|
||||||
checkAsyncEvent = true;
|
checkAsyncEvent = true;
|
||||||
hndl.close();
|
hndl.close();
|
||||||
@ -32,9 +32,8 @@ TEST(Async, Fake) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::AsyncHandle>();
|
auto handle = loop->resource<uvw::AsyncHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::AsyncHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::AsyncEvent>([](const uvw::AsyncEvent &, uvw::AsyncHandle &) { FAIL(); });
|
||||||
handle->on<uvw::AsyncEvent>(l);
|
|
||||||
|
|
||||||
handle->send();
|
handle->send();
|
||||||
handle->close();
|
handle->close();
|
||||||
|
|||||||
@ -8,9 +8,9 @@ TEST(Check, StartAndStop) {
|
|||||||
|
|
||||||
bool checkCheckEvent = false;
|
bool checkCheckEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::CheckHandle &) { FAIL(); });
|
||||||
|
|
||||||
handle->on<uvw::CheckEvent>([&checkCheckEvent](const auto &, auto &hndl) {
|
handle->on<uvw::CheckEvent>([&checkCheckEvent](const uvw::CheckEvent &, uvw::CheckHandle &hndl) {
|
||||||
ASSERT_FALSE(checkCheckEvent);
|
ASSERT_FALSE(checkCheckEvent);
|
||||||
checkCheckEvent = true;
|
checkCheckEvent = true;
|
||||||
hndl.stop();
|
hndl.stop();
|
||||||
@ -33,9 +33,8 @@ TEST(Check, Fake) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::CheckHandle>();
|
auto handle = loop->resource<uvw::CheckHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::CheckHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::CheckEvent>([](const uvw::CheckEvent &, uvw::CheckHandle &) { FAIL(); });
|
||||||
handle->on<uvw::CheckEvent>(l);
|
|
||||||
|
|
||||||
handle->start();
|
handle->start();
|
||||||
handle->close();
|
handle->close();
|
||||||
|
|||||||
@ -8,9 +8,9 @@ TEST(GetAddrInfo, GetNodeAddrInfo) {
|
|||||||
|
|
||||||
bool checkAddrInfoEvent = false;
|
bool checkAddrInfoEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::GetAddrInfoReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::AddrInfoEvent>([&checkAddrInfoEvent](const auto &, auto &) {
|
request->on<uvw::AddrInfoEvent>([&checkAddrInfoEvent](const uvw::AddrInfoEvent &, uvw::GetAddrInfoReq &) {
|
||||||
ASSERT_FALSE(checkAddrInfoEvent);
|
ASSERT_FALSE(checkAddrInfoEvent);
|
||||||
checkAddrInfoEvent = true;
|
checkAddrInfoEvent = true;
|
||||||
});
|
});
|
||||||
@ -40,7 +40,7 @@ TEST(GetAddrInfo, GetServiceAddrInfo) {
|
|||||||
|
|
||||||
bool checkErrorEvent = false;
|
bool checkErrorEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &) {
|
request->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::GetAddrInfoReq &) {
|
||||||
ASSERT_FALSE(checkErrorEvent);
|
ASSERT_FALSE(checkErrorEvent);
|
||||||
checkErrorEvent = true;
|
checkErrorEvent = true;
|
||||||
});
|
});
|
||||||
@ -69,9 +69,9 @@ TEST(GetAddrInfo, GetAddrInfo) {
|
|||||||
|
|
||||||
bool checkAddrInfoEvent = false;
|
bool checkAddrInfoEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::GetAddrInfoReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::AddrInfoEvent>([&checkAddrInfoEvent](const auto &, auto &) {
|
request->on<uvw::AddrInfoEvent>([&checkAddrInfoEvent](const uvw::AddrInfoEvent &, uvw::GetAddrInfoReq &) {
|
||||||
ASSERT_FALSE(checkAddrInfoEvent);
|
ASSERT_FALSE(checkAddrInfoEvent);
|
||||||
checkAddrInfoEvent = true;
|
checkAddrInfoEvent = true;
|
||||||
});
|
});
|
||||||
@ -103,12 +103,12 @@ TEST(GetNameInfo, GetNameInfo) {
|
|||||||
bool checkErrorEvent = false;
|
bool checkErrorEvent = false;
|
||||||
bool checkNameInfoEvent = false;
|
bool checkNameInfoEvent = false;
|
||||||
|
|
||||||
koRequest->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &) {
|
koRequest->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::GetNameInfoReq &) {
|
||||||
ASSERT_FALSE(checkErrorEvent);
|
ASSERT_FALSE(checkErrorEvent);
|
||||||
checkErrorEvent = true;
|
checkErrorEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
okRequest->on<uvw::NameInfoEvent>([&checkNameInfoEvent](const auto &, auto &) {
|
okRequest->on<uvw::NameInfoEvent>([&checkNameInfoEvent](const uvw::NameInfoEvent &, uvw::GetNameInfoReq &) {
|
||||||
ASSERT_FALSE(checkNameInfoEvent);
|
ASSERT_FALSE(checkNameInfoEvent);
|
||||||
checkNameInfoEvent = true;
|
checkNameInfoEvent = true;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,7 +11,7 @@ struct TestEmitter: uvw::Emitter<TestEmitter> {
|
|||||||
|
|
||||||
|
|
||||||
TEST(ErrorEvent, Functionalities) {
|
TEST(ErrorEvent, Functionalities) {
|
||||||
auto ecode = static_cast<std::underlying_type_t<uv_errno_t>>(UV_EADDRINUSE);
|
auto ecode = static_cast<typename std::underlying_type<uv_errno_t>::type>(UV_EADDRINUSE);
|
||||||
|
|
||||||
uvw::ErrorEvent event{ecode};
|
uvw::ErrorEvent event{ecode};
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ TEST(Emitter, EmptyAndClear) {
|
|||||||
|
|
||||||
ASSERT_TRUE(emitter.empty());
|
ASSERT_TRUE(emitter.empty());
|
||||||
|
|
||||||
emitter.on<uvw::ErrorEvent>([](const auto &, auto &){});
|
emitter.on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, TestEmitter &){});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
ASSERT_FALSE(emitter.empty<uvw::ErrorEvent>());
|
ASSERT_FALSE(emitter.empty<uvw::ErrorEvent>());
|
||||||
@ -48,8 +48,8 @@ TEST(Emitter, EmptyAndClear) {
|
|||||||
ASSERT_TRUE(emitter.empty<uvw::ErrorEvent>());
|
ASSERT_TRUE(emitter.empty<uvw::ErrorEvent>());
|
||||||
ASSERT_TRUE(emitter.empty<FakeEvent>());
|
ASSERT_TRUE(emitter.empty<FakeEvent>());
|
||||||
|
|
||||||
emitter.on<uvw::ErrorEvent>([](const auto &, auto &){});
|
emitter.on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, TestEmitter &){});
|
||||||
emitter.on<FakeEvent>([](const auto &, auto &){});
|
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
ASSERT_FALSE(emitter.empty<uvw::ErrorEvent>());
|
ASSERT_FALSE(emitter.empty<uvw::ErrorEvent>());
|
||||||
@ -66,7 +66,7 @@ TEST(Emitter, EmptyAndClear) {
|
|||||||
TEST(Emitter, On) {
|
TEST(Emitter, On) {
|
||||||
TestEmitter emitter{};
|
TestEmitter emitter{};
|
||||||
|
|
||||||
emitter.on<FakeEvent>([](const auto &, auto &){});
|
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
||||||
@ -81,7 +81,7 @@ TEST(Emitter, On) {
|
|||||||
TEST(Emitter, Once) {
|
TEST(Emitter, Once) {
|
||||||
TestEmitter emitter{};
|
TestEmitter emitter{};
|
||||||
|
|
||||||
emitter.once<FakeEvent>([](const auto &, auto &){});
|
emitter.once<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
||||||
@ -96,7 +96,7 @@ TEST(Emitter, Once) {
|
|||||||
TEST(Emitter, OnceAndErase) {
|
TEST(Emitter, OnceAndErase) {
|
||||||
TestEmitter emitter{};
|
TestEmitter emitter{};
|
||||||
|
|
||||||
auto conn = emitter.once<FakeEvent>([](const auto &, auto &){});
|
auto conn = emitter.once<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
||||||
@ -111,7 +111,7 @@ TEST(Emitter, OnceAndErase) {
|
|||||||
TEST(Emitter, OnAndErase) {
|
TEST(Emitter, OnAndErase) {
|
||||||
TestEmitter emitter{};
|
TestEmitter emitter{};
|
||||||
|
|
||||||
auto conn = emitter.on<FakeEvent>([](const auto &, auto &){});
|
auto conn = emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
ASSERT_FALSE(emitter.empty<FakeEvent>());
|
||||||
@ -126,8 +126,8 @@ TEST(Emitter, OnAndErase) {
|
|||||||
TEST(Emitter, CallbackClear) {
|
TEST(Emitter, CallbackClear) {
|
||||||
TestEmitter emitter{};
|
TestEmitter emitter{};
|
||||||
|
|
||||||
emitter.on<FakeEvent>([](const auto &, auto &ref) {
|
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &ref) {
|
||||||
ref.template on<FakeEvent>([](const auto &, auto &){});
|
ref.template on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
ref.clear();
|
ref.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,9 +139,9 @@ TEST(Emitter, CallbackClear) {
|
|||||||
ASSERT_TRUE(emitter.empty());
|
ASSERT_TRUE(emitter.empty());
|
||||||
ASSERT_TRUE(emitter.empty<FakeEvent>());
|
ASSERT_TRUE(emitter.empty<FakeEvent>());
|
||||||
|
|
||||||
emitter.on<FakeEvent>([](const auto &, auto &ref) {
|
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &ref) {
|
||||||
ref.clear();
|
ref.clear();
|
||||||
ref.template on<FakeEvent>([](const auto &, auto &){});
|
ref.template on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
|
||||||
});
|
});
|
||||||
|
|
||||||
ASSERT_FALSE(emitter.empty());
|
ASSERT_FALSE(emitter.empty());
|
||||||
|
|||||||
@ -18,12 +18,12 @@ TEST(FileReq, OpenAndCloseErr) {
|
|||||||
bool checkFileOpenErrorEvent = false;
|
bool checkFileOpenErrorEvent = false;
|
||||||
bool checkFileCloseErrorEvent = false;
|
bool checkFileCloseErrorEvent = false;
|
||||||
|
|
||||||
openReq->on<uvw::ErrorEvent>([&checkFileOpenErrorEvent](const auto &, auto &) {
|
openReq->on<uvw::ErrorEvent>([&checkFileOpenErrorEvent](const uvw::ErrorEvent &, uvw::FileReq &) {
|
||||||
ASSERT_FALSE(checkFileOpenErrorEvent);
|
ASSERT_FALSE(checkFileOpenErrorEvent);
|
||||||
checkFileOpenErrorEvent = true;
|
checkFileOpenErrorEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
closeReq->on<uvw::ErrorEvent>([&checkFileCloseErrorEvent](const auto &, auto &) {
|
closeReq->on<uvw::ErrorEvent>([&checkFileCloseErrorEvent](const uvw::ErrorEvent &, uvw::FileReq &) {
|
||||||
ASSERT_FALSE(checkFileCloseErrorEvent);
|
ASSERT_FALSE(checkFileCloseErrorEvent);
|
||||||
checkFileCloseErrorEvent = true;
|
checkFileCloseErrorEvent = true;
|
||||||
});
|
});
|
||||||
@ -61,14 +61,14 @@ TEST(FileReq, OpenAndClose) {
|
|||||||
bool checkFileOpenEvent = false;
|
bool checkFileOpenEvent = false;
|
||||||
bool checkFileCloseEvent = false;
|
bool checkFileCloseEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&checkFileCloseEvent](const auto &, auto &) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&checkFileCloseEvent](const uvw::FsEvent<uvw::FileReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
ASSERT_FALSE(checkFileCloseEvent);
|
ASSERT_FALSE(checkFileCloseEvent);
|
||||||
checkFileCloseEvent = true;
|
checkFileCloseEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&checkFileOpenEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&checkFileOpenEvent](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileOpenEvent);
|
ASSERT_FALSE(checkFileOpenEvent);
|
||||||
checkFileOpenEvent = true;
|
checkFileOpenEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
@ -106,22 +106,22 @@ TEST(FileReq, RWChecked) {
|
|||||||
bool checkFileWriteEvent = false;
|
bool checkFileWriteEvent = false;
|
||||||
bool checkFileReadEvent = false;
|
bool checkFileReadEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::READ>>([&checkFileReadEvent](const auto &event, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::READ>>([&checkFileReadEvent](const uvw::FsEvent<uvw::FileReq::Type::READ> &event, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileReadEvent);
|
ASSERT_FALSE(checkFileReadEvent);
|
||||||
ASSERT_EQ(event.data[0], 42);
|
ASSERT_EQ(event.data[0], 42);
|
||||||
checkFileReadEvent = true;
|
checkFileReadEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([&checkFileWriteEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([&checkFileWriteEvent](const uvw::FsEvent<uvw::FileReq::Type::WRITE> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileWriteEvent);
|
ASSERT_FALSE(checkFileWriteEvent);
|
||||||
checkFileWriteEvent = true;
|
checkFileWriteEvent = true;
|
||||||
req.read(0, 1);
|
req.read(0, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.write(std::unique_ptr<char[]>{new char[1]{ 42 }}, 1, 0);
|
req.write(std::unique_ptr<char[]>{new char[1]{ 42 }}, 1, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -145,22 +145,22 @@ TEST(FileReq, RWUnchecked) {
|
|||||||
bool checkFileWriteEvent = false;
|
bool checkFileWriteEvent = false;
|
||||||
bool checkFileReadEvent = false;
|
bool checkFileReadEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::READ>>([&checkFileReadEvent](const auto &event, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::READ>>([&checkFileReadEvent](const uvw::FsEvent<uvw::FileReq::Type::READ> &event, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileReadEvent);
|
ASSERT_FALSE(checkFileReadEvent);
|
||||||
ASSERT_EQ(event.data[0], 42);
|
ASSERT_EQ(event.data[0], 42);
|
||||||
checkFileReadEvent = true;
|
checkFileReadEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([&checkFileWriteEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([&checkFileWriteEvent](const uvw::FsEvent<uvw::FileReq::Type::WRITE> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileWriteEvent);
|
ASSERT_FALSE(checkFileWriteEvent);
|
||||||
checkFileWriteEvent = true;
|
checkFileWriteEvent = true;
|
||||||
req.read(0, 1);
|
req.read(0, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&data](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&data](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.write(data.get(), 1, 0);
|
req.write(data.get(), 1, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -207,15 +207,15 @@ TEST(FileReq, Stat) {
|
|||||||
|
|
||||||
bool checkFileStatEvent = false;
|
bool checkFileStatEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FSTAT>>([&checkFileStatEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FSTAT>>([&checkFileStatEvent](const uvw::FsEvent<uvw::FileReq::Type::FSTAT> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileStatEvent);
|
ASSERT_FALSE(checkFileStatEvent);
|
||||||
checkFileStatEvent = true;
|
checkFileStatEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.stat();
|
req.stat();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -254,15 +254,15 @@ TEST(FileReq, Sync) {
|
|||||||
|
|
||||||
bool checkFileSyncEvent = false;
|
bool checkFileSyncEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FSYNC>>([&checkFileSyncEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FSYNC>>([&checkFileSyncEvent](const uvw::FsEvent<uvw::FileReq::Type::FSYNC> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileSyncEvent);
|
ASSERT_FALSE(checkFileSyncEvent);
|
||||||
checkFileSyncEvent = true;
|
checkFileSyncEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.sync();
|
req.sync();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -297,15 +297,15 @@ TEST(FileReq, Datasync) {
|
|||||||
|
|
||||||
bool checkFileDatasyncEvent = false;
|
bool checkFileDatasyncEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FDATASYNC>>([&checkFileDatasyncEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FDATASYNC>>([&checkFileDatasyncEvent](const uvw::FsEvent<uvw::FileReq::Type::FDATASYNC> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileDatasyncEvent);
|
ASSERT_FALSE(checkFileDatasyncEvent);
|
||||||
checkFileDatasyncEvent = true;
|
checkFileDatasyncEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.datasync();
|
req.datasync();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -340,15 +340,15 @@ TEST(FileReq, Truncate) {
|
|||||||
|
|
||||||
bool checkFileTruncateEvent = false;
|
bool checkFileTruncateEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FTRUNCATE>>([&checkFileTruncateEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FTRUNCATE>>([&checkFileTruncateEvent](const uvw::FsEvent<uvw::FileReq::Type::FTRUNCATE> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileTruncateEvent);
|
ASSERT_FALSE(checkFileTruncateEvent);
|
||||||
checkFileTruncateEvent = true;
|
checkFileTruncateEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.truncate(0);
|
req.truncate(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -385,21 +385,21 @@ TEST(FileReq, SendFile) {
|
|||||||
|
|
||||||
bool checkFileSendFileEvent = false;
|
bool checkFileSendFileEvent = false;
|
||||||
|
|
||||||
dstReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
dstReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
srcReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
srcReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
dstReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&srcReq](const auto &, auto &req) {
|
dstReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&srcReq](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
srcReq->sendfile(static_cast<uvw::FileHandle>(req), 0, 0);
|
srcReq->sendfile(static_cast<uvw::FileHandle>(req), 0, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
srcReq->on<uvw::FsEvent<uvw::FileReq::Type::SENDFILE>>([&checkFileSendFileEvent, &dstReq](const auto &, auto &req) {
|
srcReq->on<uvw::FsEvent<uvw::FileReq::Type::SENDFILE>>([&checkFileSendFileEvent, &dstReq](const uvw::FsEvent<uvw::FileReq::Type::SENDFILE> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileSendFileEvent);
|
ASSERT_FALSE(checkFileSendFileEvent);
|
||||||
checkFileSendFileEvent = true;
|
checkFileSendFileEvent = true;
|
||||||
dstReq->close();
|
dstReq->close();
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
srcReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&dstFilename, &dstReq](const auto &, auto &) {
|
srcReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([&dstFilename, &dstReq](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &) {
|
||||||
auto flags = uvw::Flags<uvw::FileReq::FileOpen>::from<uvw::FileReq::FileOpen::CREAT, uvw::FileReq::FileOpen::WRONLY, uvw::FileReq::FileOpen::TRUNC>();
|
auto flags = uvw::Flags<uvw::FileReq::FileOpen>::from<uvw::FileReq::FileOpen::CREAT, uvw::FileReq::FileOpen::WRONLY, uvw::FileReq::FileOpen::TRUNC>();
|
||||||
dstReq->open(dstFilename, flags, 0644);
|
dstReq->open(dstFilename, flags, 0644);
|
||||||
});
|
});
|
||||||
@ -442,15 +442,15 @@ TEST(FileReq, Chmod) {
|
|||||||
|
|
||||||
bool checkFileChmodEvent = false;
|
bool checkFileChmodEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FCHMOD>>([&checkFileChmodEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FCHMOD>>([&checkFileChmodEvent](const uvw::FsEvent<uvw::FileReq::Type::FCHMOD> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileChmodEvent);
|
ASSERT_FALSE(checkFileChmodEvent);
|
||||||
checkFileChmodEvent = true;
|
checkFileChmodEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.chmod(0644);
|
req.chmod(0644);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -485,15 +485,15 @@ TEST(FileReq, Utime) {
|
|||||||
|
|
||||||
bool checkFileUtimeEvent = false;
|
bool checkFileUtimeEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FUTIME>>([&checkFileUtimeEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FUTIME>>([&checkFileUtimeEvent](const uvw::FsEvent<uvw::FileReq::Type::FUTIME> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileUtimeEvent);
|
ASSERT_FALSE(checkFileUtimeEvent);
|
||||||
checkFileUtimeEvent = true;
|
checkFileUtimeEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
auto epoch = now.time_since_epoch();
|
auto epoch = now.time_since_epoch();
|
||||||
auto value = std::chrono::duration_cast<std::chrono::seconds>(epoch);
|
auto value = std::chrono::duration_cast<std::chrono::seconds>(epoch);
|
||||||
@ -537,21 +537,21 @@ TEST(FileReq, Chown) {
|
|||||||
|
|
||||||
bool checkFileChownEvent = false;
|
bool checkFileChownEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FCHOWN>>([&checkFileChownEvent](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FCHOWN>>([&checkFileChownEvent](const uvw::FsEvent<uvw::FileReq::Type::FCHOWN> &, uvw::FileReq &req) {
|
||||||
ASSERT_FALSE(checkFileChownEvent);
|
ASSERT_FALSE(checkFileChownEvent);
|
||||||
checkFileChownEvent = true;
|
checkFileChownEvent = true;
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::FSTAT>>([](const auto &event, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::FSTAT>>([](const uvw::FsEvent<uvw::FileReq::Type::FSTAT> &event, uvw::FileReq &req) {
|
||||||
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
|
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
|
||||||
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
|
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
|
||||||
req.chown(uid, gid);
|
req.chown(uid, gid);
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.stat();
|
req.stat();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,10 @@ TEST(FsEvent, Functionalities) {
|
|||||||
|
|
||||||
bool checkFsEventEvent = false;
|
bool checkFsEventEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsEventHandle &) { FAIL(); });
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
handle->on<uvw::FsEventEvent>([&checkFsEventEvent](const auto &event, auto &hndl) {
|
handle->on<uvw::FsEventEvent>([&checkFsEventEvent](const uvw::FsEventEvent &event, uvw::FsEventHandle &hndl) {
|
||||||
ASSERT_FALSE(checkFsEventEvent);
|
ASSERT_FALSE(checkFsEventEvent);
|
||||||
ASSERT_EQ(std::string{event.filename}, std::string{"test.file"});
|
ASSERT_EQ(std::string{event.filename}, std::string{"test.file"});
|
||||||
checkFsEventEvent = true;
|
checkFsEventEvent = true;
|
||||||
@ -23,11 +23,11 @@ TEST(FsEvent, Functionalities) {
|
|||||||
ASSERT_TRUE(hndl.closing());
|
ASSERT_TRUE(hndl.closing());
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([](const uvw::FsEvent<uvw::FileReq::Type::WRITE> &, uvw::FileReq &req) {
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FileReq::Type::OPEN> &, uvw::FileReq &req) {
|
||||||
req.write(std::unique_ptr<char[]>{new char[1]{ 42 }}, 1, 0);
|
req.write(std::unique_ptr<char[]>{new char[1]{ 42 }}, 1, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,10 @@ TEST(FsPoll, Functionalities) {
|
|||||||
|
|
||||||
bool checkFsPollEvent = false;
|
bool checkFsPollEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsPollHandle &) { FAIL(); });
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
handle->on<uvw::FsPollEvent>([&checkFsPollEvent](const auto &, auto &hndl) {
|
handle->on<uvw::FsPollEvent>([&checkFsPollEvent](const uvw::FsPollEvent &, uvw::FsPollHandle &hndl) {
|
||||||
ASSERT_FALSE(checkFsPollEvent);
|
ASSERT_FALSE(checkFsPollEvent);
|
||||||
checkFsPollEvent = true;
|
checkFsPollEvent = true;
|
||||||
hndl.stop();
|
hndl.stop();
|
||||||
@ -22,7 +22,7 @@ TEST(FsPoll, Functionalities) {
|
|||||||
ASSERT_TRUE(hndl.closing());
|
ASSERT_TRUE(hndl.closing());
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FileReq::Type::WRITE>>([](const uvw::FsEvent<uvw::FileReq::Type::WRITE> &, uvw::FileReq &req) {
|
||||||
req.close();
|
req.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -17,14 +17,14 @@ TEST(FsReq, MkdirAndRmdir) {
|
|||||||
bool checkFsMkdirEvent = false;
|
bool checkFsMkdirEvent = false;
|
||||||
bool checkFsRmdirEvent = false;
|
bool checkFsRmdirEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FsReq::Type::RMDIR>>([&checkFsRmdirEvent](const auto &, auto &) {
|
request->on<uvw::FsEvent<uvw::FsReq::Type::RMDIR>>([&checkFsRmdirEvent](const uvw::FsEvent<uvw::FsReq::Type::RMDIR> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsRmdirEvent);
|
ASSERT_FALSE(checkFsRmdirEvent);
|
||||||
checkFsRmdirEvent = true;
|
checkFsRmdirEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FsReq::Type::MKDIR>>([&checkFsMkdirEvent, &dirname](const auto &, auto &req) {
|
request->on<uvw::FsEvent<uvw::FsReq::Type::MKDIR>>([&checkFsMkdirEvent, &dirname](const uvw::FsEvent<uvw::FsReq::Type::MKDIR> &, uvw::FsReq &req) {
|
||||||
ASSERT_FALSE(checkFsMkdirEvent);
|
ASSERT_FALSE(checkFsMkdirEvent);
|
||||||
checkFsMkdirEvent = true;
|
checkFsMkdirEvent = true;
|
||||||
req.rmdir(dirname);
|
req.rmdir(dirname);
|
||||||
@ -61,14 +61,14 @@ TEST(FsReq, MkdtempAndRmdir) {
|
|||||||
bool checkFsMkdtempEvent = false;
|
bool checkFsMkdtempEvent = false;
|
||||||
bool checkFsRmdirEvent = false;
|
bool checkFsRmdirEvent = false;
|
||||||
|
|
||||||
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
request->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FsReq::Type::RMDIR>>([&checkFsRmdirEvent](const auto &, auto &) {
|
request->on<uvw::FsEvent<uvw::FsReq::Type::RMDIR>>([&checkFsRmdirEvent](const uvw::FsEvent<uvw::FsReq::Type::RMDIR> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsRmdirEvent);
|
ASSERT_FALSE(checkFsRmdirEvent);
|
||||||
checkFsRmdirEvent = true;
|
checkFsRmdirEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
request->on<uvw::FsEvent<uvw::FsReq::Type::MKDTEMP>>([&checkFsMkdtempEvent](const auto &event, auto &req) {
|
request->on<uvw::FsEvent<uvw::FsReq::Type::MKDTEMP>>([&checkFsMkdtempEvent](const uvw::FsEvent<uvw::FsReq::Type::MKDTEMP> &event, uvw::FsReq &req) {
|
||||||
ASSERT_FALSE(checkFsMkdtempEvent);
|
ASSERT_FALSE(checkFsMkdtempEvent);
|
||||||
ASSERT_NE(event.path, nullptr);
|
ASSERT_NE(event.path, nullptr);
|
||||||
checkFsMkdtempEvent = true;
|
checkFsMkdtempEvent = true;
|
||||||
@ -121,19 +121,19 @@ TEST(FsReq, Stat) {
|
|||||||
|
|
||||||
bool checkFsStatEvent = false;
|
bool checkFsStatEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&checkFsStatEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&checkFsStatEvent](const uvw::FsEvent<uvw::FsReq::Type::STAT> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsStatEvent);
|
ASSERT_FALSE(checkFsStatEvent);
|
||||||
checkFsStatEvent = true;
|
checkFsStatEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->stat(filename);
|
fsReq->stat(filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -173,19 +173,19 @@ TEST(FsReq, Lstat) {
|
|||||||
|
|
||||||
bool checkFsLstatEvent = false;
|
bool checkFsLstatEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LSTAT>>([&checkFsLstatEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LSTAT>>([&checkFsLstatEvent](const uvw::FsEvent<uvw::FsReq::Type::LSTAT> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsLstatEvent);
|
ASSERT_FALSE(checkFsLstatEvent);
|
||||||
checkFsLstatEvent = true;
|
checkFsLstatEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->lstat(filename);
|
fsReq->lstat(filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -226,19 +226,19 @@ TEST(FsReq, Rename) {
|
|||||||
|
|
||||||
bool checkFsRenameEvent = false;
|
bool checkFsRenameEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::RENAME>>([&checkFsRenameEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::RENAME>>([&checkFsRenameEvent](const uvw::FsEvent<uvw::FsReq::Type::RENAME> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsRenameEvent);
|
ASSERT_FALSE(checkFsRenameEvent);
|
||||||
checkFsRenameEvent = true;
|
checkFsRenameEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &rename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &rename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->rename(filename, rename);
|
fsReq->rename(filename, rename);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -286,19 +286,19 @@ TEST(FsReq, Access) {
|
|||||||
|
|
||||||
bool checkFsAccessEvent = false;
|
bool checkFsAccessEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::ACCESS>>([&checkFsAccessEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::ACCESS>>([&checkFsAccessEvent](const uvw::FsEvent<uvw::FsReq::Type::ACCESS> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsAccessEvent);
|
ASSERT_FALSE(checkFsAccessEvent);
|
||||||
checkFsAccessEvent = true;
|
checkFsAccessEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->access(filename, R_OK);
|
fsReq->access(filename, R_OK);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -335,19 +335,19 @@ TEST(FsReq, Chmod) {
|
|||||||
|
|
||||||
bool checkFsChmodEvent = false;
|
bool checkFsChmodEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::CHMOD>>([&checkFsChmodEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::CHMOD>>([&checkFsChmodEvent](const uvw::FsEvent<uvw::FsReq::Type::CHMOD> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsChmodEvent);
|
ASSERT_FALSE(checkFsChmodEvent);
|
||||||
checkFsChmodEvent = true;
|
checkFsChmodEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->chmod(filename, 0644);
|
fsReq->chmod(filename, 0644);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -384,22 +384,22 @@ TEST(FsReq, Utime) {
|
|||||||
|
|
||||||
bool checkFsUtimeEvent = false;
|
bool checkFsUtimeEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::UTIME>>([&checkFsUtimeEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::UTIME>>([&checkFsUtimeEvent](const uvw::FsEvent<uvw::FsReq::Type::UTIME> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsUtimeEvent);
|
ASSERT_FALSE(checkFsUtimeEvent);
|
||||||
checkFsUtimeEvent = true;
|
checkFsUtimeEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
auto epoch = now.time_since_epoch();
|
auto epoch = now.time_since_epoch();
|
||||||
auto value = std::chrono::duration_cast<std::chrono::seconds>(epoch);
|
auto value = std::chrono::duration_cast<std::chrono::seconds>(epoch);
|
||||||
fsReq->utime(filename, value, value);
|
fsReq->utime(filename, value, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -443,25 +443,25 @@ TEST(FsReq, LinkAndUnlink) {
|
|||||||
bool checkFsLinkEvent = false;
|
bool checkFsLinkEvent = false;
|
||||||
bool checkFsUnlinkEvent = false;
|
bool checkFsUnlinkEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::UNLINK>>([&checkFsUnlinkEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::UNLINK>>([&checkFsUnlinkEvent](const uvw::FsEvent<uvw::FsReq::Type::UNLINK> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsUnlinkEvent);
|
ASSERT_FALSE(checkFsUnlinkEvent);
|
||||||
checkFsUnlinkEvent = true;
|
checkFsUnlinkEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LINK>>([&checkFsLinkEvent, &linkname](const auto &, auto &request) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LINK>>([&checkFsLinkEvent, &linkname](const uvw::FsEvent<uvw::FsReq::Type::LINK> &, uvw::FsReq &request) {
|
||||||
ASSERT_FALSE(checkFsLinkEvent);
|
ASSERT_FALSE(checkFsLinkEvent);
|
||||||
checkFsLinkEvent = true;
|
checkFsLinkEvent = true;
|
||||||
request.unlink(linkname);
|
request.unlink(linkname);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->link(filename, linkname);
|
fsReq->link(filename, linkname);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -503,25 +503,25 @@ TEST(FsReq, SymlinkAndUnlink) {
|
|||||||
bool checkFsLinkEvent = false;
|
bool checkFsLinkEvent = false;
|
||||||
bool checkFsUnlinkEvent = false;
|
bool checkFsUnlinkEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::UNLINK>>([&checkFsUnlinkEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::UNLINK>>([&checkFsUnlinkEvent](const uvw::FsEvent<uvw::FsReq::Type::UNLINK> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsUnlinkEvent);
|
ASSERT_FALSE(checkFsUnlinkEvent);
|
||||||
checkFsUnlinkEvent = true;
|
checkFsUnlinkEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::SYMLINK>>([&checkFsLinkEvent, &linkname](const auto &, auto &request) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::SYMLINK>>([&checkFsLinkEvent, &linkname](const uvw::FsEvent<uvw::FsReq::Type::SYMLINK> &, uvw::FsReq &request) {
|
||||||
ASSERT_FALSE(checkFsLinkEvent);
|
ASSERT_FALSE(checkFsLinkEvent);
|
||||||
checkFsLinkEvent = true;
|
checkFsLinkEvent = true;
|
||||||
request.unlink(linkname);
|
request.unlink(linkname);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->symlink(filename, linkname);
|
fsReq->symlink(filename, linkname);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -562,24 +562,24 @@ TEST(FsReq, Readlink) {
|
|||||||
|
|
||||||
bool checkFsReadlinkEvent = false;
|
bool checkFsReadlinkEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::READLINK>>([&checkFsReadlinkEvent, &linkname](const auto &, auto &request) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::READLINK>>([&checkFsReadlinkEvent, &linkname](const uvw::FsEvent<uvw::FsReq::Type::READLINK> &, uvw::FsReq &request) {
|
||||||
ASSERT_FALSE(checkFsReadlinkEvent);
|
ASSERT_FALSE(checkFsReadlinkEvent);
|
||||||
checkFsReadlinkEvent = true;
|
checkFsReadlinkEvent = true;
|
||||||
request.unlink(linkname);
|
request.unlink(linkname);
|
||||||
});
|
});
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::SYMLINK>>([&linkname](const auto &, auto &request) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::SYMLINK>>([&linkname](const uvw::FsEvent<uvw::FsReq::Type::SYMLINK> &, uvw::FsReq &request) {
|
||||||
request.readlink(linkname);
|
request.readlink(linkname);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->symlink(filename, linkname, 0);
|
fsReq->symlink(filename, linkname, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -622,20 +622,20 @@ TEST(FsReq, Realpath) {
|
|||||||
|
|
||||||
bool checkFsRealpathEvent = false;
|
bool checkFsRealpathEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::REALPATH>>([&checkFsRealpathEvent](const auto &event, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::REALPATH>>([&checkFsRealpathEvent](const uvw::FsEvent<uvw::FsReq::Type::REALPATH> &event, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsRealpathEvent);
|
ASSERT_FALSE(checkFsRealpathEvent);
|
||||||
ASSERT_NE(event.path, nullptr);
|
ASSERT_NE(event.path, nullptr);
|
||||||
checkFsRealpathEvent = true;
|
checkFsRealpathEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->realpath(filename);
|
fsReq->realpath(filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -676,25 +676,25 @@ TEST(FsReq, Chown) {
|
|||||||
|
|
||||||
bool checkFsChownEvent = false;
|
bool checkFsChownEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::CHOWN>>([&checkFsChownEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::CHOWN>>([&checkFsChownEvent](const uvw::FsEvent<uvw::FsReq::Type::CHOWN> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsChownEvent);
|
ASSERT_FALSE(checkFsChownEvent);
|
||||||
checkFsChownEvent = true;
|
checkFsChownEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&filename](const auto &event, auto &request) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&filename](const uvw::FsEvent<uvw::FsReq::Type::STAT> &event, uvw::FsReq &request) {
|
||||||
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
|
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
|
||||||
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
|
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
|
||||||
request.chown(filename, uid, gid);
|
request.chown(filename, uid, gid);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->stat(filename);
|
fsReq->stat(filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -737,25 +737,25 @@ TEST(FsReq, Lchown) {
|
|||||||
|
|
||||||
bool checkFsLChownEvent = false;
|
bool checkFsLChownEvent = false;
|
||||||
|
|
||||||
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { FAIL(); });
|
||||||
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
fileReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { FAIL(); });
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LCHOWN>>([&checkFsLChownEvent](const auto &, auto &) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LCHOWN>>([&checkFsLChownEvent](const uvw::FsEvent<uvw::FsReq::Type::LCHOWN> &, uvw::FsReq &) {
|
||||||
ASSERT_FALSE(checkFsLChownEvent);
|
ASSERT_FALSE(checkFsLChownEvent);
|
||||||
checkFsLChownEvent = true;
|
checkFsLChownEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&filename](const auto &event, auto &request) {
|
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&filename](const uvw::FsEvent<uvw::FsReq::Type::STAT> &event, uvw::FsReq &request) {
|
||||||
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
|
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
|
||||||
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
|
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
|
||||||
request.lchown(filename, uid, gid);
|
request.lchown(filename, uid, gid);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const uvw::FsEvent<uvw::FsReq::Type::CLOSE> &, uvw::FileReq &) {
|
||||||
fsReq->stat(filename);
|
fsReq->stat(filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
|
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const uvw::FsEvent<uvw::FsReq::Type::OPEN> &, uvw::FileReq &request) {
|
||||||
request.close();
|
request.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ struct FakeHandle: uvw::Handle<FakeHandle, fake_handle_t> {
|
|||||||
using Handle::Handle;
|
using Handle::Handle;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
bool init(Args&&...) { return initialize([](auto...){ return true; }); }
|
bool init(Args&&...) { return initialize([](uv_loop_t*, fake_handle_t*){ return true; }); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,9 @@ TEST(Idle, StartAndStop) {
|
|||||||
|
|
||||||
bool checkIdleEvent = false;
|
bool checkIdleEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::IdleHandle &) { FAIL(); });
|
||||||
|
|
||||||
handle->on<uvw::IdleEvent>([&checkIdleEvent](const auto &, auto &hndl) {
|
handle->on<uvw::IdleEvent>([&checkIdleEvent](const uvw::IdleEvent &, uvw::IdleHandle &hndl) {
|
||||||
ASSERT_FALSE(checkIdleEvent);
|
ASSERT_FALSE(checkIdleEvent);
|
||||||
checkIdleEvent = true;
|
checkIdleEvent = true;
|
||||||
hndl.stop();
|
hndl.stop();
|
||||||
@ -33,9 +33,8 @@ TEST(Idle, Fake) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::IdleHandle>();
|
auto handle = loop->resource<uvw::IdleHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::IdleHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::IdleEvent>([](const uvw::IdleEvent &, uvw::IdleHandle &) { FAIL(); });
|
||||||
handle->on<uvw::IdleEvent>(l);
|
|
||||||
|
|
||||||
handle->start();
|
handle->start();
|
||||||
handle->close();
|
handle->close();
|
||||||
|
|||||||
@ -21,11 +21,9 @@ TEST(Loop, Functionalities) {
|
|||||||
auto handle = loop->resource<uvw::PrepareHandle>();
|
auto handle = loop->resource<uvw::PrepareHandle>();
|
||||||
auto req = loop->resource<uvw::WorkReq>([]{});
|
auto req = loop->resource<uvw::WorkReq>([]{});
|
||||||
|
|
||||||
auto err = [](const auto &, auto &) { FAIL(); };
|
loop->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::Loop &) { FAIL(); });
|
||||||
|
req->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::WorkReq &) { FAIL(); });
|
||||||
loop->on<uvw::ErrorEvent>(err);
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PrepareHandle &) { FAIL(); });
|
||||||
req->on<uvw::ErrorEvent>(err);
|
|
||||||
handle->on<uvw::ErrorEvent>(err);
|
|
||||||
|
|
||||||
ASSERT_TRUE(static_cast<bool>(handle));
|
ASSERT_TRUE(static_cast<bool>(handle));
|
||||||
ASSERT_TRUE(static_cast<bool>(req));
|
ASSERT_TRUE(static_cast<bool>(req));
|
||||||
@ -39,7 +37,7 @@ TEST(Loop, Functionalities) {
|
|||||||
ASSERT_FALSE(loop->timeout().first);
|
ASSERT_FALSE(loop->timeout().first);
|
||||||
|
|
||||||
handle->start();
|
handle->start();
|
||||||
handle->on<uvw::PrepareEvent>([](const auto &, auto &hndl) {
|
handle->on<uvw::PrepareEvent>([](const uvw::PrepareEvent &, uvw::PrepareHandle &hndl) {
|
||||||
hndl.loop().walk([](uvw::BaseHandle &) {
|
hndl.loop().walk([](uvw::BaseHandle &) {
|
||||||
static bool trigger = true;
|
static bool trigger = true;
|
||||||
ASSERT_TRUE(trigger);
|
ASSERT_TRUE(trigger);
|
||||||
|
|||||||
@ -9,8 +9,8 @@ TEST(Pipe, ReadWrite) {
|
|||||||
auto server = loop->resource<uvw::PipeHandle>();
|
auto server = loop->resource<uvw::PipeHandle>();
|
||||||
auto client = loop->resource<uvw::PipeHandle>();
|
auto client = loop->resource<uvw::PipeHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
|
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
|
||||||
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();
|
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();
|
||||||
@ -52,8 +52,8 @@ TEST(Pipe, SockPeer) {
|
|||||||
auto server = loop->resource<uvw::PipeHandle>();
|
auto server = loop->resource<uvw::PipeHandle>();
|
||||||
auto client = loop->resource<uvw::PipeHandle>();
|
auto client = loop->resource<uvw::PipeHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::ListenEvent>([&sockname](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
|
server->once<uvw::ListenEvent>([&sockname](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
|
||||||
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();
|
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();
|
||||||
@ -90,8 +90,8 @@ TEST(Pipe, Shutdown) {
|
|||||||
auto server = loop->resource<uvw::PipeHandle>();
|
auto server = loop->resource<uvw::PipeHandle>();
|
||||||
auto client = loop->resource<uvw::PipeHandle>();
|
auto client = loop->resource<uvw::PipeHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
|
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
|
||||||
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();
|
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();
|
||||||
|
|||||||
@ -8,9 +8,9 @@ TEST(Prepare, StartAndStop) {
|
|||||||
|
|
||||||
bool checkPrepareEvent = false;
|
bool checkPrepareEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PrepareHandle &) { FAIL(); });
|
||||||
|
|
||||||
handle->on<uvw::PrepareEvent>([&checkPrepareEvent](const auto &, auto &hndl) {
|
handle->on<uvw::PrepareEvent>([&checkPrepareEvent](const uvw::PrepareEvent &, uvw::PrepareHandle &hndl) {
|
||||||
ASSERT_FALSE(checkPrepareEvent);
|
ASSERT_FALSE(checkPrepareEvent);
|
||||||
checkPrepareEvent = true;
|
checkPrepareEvent = true;
|
||||||
hndl.stop();
|
hndl.stop();
|
||||||
@ -33,9 +33,8 @@ TEST(Prepare, Fake) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::PrepareHandle>();
|
auto handle = loop->resource<uvw::PrepareHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PrepareHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::PrepareEvent>([](const uvw::PrepareEvent &, uvw::PrepareHandle &) { FAIL(); });
|
||||||
handle->on<uvw::PrepareEvent>(l);
|
|
||||||
|
|
||||||
handle->start();
|
handle->start();
|
||||||
handle->close();
|
handle->close();
|
||||||
|
|||||||
@ -6,9 +6,8 @@ TEST(Signal, Start) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::SignalHandle>();
|
auto handle = loop->resource<uvw::SignalHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::SignalHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::CheckEvent>([](const uvw::CheckEvent &, uvw::SignalHandle &) { FAIL(); });
|
||||||
handle->on<uvw::CheckEvent>(l);
|
|
||||||
|
|
||||||
handle->start(2);
|
handle->start(2);
|
||||||
|
|
||||||
@ -27,9 +26,8 @@ TEST(Signal, OneShot) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::SignalHandle>();
|
auto handle = loop->resource<uvw::SignalHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::SignalHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::CheckEvent>([](const uvw::CheckEvent &, uvw::SignalHandle &) { FAIL(); });
|
||||||
handle->on<uvw::CheckEvent>(l);
|
|
||||||
|
|
||||||
handle->oneShot(2);
|
handle->oneShot(2);
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
#include <uvw.hpp>
|
#include <uvw.hpp>
|
||||||
|
|
||||||
|
|
||||||
TEST(Tcp, Functionalities) {
|
TEST(TCP, Functionalities) {
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::TcpHandle>();
|
auto handle = loop->resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
ASSERT_TRUE(handle->noDelay(true));
|
ASSERT_TRUE(handle->noDelay(true));
|
||||||
ASSERT_TRUE(handle->keepAlive(true, uvw::TcpHandle::Time{128}));
|
ASSERT_TRUE(handle->keepAlive(true, uvw::TCPHandle::Time{128}));
|
||||||
ASSERT_TRUE(handle->simultaneousAccepts());
|
ASSERT_TRUE(handle->simultaneousAccepts());
|
||||||
|
|
||||||
handle->close();
|
handle->close();
|
||||||
@ -15,33 +15,33 @@ TEST(Tcp, Functionalities) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Tcp, ReadWrite) {
|
TEST(TCP, ReadWrite) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto server = loop->resource<uvw::TcpHandle>();
|
auto server = loop->resource<uvw::TCPHandle>();
|
||||||
auto client = loop->resource<uvw::TcpHandle>();
|
auto client = loop->resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &handle) {
|
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &handle) {
|
||||||
std::shared_ptr<uvw::TcpHandle> socket = handle.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> socket = handle.loop().resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
socket->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); });
|
socket->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
socket->on<uvw::CloseEvent>([&handle](const uvw::CloseEvent &, uvw::TcpHandle &) { handle.close(); });
|
socket->on<uvw::CloseEvent>([&handle](const uvw::CloseEvent &, uvw::TCPHandle &) { handle.close(); });
|
||||||
socket->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); });
|
socket->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); });
|
||||||
|
|
||||||
handle.accept(*socket);
|
handle.accept(*socket);
|
||||||
socket->read();
|
socket->read();
|
||||||
});
|
});
|
||||||
|
|
||||||
client->once<uvw::WriteEvent>([](const uvw::WriteEvent &, uvw::TcpHandle &handle) {
|
client->once<uvw::WriteEvent>([](const uvw::WriteEvent &, uvw::TCPHandle &handle) {
|
||||||
handle.close();
|
handle.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
client->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) {
|
client->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
|
||||||
ASSERT_TRUE(handle.writable());
|
ASSERT_TRUE(handle.writable());
|
||||||
ASSERT_TRUE(handle.readable());
|
ASSERT_TRUE(handle.readable());
|
||||||
|
|
||||||
@ -59,23 +59,23 @@ TEST(Tcp, ReadWrite) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Tcp, SockPeer) {
|
TEST(TCP, SockPeer) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto server = loop->resource<uvw::TcpHandle>();
|
auto server = loop->resource<uvw::TCPHandle>();
|
||||||
auto client = loop->resource<uvw::TcpHandle>();
|
auto client = loop->resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::ListenEvent>([&address, port](const uvw::ListenEvent &, uvw::TcpHandle &handle) {
|
server->once<uvw::ListenEvent>([&address, port](const uvw::ListenEvent &, uvw::TCPHandle &handle) {
|
||||||
std::shared_ptr<uvw::TcpHandle> socket = handle.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> socket = handle.loop().resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
socket->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); });
|
socket->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
socket->on<uvw::CloseEvent>([&handle](const uvw::CloseEvent &, uvw::TcpHandle &) { handle.close(); });
|
socket->on<uvw::CloseEvent>([&handle](const uvw::CloseEvent &, uvw::TCPHandle &) { handle.close(); });
|
||||||
socket->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); });
|
socket->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); });
|
||||||
|
|
||||||
handle.accept(*socket);
|
handle.accept(*socket);
|
||||||
socket->read();
|
socket->read();
|
||||||
@ -86,7 +86,7 @@ TEST(Tcp, SockPeer) {
|
|||||||
ASSERT_EQ(addr.port, decltype(addr.port){port});
|
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);
|
||||||
@ -103,33 +103,33 @@ TEST(Tcp, SockPeer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Tcp, Shutdown) {
|
TEST(TCP, Shutdown) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto server = loop->resource<uvw::TcpHandle>();
|
auto server = loop->resource<uvw::TCPHandle>();
|
||||||
auto client = loop->resource<uvw::TcpHandle>();
|
auto client = loop->resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &handle) {
|
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &handle) {
|
||||||
std::shared_ptr<uvw::TcpHandle> socket = handle.loop().resource<uvw::TcpHandle>();
|
std::shared_ptr<uvw::TCPHandle> socket = handle.loop().resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
socket->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); });
|
socket->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
|
||||||
socket->on<uvw::CloseEvent>([&handle](const uvw::CloseEvent &, uvw::TcpHandle &) { handle.close(); });
|
socket->on<uvw::CloseEvent>([&handle](const uvw::CloseEvent &, uvw::TCPHandle &) { handle.close(); });
|
||||||
socket->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); });
|
socket->on<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); });
|
||||||
|
|
||||||
handle.accept(*socket);
|
handle.accept(*socket);
|
||||||
socket->read();
|
socket->read();
|
||||||
});
|
});
|
||||||
|
|
||||||
client->once<uvw::ShutdownEvent>([](const uvw::ShutdownEvent &, uvw::TcpHandle &handle) {
|
client->once<uvw::ShutdownEvent>([](const uvw::ShutdownEvent &, uvw::TCPHandle &handle) {
|
||||||
handle.close();
|
handle.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
client->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) {
|
client->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
|
||||||
handle.shutdown();
|
handle.shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -141,9 +141,9 @@ TEST(Tcp, Shutdown) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Tcp, WriteError) {
|
TEST(TCP, WriteError) {
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::TcpHandle>();
|
auto handle = loop->resource<uvw::TCPHandle>();
|
||||||
|
|
||||||
bool checkWriteSmartPtrErrorEvent = false;
|
bool checkWriteSmartPtrErrorEvent = false;
|
||||||
bool checkWriteNakedPtrErrorEvent = false;
|
bool checkWriteNakedPtrErrorEvent = false;
|
||||||
@ -151,13 +151,13 @@ TEST(Tcp, WriteError) {
|
|||||||
bool checkTryWriteNakedPtrErrorEvent = false;
|
bool checkTryWriteNakedPtrErrorEvent = false;
|
||||||
|
|
||||||
handle->close();
|
handle->close();
|
||||||
handle->once<uvw::ErrorEvent>([&checkWriteSmartPtrErrorEvent](const auto &, auto &) { checkWriteSmartPtrErrorEvent = true; });
|
handle->once<uvw::ErrorEvent>([&checkWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkWriteSmartPtrErrorEvent = true; });
|
||||||
handle->write(std::unique_ptr<char[]>{}, 0);
|
handle->write(std::unique_ptr<char[]>{}, 0);
|
||||||
handle->once<uvw::ErrorEvent>([&checkWriteNakedPtrErrorEvent](const auto &, auto &) { checkWriteNakedPtrErrorEvent = true; });
|
handle->once<uvw::ErrorEvent>([&checkWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkWriteNakedPtrErrorEvent = true; });
|
||||||
handle->write(nullptr, 0);
|
handle->write(nullptr, 0);
|
||||||
handle->once<uvw::ErrorEvent>([&checkTryWriteSmartPtrErrorEvent](const auto &, auto &) { checkTryWriteSmartPtrErrorEvent = true; });
|
handle->once<uvw::ErrorEvent>([&checkTryWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkTryWriteSmartPtrErrorEvent = true; });
|
||||||
handle->tryWrite(std::unique_ptr<char[]>{}, 0);
|
handle->tryWrite(std::unique_ptr<char[]>{}, 0);
|
||||||
handle->once<uvw::ErrorEvent>([&checkTryWriteNakedPtrErrorEvent](const auto &, auto &) { checkTryWriteNakedPtrErrorEvent = true; });
|
handle->once<uvw::ErrorEvent>([&checkTryWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkTryWriteNakedPtrErrorEvent = true; });
|
||||||
handle->tryWrite(nullptr, 0);
|
handle->tryWrite(nullptr, 0);
|
||||||
|
|
||||||
loop->run();
|
loop->run();
|
||||||
|
|||||||
@ -10,10 +10,10 @@ TEST(Timer, StartAndStop) {
|
|||||||
bool checkTimerNoRepeatEvent = false;
|
bool checkTimerNoRepeatEvent = false;
|
||||||
bool checkTimerRepeatEvent = false;
|
bool checkTimerRepeatEvent = false;
|
||||||
|
|
||||||
handleNoRepeat->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handleNoRepeat->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TimerHandle &) { FAIL(); });
|
||||||
handleRepeat->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handleRepeat->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TimerHandle &) { FAIL(); });
|
||||||
|
|
||||||
handleNoRepeat->on<uvw::TimerEvent>([&checkTimerNoRepeatEvent](const auto &, auto &handle) {
|
handleNoRepeat->on<uvw::TimerEvent>([&checkTimerNoRepeatEvent](const uvw::TimerEvent &, uvw::TimerHandle &handle) {
|
||||||
ASSERT_FALSE(checkTimerNoRepeatEvent);
|
ASSERT_FALSE(checkTimerNoRepeatEvent);
|
||||||
checkTimerNoRepeatEvent = true;
|
checkTimerNoRepeatEvent = true;
|
||||||
handle.stop();
|
handle.stop();
|
||||||
@ -21,7 +21,7 @@ TEST(Timer, StartAndStop) {
|
|||||||
ASSERT_TRUE(handle.closing());
|
ASSERT_TRUE(handle.closing());
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRepeat->on<uvw::TimerEvent>([&checkTimerRepeatEvent](const auto &, auto &handle) {
|
handleRepeat->on<uvw::TimerEvent>([&checkTimerRepeatEvent](const uvw::TimerEvent &, uvw::TimerHandle &handle) {
|
||||||
if(checkTimerRepeatEvent) {
|
if(checkTimerRepeatEvent) {
|
||||||
handle.stop();
|
handle.stop();
|
||||||
handle.close();
|
handle.close();
|
||||||
@ -55,12 +55,12 @@ TEST(Timer, Again) {
|
|||||||
bool checkErrorEvent = false;
|
bool checkErrorEvent = false;
|
||||||
bool checkTimerEvent = false;
|
bool checkTimerEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &) {
|
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::TimerHandle &) {
|
||||||
ASSERT_FALSE(checkErrorEvent);
|
ASSERT_FALSE(checkErrorEvent);
|
||||||
checkErrorEvent = true;
|
checkErrorEvent = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
handle->on<uvw::TimerEvent>([&checkTimerEvent](const auto &, auto &hndl) {
|
handle->on<uvw::TimerEvent>([&checkTimerEvent](const uvw::TimerEvent &, uvw::TimerHandle &hndl) {
|
||||||
static bool guard = false;
|
static bool guard = false;
|
||||||
|
|
||||||
if(guard) {
|
if(guard) {
|
||||||
@ -111,9 +111,8 @@ TEST(Timer, Fake) {
|
|||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::TimerHandle>();
|
auto handle = loop->resource<uvw::TimerHandle>();
|
||||||
|
|
||||||
auto l = [](const auto &, auto &) { FAIL(); };
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TimerHandle &) { FAIL(); });
|
||||||
handle->on<uvw::ErrorEvent>(l);
|
handle->on<uvw::TimerEvent>([](const uvw::TimerEvent &, uvw::TimerHandle &) { FAIL(); });
|
||||||
handle->on<uvw::TimerEvent>(l);
|
|
||||||
|
|
||||||
handle->start(uvw::TimerHandle::Time{0}, uvw::TimerHandle::Time{0});
|
handle->start(uvw::TimerHandle::Time{0}, uvw::TimerHandle::Time{0});
|
||||||
handle->close();
|
handle->close();
|
||||||
|
|||||||
@ -9,14 +9,14 @@ TEST(TTY, Functionalities) {
|
|||||||
|
|
||||||
bool checkWriteEvent = false;
|
bool checkWriteEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::WriteEvent>([&checkWriteEvent](const auto &, auto &hndl){
|
handle->on<uvw::WriteEvent>([&checkWriteEvent](const uvw::WriteEvent &, uvw::TTYHandle &hndl){
|
||||||
ASSERT_FALSE(checkWriteEvent);
|
ASSERT_FALSE(checkWriteEvent);
|
||||||
checkWriteEvent = true;
|
checkWriteEvent = true;
|
||||||
hndl.close();
|
hndl.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
timer->on<uvw::TimerEvent>([handle](const auto &, auto &hndl){
|
timer->on<uvw::TimerEvent>([handle](const uvw::TimerEvent &, uvw::TimerHandle &hndl){
|
||||||
auto data = std::make_unique<char[]>('*');
|
auto data = std::unique_ptr<char[]>(new char[1]{'*'});
|
||||||
handle->write(std::move(data), 1);
|
handle->write(std::move(data), 1);
|
||||||
hndl.close();
|
hndl.close();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include <uvw.hpp>
|
#include <uvw.hpp>
|
||||||
|
|
||||||
|
|
||||||
TEST(Udp, Functionalities) {
|
TEST(UDP, Functionalities) {
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::UDPHandle>();
|
auto handle = loop->resource<uvw::UDPHandle>();
|
||||||
|
|
||||||
@ -21,14 +21,14 @@ TEST(Udp, Functionalities) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Udp, BindRecvStop) {
|
TEST(UDP, BindRecvStop) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::UDPHandle>();
|
auto handle = loop->resource<uvw::UDPHandle>();
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||||
|
|
||||||
handle->bind(address, port);
|
handle->bind(address, port);
|
||||||
handle->recv();
|
handle->recv();
|
||||||
@ -39,7 +39,7 @@ TEST(Udp, BindRecvStop) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Udp, ReadTrySend) {
|
TEST(UDP, ReadTrySend) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ TEST(Udp, ReadTrySend) {
|
|||||||
auto server = loop->resource<uvw::UDPHandle>();
|
auto server = loop->resource<uvw::UDPHandle>();
|
||||||
auto client = loop->resource<uvw::UDPHandle>();
|
auto client = loop->resource<uvw::UDPHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::UDPDataEvent>([&client](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
|
server->once<uvw::UDPDataEvent>([&client](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
|
||||||
client->close();
|
client->close();
|
||||||
@ -70,7 +70,7 @@ TEST(Udp, ReadTrySend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Udp, ReadSend) {
|
TEST(UDP, ReadSend) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
@ -78,8 +78,8 @@ TEST(Udp, ReadSend) {
|
|||||||
auto server = loop->resource<uvw::UDPHandle>();
|
auto server = loop->resource<uvw::UDPHandle>();
|
||||||
auto client = loop->resource<uvw::UDPHandle>();
|
auto client = loop->resource<uvw::UDPHandle>();
|
||||||
|
|
||||||
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||||
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||||
|
|
||||||
server->once<uvw::UDPDataEvent>([](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
|
server->once<uvw::UDPDataEvent>([](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
|
||||||
handle.close();
|
handle.close();
|
||||||
@ -104,14 +104,14 @@ TEST(Udp, ReadSend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(Udp, Sock) {
|
TEST(UDP, Sock) {
|
||||||
const std::string address = std::string{"127.0.0.1"};
|
const std::string address = std::string{"127.0.0.1"};
|
||||||
const unsigned int port = 4242;
|
const unsigned int port = 4242;
|
||||||
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
auto loop = uvw::Loop::getDefault();
|
||||||
auto handle = loop->resource<uvw::UDPHandle>();
|
auto handle = loop->resource<uvw::UDPHandle>();
|
||||||
|
|
||||||
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||||
|
|
||||||
handle->bind(address, port);
|
handle->bind(address, port);
|
||||||
handle->recv();
|
handle->recv();
|
||||||
|
|||||||
@ -71,6 +71,14 @@ TEST(Util, ScopedFlags) {
|
|||||||
ASSERT_TRUE(flags & uvw::Flags<ScopedEnum>::from<ScopedEnum::QUUX>());
|
ASSERT_TRUE(flags & uvw::Flags<ScopedEnum>::from<ScopedEnum::QUUX>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
void guessHandle(T tag, U type) {
|
||||||
|
auto loop = uvw::Loop::getDefault();
|
||||||
|
auto handle = loop->resource<typename decltype(tag)::type>();
|
||||||
|
ASSERT_EQ(uvw::Utilities::guessHandle(handle->category()), type);
|
||||||
|
handle->close();
|
||||||
|
loop->run();
|
||||||
|
};
|
||||||
|
|
||||||
TEST(Util, Utilities) {
|
TEST(Util, Utilities) {
|
||||||
ASSERT_EQ(uvw::PidType{}, uvw::PidType{});
|
ASSERT_EQ(uvw::PidType{}, uvw::PidType{});
|
||||||
@ -98,14 +106,6 @@ TEST(Util, Utilities) {
|
|||||||
ASSERT_EQ(uvw::Utilities::guessHandle(uvw::FileHandle{-1}), uvw::HandleType::UNKNOWN);
|
ASSERT_EQ(uvw::Utilities::guessHandle(uvw::FileHandle{-1}), uvw::HandleType::UNKNOWN);
|
||||||
ASSERT_NE(uvw::Utilities::guessHandle(uvw::StdIN), uvw::HandleType::UNKNOWN);
|
ASSERT_NE(uvw::Utilities::guessHandle(uvw::StdIN), uvw::HandleType::UNKNOWN);
|
||||||
|
|
||||||
auto guessHandle = [](auto tag, auto type) {
|
|
||||||
auto loop = uvw::Loop::getDefault();
|
|
||||||
auto handle = loop->resource<typename decltype(tag)::type>();
|
|
||||||
ASSERT_EQ(uvw::Utilities::guessHandle(handle->category()), type);
|
|
||||||
handle->close();
|
|
||||||
loop->run();
|
|
||||||
};
|
|
||||||
|
|
||||||
guessHandle(tag<uvw::AsyncHandle>{}, uvw::HandleType::ASYNC);
|
guessHandle(tag<uvw::AsyncHandle>{}, uvw::HandleType::ASYNC);
|
||||||
guessHandle(tag<uvw::CheckHandle>{}, uvw::HandleType::CHECK);
|
guessHandle(tag<uvw::CheckHandle>{}, uvw::HandleType::CHECK);
|
||||||
guessHandle(tag<uvw::FsEventHandle>{}, uvw::HandleType::FS_EVENT);
|
guessHandle(tag<uvw::FsEventHandle>{}, uvw::HandleType::FS_EVENT);
|
||||||
@ -113,7 +113,7 @@ TEST(Util, Utilities) {
|
|||||||
guessHandle(tag<uvw::IdleHandle>{}, uvw::HandleType::IDLE);
|
guessHandle(tag<uvw::IdleHandle>{}, uvw::HandleType::IDLE);
|
||||||
guessHandle(tag<uvw::PipeHandle>{}, uvw::HandleType::PIPE);
|
guessHandle(tag<uvw::PipeHandle>{}, uvw::HandleType::PIPE);
|
||||||
guessHandle(tag<uvw::PrepareHandle>{}, uvw::HandleType::PREPARE);
|
guessHandle(tag<uvw::PrepareHandle>{}, uvw::HandleType::PREPARE);
|
||||||
guessHandle(tag<uvw::TcpHandle>{}, uvw::HandleType::TCP);
|
guessHandle(tag<uvw::TCPHandle>{}, uvw::HandleType::TCP);
|
||||||
guessHandle(tag<uvw::TimerHandle>{}, uvw::HandleType::TIMER);
|
guessHandle(tag<uvw::TimerHandle>{}, uvw::HandleType::TIMER);
|
||||||
guessHandle(tag<uvw::UDPHandle>{}, uvw::HandleType::UDP);
|
guessHandle(tag<uvw::UDPHandle>{}, uvw::HandleType::UDP);
|
||||||
guessHandle(tag<uvw::SignalHandle>{}, uvw::HandleType::SIGNAL);
|
guessHandle(tag<uvw::SignalHandle>{}, uvw::HandleType::SIGNAL);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ TEST(Work, RunTask) {
|
|||||||
bool checkWorkEvent = false;
|
bool checkWorkEvent = false;
|
||||||
bool checkTask = false;
|
bool checkTask = false;
|
||||||
|
|
||||||
handle->on<uvw::CheckEvent>([&checkWorkEvent](const auto &, auto &hndl) {
|
handle->on<uvw::CheckEvent>([&checkWorkEvent](const uvw::CheckEvent &, uvw::CheckHandle &hndl) {
|
||||||
if(checkWorkEvent) {
|
if(checkWorkEvent) {
|
||||||
hndl.stop();
|
hndl.stop();
|
||||||
hndl.close();
|
hndl.close();
|
||||||
@ -21,9 +21,9 @@ TEST(Work, RunTask) {
|
|||||||
checkTask = true;
|
checkTask = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
req->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
|
req->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::WorkReq &) { FAIL(); });
|
||||||
|
|
||||||
req->on<uvw::WorkEvent>([&checkWorkEvent](const auto &, auto &) {
|
req->on<uvw::WorkEvent>([&checkWorkEvent](const uvw::WorkEvent &, uvw::WorkReq &) {
|
||||||
ASSERT_FALSE(checkWorkEvent);
|
ASSERT_FALSE(checkWorkEvent);
|
||||||
checkWorkEvent = true;
|
checkWorkEvent = true;
|
||||||
});
|
});
|
||||||
@ -42,7 +42,7 @@ TEST(Work, Cancellation) {
|
|||||||
|
|
||||||
bool checkErrorEvent = false;
|
bool checkErrorEvent = false;
|
||||||
|
|
||||||
handle->on<uvw::TimerEvent>([](const auto &, auto &hndl) {
|
handle->on<uvw::TimerEvent>([](const uvw::TimerEvent &, uvw::TimerHandle &hndl) {
|
||||||
hndl.stop();
|
hndl.stop();
|
||||||
hndl.close();
|
hndl.close();
|
||||||
});
|
});
|
||||||
@ -50,8 +50,8 @@ TEST(Work, Cancellation) {
|
|||||||
for(auto i = 0; i < 5 /* default uv thread pool size + 1 */; ++i) {
|
for(auto i = 0; i < 5 /* default uv thread pool size + 1 */; ++i) {
|
||||||
auto req = loop->resource<uvw::WorkReq>([]() {});
|
auto req = loop->resource<uvw::WorkReq>([]() {});
|
||||||
|
|
||||||
req->on<uvw::WorkEvent>([](const auto &, auto &) {});
|
req->on<uvw::WorkEvent>([](const uvw::WorkEvent &, uvw::WorkReq &) {});
|
||||||
req->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &) { checkErrorEvent = true; });
|
req->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::WorkReq &) { checkErrorEvent = true; });
|
||||||
|
|
||||||
req->queue();
|
req->queue();
|
||||||
req->cancel();
|
req->cancel();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user