Compare commits

...

2 Commits
main ... cpp11

Author SHA1 Message Date
Fei Chong
68ed09d929 Update C++11 version: renaming Tcp -> TCP
* Migrate the project from C++14 to C++11.
All tests passed.

* Remove CONSTEXPR_SPECIFIER macro cause fall back to const in c++11.

* Remove C++14 code in test/main.cpp
Change sample code from C++14 to C++11 in README.md

* Fixed warnings in old-version gcc since C++11 doesn't support empty braced initialization well.

* Fixed warnings in old-version gcc since C++11 doesn't support empty braced initialization well.

* renaming

* fixed conan cpp

* fixed appveyor configuration

* skip tests from libuv

* Add line-feed to tcp.hpp:21
2018-11-08 10:26:56 +01:00
Fei Chong
1c930cdcb5 Migrate the project from C++14 to C++11. (#138)
* Migrate the project from C++14 to C++11.
All tests passed.

* Remove CONSTEXPR_SPECIFIER macro cause fall back to const in c++11.

* Remove C++14 code in test/main.cpp
Change sample code from C++14 to C++11 in README.md

* Fixed warnings in old-version gcc since C++11 doesn't support empty braced initialization well.
2018-11-05 14:04:28 +01:00
43 changed files with 460 additions and 434 deletions

View File

@ -4,13 +4,13 @@
#include <memory>
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) {
std::shared_ptr<uvw::TcpHandle> client = srv.loop().resource<uvw::TcpHandle>();
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
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(); });
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(); });
srv.accept(*client);
client->read();
@ -21,11 +21,11 @@ void listen(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' });
tcp.write(std::move(dataWrite), 2);
tcp.close();
@ -45,4 +45,4 @@ int main() {
std::cout << "Done!\n";
return EXIT_SUCCESS;
}
}

View File

@ -30,7 +30,7 @@ message("* ${PROJECT_NAME} v${PROJECT_VERSION} (${CMAKE_BUILD_TYPE})")
message("* Copyright (c) 2016-2018 ${PROJECT_AUTHOR} <${PROJECT_AUTHOR_EMAIL}>")
message("*")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT MSVC)
@ -67,7 +67,8 @@ if(DOXYGEN_FOUND)
endif()
if(BUILD_TESTING)
enable_testing()
set(BUILD_TESTING OFF)
set(GOOGLETEST_DEPS_DIR ${PROJECT_DEPS_DIR}/googletest)
set(LIBUV_DEPS_DIR ${PROJECT_DEPS_DIR}/libuv)
@ -83,6 +84,9 @@ if(BUILD_TESTING)
add_subdirectory(${LIBUV_DEPS_DIR})
include_directories(${LIBUV_DEPS_DIR}/include)
set(BUILD_TESTING ON)
enable_testing()
add_subdirectory(test)
endif()

View File

@ -30,14 +30,14 @@ As an example, a *handle* should be initialized before any other operation and c
#include <memory>
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) {
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(); });
tcp->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();
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);
client->read();
});
@ -47,11 +47,11 @@ void listen(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' });
tcp.write(std::move(dataWrite), 2);
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:
* 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).
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:
```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/>
@ -210,7 +210,7 @@ Users should check if pointers have been correctly initialized: in case of error
Another way to create a resource is:
```cpp
auto tcp = TcpHandle::create(loop);
auto tcp = TCPHandle::create(loop);
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.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/>
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
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) {
std::shared_ptr<uvw::TcpHandle> client = srv.loop().resource<uvw::TcpHandle>();
client->once<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); });
client->on<uvw::DataEvent>([](const uvw::DataEvent &, uvw::TcpHandle &) { /* data received */ });
tcp->on<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &srv) {
std::shared_ptr<uvw::TCPHandle> client = srv.loop().resource<uvw::TCPHandle>();
client->once<uvw::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); });
client->on<uvw::DataEvent>([](const uvw::DataEvent &, uvw::TCPHandle &) { /* data received */ });
srv.accept(*client);
client->read();
});
@ -299,7 +299,7 @@ tcp->bind("127.0.0.1", 4242);
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.
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
auto loop = uvw::Loop::getDefault();
auto tcp = loop.resource<uvw::TcpHandle>();
auto tcp = loop.resource<uvw::TCPHandle>();
uv_loop_t *raw = loop->raw();
uv_tcp_t *handle = tcp->raw();

View File

@ -14,7 +14,7 @@ configuration:
before_build:
- cd %BUILD_DIR%
- cmake .. -G"Visual Studio 15 2017"
- cmake .. -DBUILD_TESTING=ON -G"Visual Studio 15 2017"
build:
parallel: true

View File

@ -89,7 +89,7 @@ class GetAddrInfoReq final: public Request<GetAddrInfoReq, uv_getaddrinfo_t> {
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 err = uv_getaddrinfo(parent(), req, nullptr, node, service, hints);
auto data = std::unique_ptr<addrinfo, void(*)(addrinfo *)>{req->addrinfo, [](addrinfo *addr){ uv_freeaddrinfo(addr); }};

View File

@ -21,7 +21,7 @@ namespace uvw {
* Custom wrapper around error constants of `libuv`.
*/
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
: ec{static_cast<int>(val)}
{}
@ -99,7 +99,7 @@ class Emitter {
using Connection = typename ListenerList::iterator;
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) &&
std::all_of(onL.cbegin(), onL.cend(), pred);
@ -107,7 +107,7 @@ class Emitter {
void clear() noexcept override {
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(onL.begin(), onL.end(), func);
} else {
@ -117,18 +117,18 @@ class Emitter {
}
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) {
return onL.emplace(onL.cend(), false, std::move(f));
return onL.emplace(onL.end(), false, std::move(f));
}
void erase(Connection conn) noexcept {
conn->first = true;
if(!publishing) {
auto pred = [](auto &&element){ return element.first; };
auto pred = [](const Element &element){ return element.first; };
onceL.remove_if(pred);
onL.remove_if(pred);
}
@ -138,7 +138,7 @@ class Emitter {
ListenerList currentL;
onceL.swap(currentL);
auto func = [&event, &ref](auto &&element) {
auto func = [&event, &ref](Element &element) {
return element.first ? void() : element.second(event, ref);
};
@ -149,7 +149,7 @@ class Emitter {
publishing = false;
onL.remove_if([](auto &&element){ return element.first; });
onL.remove_if([](const Element &element){ return element.first; });
}
private:
@ -178,7 +178,7 @@ class Emitter {
}
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]);
@ -283,7 +283,7 @@ public:
*/
void clear() noexcept {
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 {
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:

View File

@ -17,7 +17,7 @@ namespace uvw {
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,
CUSTOM = UV_FS_CUSTOM,
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,
FILE = UV_DIRENT_FILE,
DIR = UV_DIRENT_DIR,
@ -220,7 +220,7 @@ struct FsEvent<details::UVFsType::SENDFILE> {
template<>
struct FsEvent<details::UVFsType::STAT> {
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. */
@ -237,7 +237,7 @@ struct FsEvent<details::UVFsType::STAT> {
template<>
struct FsEvent<details::UVFsType::FSTAT> {
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. */
@ -254,7 +254,7 @@ struct FsEvent<details::UVFsType::FSTAT> {
template<>
struct FsEvent<details::UVFsType::LSTAT> {
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. */
@ -809,7 +809,7 @@ public:
private:
std::unique_ptr<char[]> data{nullptr};
uv_buf_t buffer{};
uv_buf_t buffer;
uv_file file{BAD_FD};
};

View File

@ -16,14 +16,14 @@ namespace uvw {
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,
STAT = UV_FS_EVENT_STAT,
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,
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) {
FsEventHandle &fsEvent = *(static_cast<FsEventHandle*>(handle->data));
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:

View File

@ -21,7 +21,7 @@ namespace uvw {
*/
struct FsPollEvent {
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. */

View File

@ -99,7 +99,7 @@ public:
*
* * An AsyncHandle handle is always active and cannot be deactivated,
* 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
* I/O, like reading, writing, connecting, accepting new connections, etc.
* * 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
* socket.<br/>
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
* 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.
@ -200,8 +200,8 @@ public:
*
* Sets the size of the send buffer that the operating system uses for the
* socket.<br/>
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
* Note that Linux will set double the size.
*
* @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
* the socket.<br/>
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
* 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.
@ -232,8 +232,8 @@ public:
*
* Sets the size of the receive buffer that the operating system uses for
* the socket.<br/>
* This function works for TcpHandle, PipeHandle and UDPHandle handles on
* Unix and for TcpHandle and UDPHandle handles on Windows.<br/>
* This function works for TCPHandle, PipeHandle and UDPHandle handles on
* Unix and for TCPHandle and UDPHandle handles on Windows.<br/>
* Note that Linux will set double the size.
*
* @return True in case of success, false otherwise.
@ -247,7 +247,7 @@ public:
*
* Supported handles:
*
* * TcpHandle
* * TCPHandle
* * PipeHandle
* * TTYHandle
* * UDPHandle

View File

@ -21,12 +21,12 @@ namespace uvw {
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
};
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,
ONCE = UV_RUN_ONCE,
NOWAIT = UV_RUN_NOWAIT
@ -74,7 +74,7 @@ struct BaseHandle {
*
* * An AsyncHandle handle is always active and cannot be deactivated,
* 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
* I/O, like reading, writing, connecting, accepting new connections, etc.
* * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it
@ -230,7 +230,7 @@ public:
*/
template<typename... 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)...);
if(err) { publish(ErrorEvent{err}); }
}
@ -246,7 +246,7 @@ public:
* @return A pointer to the newly created resource.
*/
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) {
auto ptr = R::create(shared_from_this(), std::forward<Args>(args)...);
ptr = ptr->init() ? ptr : nullptr;
@ -264,7 +264,7 @@ public:
* @return A pointer to the newly created resource.
*/
template<typename R, typename... Args>
std::enable_if_t<not std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>
typename std::enable_if<not std::is_base_of<BaseHandle, R>::value, std::shared_ptr<R>>::type
resource(Args&&... args) {
return R::create(shared_from_this(), std::forward<Args>(args)...);
}
@ -302,7 +302,7 @@ public:
*/
template<Mode mode = Mode::DEFAULT>
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);
return (uv_run(loop.get(), uvrm) == 0);
}

View File

@ -18,7 +18,7 @@ namespace uvw {
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,
WRITABLE = UV_WRITABLE
};
@ -90,13 +90,17 @@ public:
* @param name A valid domain socket or named pipe.
*/
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);
};
auto connect = loop().resource<details::ConnectReq>();
connect->once<ErrorEvent>(listener);
connect->once<ConnectEvent>(listener);
connect->once<ErrorEvent>(errorEventListener);
connect->once<ConnectEvent>(connectEventListener);
connect->connect(&uv_pipe_connect, get(), name.data());
}

View File

@ -15,7 +15,7 @@ namespace uvw {
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,
WRITABLE = UV_WRITABLE,
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) {
PollHandle &poll = *(static_cast<PollHandle*>(handle->data));
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:

View File

@ -19,7 +19,7 @@ namespace uvw {
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,
SETGID = UV_PROCESS_SETGID,
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,
CREATE_PIPE = UV_CREATE_PIPE,
INHERIT_FD = UV_INHERIT_FD,
@ -144,13 +144,13 @@ public:
poStdio.reserve(poFdStdio.size() + poStreamStdio.size());
poStdio.insert(poStdio.begin(), poFdStdio.cbegin(), poFdStdio.cend());
poStdio.insert(poStdio.end(), poStreamStdio.cbegin(), poStreamStdio.cend());
po.stdio_count = static_cast<decltype(po.stdio_count)>(poStdio.size());
po.stdio = poStdio.data();
// fake initialization so as to have leak invoked
// 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);
}
@ -269,7 +269,7 @@ public:
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;
});

View File

@ -14,7 +14,7 @@ namespace uvw {
template<typename T, typename U>
class Request: public Resource<T, U> {
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();
ptr->reset();
return ptr;
@ -29,7 +29,7 @@ protected:
template<typename F, typename... 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)...);
if(err) { Emitter<T>::publish(ErrorEvent{err}); }
else { this->leak(); }
@ -37,7 +37,7 @@ protected:
template<typename F, typename... 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)...);
this->leak();
}

View File

@ -20,7 +20,7 @@ class Resource: public UnderlyingType<T, U>, public Emitter<T>, public std::enab
protected:
using ConstructorAccess = typename UnderlyingType<T, U>::ConstructorAccess;
auto parent() const noexcept {
auto parent() const noexcept -> uv_loop_t * {
return this->loop().loop.get();
}

View File

@ -99,7 +99,7 @@ public:
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)},
data{std::move(dt)},
buf{uv_buf_init(data.get(), len)}
buf(uv_buf_init(data.get(), len))
{}
void write(uv_stream_t *handle) {
@ -124,7 +124,7 @@ private:
*
* Stream handles provide an abstraction of a duplex communication channel.
* StreamHandle is an intermediate type, `uvw` provides three stream
* implementations: TcpHandle, PipeHandle and TTYHandle.
* implementations: TCPHandle, PipeHandle and TTYHandle.
*/
template<typename T, typename U>
class StreamHandle: public Handle<T, U> {
@ -174,13 +174,17 @@ public:
* A ShutdownEvent event will be emitted after shutdown is complete.
*/
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);
};
auto shutdown = this->loop().template resource<details::ShutdownReq>();
shutdown->template once<ErrorEvent>(listener);
shutdown->template once<ShutdownEvent>(listener);
shutdown->template once<ErrorEvent>(errorEventListener);
shutdown->template once<ShutdownEvent>(shutdownEventListener);
shutdown->shutdown(this->template get<uv_stream_t>());
}
@ -260,12 +264,16 @@ public:
data.release(), [](char *ptr) { delete[] ptr; }
}, 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);
};
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>());
}
@ -287,12 +295,17 @@ public:
data, [](char *) {}
}, 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);
};
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>());
}
@ -301,7 +314,7 @@ public:
*
* 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
* assumed to be servers.
*
@ -322,12 +335,16 @@ public:
data.release(), [](char *ptr) { delete[] ptr; }
}, 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);
};
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>(), send.template get<uv_stream_t>());
}
@ -336,7 +353,7 @@ public:
*
* 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
* assumed to be servers.
*
@ -357,12 +374,16 @@ public:
data, [](char *) {}
}, 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);
};
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>(), send.template get<uv_stream_t>());
}

View File

@ -18,7 +18,7 @@ namespace uvw {
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
};
@ -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/>
* By default, _IPv4_ is used as a template parameter. The handle already
* 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
* 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)
* for further details.
*/
class TcpHandle final: public StreamHandle<TcpHandle, uv_tcp_t> {
class TCPHandle final: public StreamHandle<TCPHandle, uv_tcp_t> {
public:
using Time = std::chrono::duration<unsigned int>;
using Bind = details::UVTcpFlags;
using Bind = details::UVTCPFlags;
using IPv4 = uvw::IPv4;
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}
{}
@ -123,7 +123,7 @@ public:
*
* 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.
*
* @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
@ -143,7 +143,7 @@ public:
*
* 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.
*
* @param ip The address to which to bind.
@ -167,7 +167,7 @@ public:
*
* 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.
*
* @param addr A valid instance of Addr.
@ -210,13 +210,18 @@ public:
* @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
*/
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);
};
auto req = loop().resource<details::ConnectReq>();
req->once<ErrorEvent>(listener);
req->once<ConnectEvent>(listener);
req->once<ErrorEvent>(errorEventListener);
req->once<ConnectEvent>(connectEventListener);
req->connect(&uv_tcp_connect, get(), &addr);
}

View File

@ -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,
RAW = UV_TTY_MODE_RAW,
IO = UV_TTY_MODE_IO
@ -50,7 +50,7 @@ enum class UVTTYModeT: std::underlying_type_t<uv_tty_mode_t> {
* for further details.
*/
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;
auto shared = weak.lock();
if(!shared) { weak = shared = std::make_shared<details::ResetModeMemo>(); }
@ -92,7 +92,7 @@ public:
* @return True in case of success, false otherwise.
*/
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)));
}
/**

View File

@ -32,7 +32,7 @@ struct SendEvent {};
*/
struct UDPDataEvent {
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. */
@ -45,13 +45,13 @@ struct UDPDataEvent {
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,
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,
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)
: Request<SendReq, uv_udp_send_t>{ca, std::move(loop)},
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) {
@ -121,7 +121,7 @@ class UDPHandle final: public Handle<UDPHandle, uv_udp_t> {
public:
using Membership = details::UVMembership;
using Bind = details::UVUdpFlags;
using Bind = details::UVUDPFlags;
using IPv4 = uvw::IPv4;
using IPv6 = uvw::IPv6;
@ -318,12 +318,16 @@ public:
data.release(), [](char *ptr) { delete[] ptr; }
}, 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);
};
req->once<ErrorEvent>(listener);
req->once<SendEvent>(listener);
req->once<ErrorEvent>(errorEventListener);
req->once<SendEvent>(sendEventListener);
req->send(get(), &addr);
}
@ -397,12 +401,16 @@ public:
data, [](char *) {}
}, 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);
};
req->once<ErrorEvent>(listener);
req->once<SendEvent>(listener);
req->once<ErrorEvent>(errorEventListener);
req->once<SendEvent>(sendEventListener);
req->send(get(), &addr);
}

View File

@ -23,39 +23,39 @@ class UnderlyingType {
protected:
struct ConstructorAccess { explicit ConstructorAccess(int) {} };
auto get() noexcept {
auto get() noexcept -> U * {
return &resource;
}
auto get() const noexcept {
auto get() const noexcept -> const U * {
return &resource;
}
template<typename R>
auto get() noexcept {
auto get() noexcept -> R * {
static_assert(not std::is_same<R, U>::value, "!");
return reinterpret_cast<R *>(&resource);
}
template<typename R, typename... P>
auto get(UnderlyingType<P...> &other) noexcept {
auto get(UnderlyingType<P...> &other) noexcept -> R * {
return reinterpret_cast<R *>(&other.resource);
}
template<typename R>
auto get() const noexcept {
auto get() const noexcept -> const R * {
static_assert(not std::is_same<R, U>::value, "!");
return reinterpret_cast<const R *>(&resource);
}
template<typename R, typename... P>
auto get(const UnderlyingType<P...> &other) const noexcept {
auto get(const UnderlyingType<P...> &other) const noexcept -> const R * {
return reinterpret_cast<const R *>(&other.resource);
}
public:
explicit UnderlyingType(ConstructorAccess, std::shared_ptr<Loop> ref) noexcept
: pLoop{std::move(ref)}, resource{}
: pLoop{std::move(ref)}, resource()
{}
UnderlyingType(const UnderlyingType &) = delete;

View File

@ -13,21 +13,13 @@
#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 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,
ASYNC = UV_ASYNC,
CHECK = UV_CHECK,
@ -88,7 +80,7 @@ bool operator==(UVTypeWrapper<T> lhs, UVTypeWrapper<T> rhs) {
*/
template<typename E>
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); }
@ -100,7 +92,7 @@ public:
* @return A valid instance of Flags instantiated from values `V`.
*/
template<E... V>
static CONSTEXPR_SPECIFIER Flags<E> from() {
static Flags<E> from() {
auto flags = Flags<E>{};
int _[] = { 0, (flags = flags | V, 0)... };
return void(_), flags;
@ -129,12 +121,12 @@ public:
~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;
return *this;
}
CONSTEXPR_SPECIFIER Flags & operator=(Flags &&f) noexcept {
Flags & operator=(Flags &&f) noexcept {
flags = std::move(f.flags);
return *this;
}
@ -237,7 +229,7 @@ struct Passwd {
* @brief Gets the 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){});
}
@ -245,7 +237,7 @@ struct Passwd {
* @brief Gets the gid.
* @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){});
}
@ -351,7 +343,7 @@ struct IpTraits<IPv4> {
using NameFuncType = int(*)(const Type *, char *, std::size_t);
static constexpr AddrFuncType addrFunc = &uv_ip4_addr;
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);
static constexpr AddrFuncType addrFunc = &uv_ip6_addr;
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 {
sockaddr_storage ssto;
int len = sizeof(ssto);
Addr addr{};
Addr addr;
int err = std::forward<F>(f)(handle, reinterpret_cast<sockaddr *>(&ssto), &len);
@ -671,7 +663,7 @@ struct Utilities {
int 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 });
});
@ -696,7 +688,7 @@ struct Utilities {
int count{0};
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.name = iface.name;
@ -853,7 +845,7 @@ struct Utilities {
static RUsage rusage() noexcept {
RUsage ru;
auto err = uv_getrusage(&ru);
return err ? RUsage{} : ru;
return err ? RUsage() : ru;
}
/**

View File

@ -6,22 +6,23 @@
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;
});
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::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;
});
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;
ptr->close();
});
@ -34,12 +35,12 @@ void listen(uvw::Loop &loop) {
uvw::Addr remote = client->peer();
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 << "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;
int count = 0;
handle.loop().walk([&count](uvw::BaseHandle &) { ++count; });
@ -50,7 +51,7 @@ void listen(uvw::Loop &loop) {
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;
});
@ -60,18 +61,18 @@ void listen(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;
});
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;
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;
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);
});
tcp->once<uvw::CloseEvent>([](const uvw::CloseEvent &, uvw::TcpHandle &) {
tcp->once<uvw::CloseEvent>([](const uvw::CloseEvent &, uvw::TCPHandle &) {
std::cout << "close" << std::endl;
});

View File

@ -8,9 +8,9 @@ TEST(Async, Send) {
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);
checkAsyncEvent = true;
hndl.close();
@ -32,9 +32,8 @@ TEST(Async, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::AsyncHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::AsyncEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::AsyncHandle &) { FAIL(); });
handle->on<uvw::AsyncEvent>([](const uvw::AsyncEvent &, uvw::AsyncHandle &) { FAIL(); });
handle->send();
handle->close();

View File

@ -8,9 +8,9 @@ TEST(Check, StartAndStop) {
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);
checkCheckEvent = true;
hndl.stop();
@ -33,9 +33,8 @@ TEST(Check, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::CheckHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::CheckEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::CheckHandle &) { FAIL(); });
handle->on<uvw::CheckEvent>([](const uvw::CheckEvent &, uvw::CheckHandle &) { FAIL(); });
handle->start();
handle->close();

View File

@ -8,9 +8,9 @@ TEST(GetAddrInfo, GetNodeAddrInfo) {
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);
checkAddrInfoEvent = true;
});
@ -40,7 +40,7 @@ TEST(GetAddrInfo, GetServiceAddrInfo) {
bool checkErrorEvent = false;
request->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &) {
request->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::GetAddrInfoReq &) {
ASSERT_FALSE(checkErrorEvent);
checkErrorEvent = true;
});
@ -69,9 +69,9 @@ TEST(GetAddrInfo, GetAddrInfo) {
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);
checkAddrInfoEvent = true;
});
@ -103,12 +103,12 @@ TEST(GetNameInfo, GetNameInfo) {
bool checkErrorEvent = 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);
checkErrorEvent = true;
});
okRequest->on<uvw::NameInfoEvent>([&checkNameInfoEvent](const auto &, auto &) {
okRequest->on<uvw::NameInfoEvent>([&checkNameInfoEvent](const uvw::NameInfoEvent &, uvw::GetNameInfoReq &) {
ASSERT_FALSE(checkNameInfoEvent);
checkNameInfoEvent = true;
});

View File

@ -11,7 +11,7 @@ struct TestEmitter: uvw::Emitter<TestEmitter> {
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};
@ -30,7 +30,7 @@ TEST(Emitter, EmptyAndClear) {
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<uvw::ErrorEvent>());
@ -48,8 +48,8 @@ TEST(Emitter, EmptyAndClear) {
ASSERT_TRUE(emitter.empty<uvw::ErrorEvent>());
ASSERT_TRUE(emitter.empty<FakeEvent>());
emitter.on<uvw::ErrorEvent>([](const auto &, auto &){});
emitter.on<FakeEvent>([](const auto &, auto &){});
emitter.on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, TestEmitter &){});
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
ASSERT_FALSE(emitter.empty());
ASSERT_FALSE(emitter.empty<uvw::ErrorEvent>());
@ -66,7 +66,7 @@ TEST(Emitter, EmptyAndClear) {
TEST(Emitter, On) {
TestEmitter emitter{};
emitter.on<FakeEvent>([](const auto &, auto &){});
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
ASSERT_FALSE(emitter.empty());
ASSERT_FALSE(emitter.empty<FakeEvent>());
@ -81,7 +81,7 @@ TEST(Emitter, On) {
TEST(Emitter, Once) {
TestEmitter emitter{};
emitter.once<FakeEvent>([](const auto &, auto &){});
emitter.once<FakeEvent>([](const FakeEvent &, TestEmitter &){});
ASSERT_FALSE(emitter.empty());
ASSERT_FALSE(emitter.empty<FakeEvent>());
@ -96,7 +96,7 @@ TEST(Emitter, Once) {
TEST(Emitter, OnceAndErase) {
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<FakeEvent>());
@ -111,7 +111,7 @@ TEST(Emitter, OnceAndErase) {
TEST(Emitter, OnAndErase) {
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<FakeEvent>());
@ -126,8 +126,8 @@ TEST(Emitter, OnAndErase) {
TEST(Emitter, CallbackClear) {
TestEmitter emitter{};
emitter.on<FakeEvent>([](const auto &, auto &ref) {
ref.template on<FakeEvent>([](const auto &, auto &){});
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &ref) {
ref.template on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
ref.clear();
});
@ -139,9 +139,9 @@ TEST(Emitter, CallbackClear) {
ASSERT_TRUE(emitter.empty());
ASSERT_TRUE(emitter.empty<FakeEvent>());
emitter.on<FakeEvent>([](const auto &, auto &ref) {
emitter.on<FakeEvent>([](const FakeEvent &, TestEmitter &ref) {
ref.clear();
ref.template on<FakeEvent>([](const auto &, auto &){});
ref.template on<FakeEvent>([](const FakeEvent &, TestEmitter &){});
});
ASSERT_FALSE(emitter.empty());

View File

@ -18,12 +18,12 @@ TEST(FileReq, OpenAndCloseErr) {
bool checkFileOpenErrorEvent = 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);
checkFileOpenErrorEvent = true;
});
closeReq->on<uvw::ErrorEvent>([&checkFileCloseErrorEvent](const auto &, auto &) {
closeReq->on<uvw::ErrorEvent>([&checkFileCloseErrorEvent](const uvw::ErrorEvent &, uvw::FileReq &) {
ASSERT_FALSE(checkFileCloseErrorEvent);
checkFileCloseErrorEvent = true;
});
@ -61,14 +61,14 @@ TEST(FileReq, OpenAndClose) {
bool checkFileOpenEvent = 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);
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);
checkFileOpenEvent = true;
req.close();
@ -106,22 +106,22 @@ TEST(FileReq, RWChecked) {
bool checkFileWriteEvent = 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_EQ(event.data[0], 42);
checkFileReadEvent = true;
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);
checkFileWriteEvent = true;
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);
});
@ -145,22 +145,22 @@ TEST(FileReq, RWUnchecked) {
bool checkFileWriteEvent = 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_EQ(event.data[0], 42);
checkFileReadEvent = true;
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);
checkFileWriteEvent = true;
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);
});
@ -207,15 +207,15 @@ TEST(FileReq, Stat) {
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);
checkFileStatEvent = true;
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();
});
@ -254,15 +254,15 @@ TEST(FileReq, Sync) {
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);
checkFileSyncEvent = true;
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();
});
@ -297,15 +297,15 @@ TEST(FileReq, Datasync) {
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);
checkFileDatasyncEvent = true;
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();
});
@ -340,15 +340,15 @@ TEST(FileReq, Truncate) {
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);
checkFileTruncateEvent = true;
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);
});
@ -385,21 +385,21 @@ TEST(FileReq, SendFile) {
bool checkFileSendFileEvent = false;
dstReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
srcReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
dstReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FileReq &) { 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->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);
checkFileSendFileEvent = true;
dstReq->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>();
dstReq->open(dstFilename, flags, 0644);
});
@ -442,15 +442,15 @@ TEST(FileReq, Chmod) {
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);
checkFileChmodEvent = true;
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);
});
@ -485,15 +485,15 @@ TEST(FileReq, Utime) {
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);
checkFileUtimeEvent = true;
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 epoch = now.time_since_epoch();
auto value = std::chrono::duration_cast<std::chrono::seconds>(epoch);
@ -537,21 +537,21 @@ TEST(FileReq, Chown) {
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);
checkFileChownEvent = true;
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 gid = static_cast<uvw::Uid>(event.stat.st_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();
});

View File

@ -11,10 +11,10 @@ TEST(FsEvent, Functionalities) {
bool checkFsEventEvent = false;
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsEventHandle &) { 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_EQ(std::string{event.filename}, std::string{"test.file"});
checkFsEventEvent = true;
@ -23,11 +23,11 @@ TEST(FsEvent, Functionalities) {
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();
});
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);
});

View File

@ -11,10 +11,10 @@ TEST(FsPoll, Functionalities) {
bool checkFsPollEvent = false;
handle->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
request->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsPollHandle &) { 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);
checkFsPollEvent = true;
hndl.stop();
@ -22,7 +22,7 @@ TEST(FsPoll, Functionalities) {
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();
});

View File

@ -17,14 +17,14 @@ TEST(FsReq, MkdirAndRmdir) {
bool checkFsMkdirEvent = 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);
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);
checkFsMkdirEvent = true;
req.rmdir(dirname);
@ -61,14 +61,14 @@ TEST(FsReq, MkdtempAndRmdir) {
bool checkFsMkdtempEvent = 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);
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_NE(event.path, nullptr);
checkFsMkdtempEvent = true;
@ -121,19 +121,19 @@ TEST(FsReq, Stat) {
bool checkFsStatEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
});
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();
});
@ -173,19 +173,19 @@ TEST(FsReq, Lstat) {
bool checkFsLstatEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
});
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();
});
@ -226,19 +226,19 @@ TEST(FsReq, Rename) {
bool checkFsRenameEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
});
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();
});
@ -286,19 +286,19 @@ TEST(FsReq, Access) {
bool checkFsAccessEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
});
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();
});
@ -335,19 +335,19 @@ TEST(FsReq, Chmod) {
bool checkFsChmodEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
});
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();
});
@ -384,22 +384,22 @@ TEST(FsReq, Utime) {
bool checkFsUtimeEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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 epoch = now.time_since_epoch();
auto value = std::chrono::duration_cast<std::chrono::seconds>(epoch);
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();
});
@ -443,25 +443,25 @@ TEST(FsReq, LinkAndUnlink) {
bool checkFsLinkEvent = false;
bool checkFsUnlinkEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
checkFsLinkEvent = true;
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);
});
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();
});
@ -503,25 +503,25 @@ TEST(FsReq, SymlinkAndUnlink) {
bool checkFsLinkEvent = false;
bool checkFsUnlinkEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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);
checkFsLinkEvent = true;
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);
});
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();
});
@ -562,24 +562,24 @@ TEST(FsReq, Readlink) {
bool checkFsReadlinkEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
checkFsReadlinkEvent = true;
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);
});
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);
});
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();
});
@ -622,20 +622,20 @@ TEST(FsReq, Realpath) {
bool checkFsRealpathEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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_NE(event.path, nullptr);
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);
});
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();
});
@ -676,25 +676,25 @@ TEST(FsReq, Chown) {
bool checkFsChownEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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 gid = static_cast<uvw::Uid>(event.stat.st_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);
});
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();
});
@ -737,25 +737,25 @@ TEST(FsReq, Lchown) {
bool checkFsLChownEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::FsReq &) { 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);
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 gid = static_cast<uvw::Uid>(event.stat.st_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);
});
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();
});

View File

@ -9,7 +9,7 @@ struct FakeHandle: uvw::Handle<FakeHandle, fake_handle_t> {
using Handle::Handle;
template<typename... Args>
bool init(Args&&...) { return initialize([](auto...){ return true; }); }
bool init(Args&&...) { return initialize([](uv_loop_t*, fake_handle_t*){ return true; }); }
};

View File

@ -8,9 +8,9 @@ TEST(Idle, StartAndStop) {
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);
checkIdleEvent = true;
hndl.stop();
@ -33,9 +33,8 @@ TEST(Idle, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::IdleHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::IdleEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::IdleHandle &) { FAIL(); });
handle->on<uvw::IdleEvent>([](const uvw::IdleEvent &, uvw::IdleHandle &) { FAIL(); });
handle->start();
handle->close();

View File

@ -21,11 +21,9 @@ TEST(Loop, Functionalities) {
auto handle = loop->resource<uvw::PrepareHandle>();
auto req = loop->resource<uvw::WorkReq>([]{});
auto err = [](const auto &, auto &) { FAIL(); };
loop->on<uvw::ErrorEvent>(err);
req->on<uvw::ErrorEvent>(err);
handle->on<uvw::ErrorEvent>(err);
loop->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::Loop &) { FAIL(); });
req->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::WorkReq &) { FAIL(); });
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PrepareHandle &) { FAIL(); });
ASSERT_TRUE(static_cast<bool>(handle));
ASSERT_TRUE(static_cast<bool>(req));
@ -39,7 +37,7 @@ TEST(Loop, Functionalities) {
ASSERT_FALSE(loop->timeout().first);
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 &) {
static bool trigger = true;
ASSERT_TRUE(trigger);

View File

@ -9,8 +9,8 @@ TEST(Pipe, ReadWrite) {
auto server = loop->resource<uvw::PipeHandle>();
auto client = loop->resource<uvw::PipeHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
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 client = loop->resource<uvw::PipeHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
server->once<uvw::ListenEvent>([&sockname](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
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 client = loop->resource<uvw::PipeHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PipeHandle &) { FAIL(); });
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::PipeHandle &handle) {
std::shared_ptr<uvw::PipeHandle> socket = handle.loop().resource<uvw::PipeHandle>();

View File

@ -8,9 +8,9 @@ TEST(Prepare, StartAndStop) {
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);
checkPrepareEvent = true;
hndl.stop();
@ -33,9 +33,8 @@ TEST(Prepare, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::PrepareHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::PrepareEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::PrepareHandle &) { FAIL(); });
handle->on<uvw::PrepareEvent>([](const uvw::PrepareEvent &, uvw::PrepareHandle &) { FAIL(); });
handle->start();
handle->close();

View File

@ -6,9 +6,8 @@ TEST(Signal, Start) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::SignalHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::CheckEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::SignalHandle &) { FAIL(); });
handle->on<uvw::CheckEvent>([](const uvw::CheckEvent &, uvw::SignalHandle &) { FAIL(); });
handle->start(2);
@ -27,9 +26,8 @@ TEST(Signal, OneShot) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::SignalHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::CheckEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::SignalHandle &) { FAIL(); });
handle->on<uvw::CheckEvent>([](const uvw::CheckEvent &, uvw::SignalHandle &) { FAIL(); });
handle->oneShot(2);

View File

@ -2,12 +2,12 @@
#include <uvw.hpp>
TEST(Tcp, Functionalities) {
TEST(TCP, Functionalities) {
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->keepAlive(true, uvw::TcpHandle::Time{128}));
ASSERT_TRUE(handle->keepAlive(true, uvw::TCPHandle::Time{128}));
ASSERT_TRUE(handle->simultaneousAccepts());
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 unsigned int port = 4242;
auto loop = uvw::Loop::getDefault();
auto server = loop->resource<uvw::TcpHandle>();
auto client = loop->resource<uvw::TcpHandle>();
auto server = loop->resource<uvw::TCPHandle>();
auto client = loop->resource<uvw::TCPHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &handle) {
std::shared_ptr<uvw::TcpHandle> socket = handle.loop().resource<uvw::TcpHandle>();
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &handle) {
std::shared_ptr<uvw::TCPHandle> socket = handle.loop().resource<uvw::TCPHandle>();
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::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); });
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::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); });
handle.accept(*socket);
socket->read();
});
client->once<uvw::WriteEvent>([](const uvw::WriteEvent &, uvw::TcpHandle &handle) {
client->once<uvw::WriteEvent>([](const uvw::WriteEvent &, uvw::TCPHandle &handle) {
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.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 unsigned int port = 4242;
auto loop = uvw::Loop::getDefault();
auto server = loop->resource<uvw::TcpHandle>();
auto client = loop->resource<uvw::TcpHandle>();
auto server = loop->resource<uvw::TCPHandle>();
auto client = loop->resource<uvw::TCPHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
server->once<uvw::ListenEvent>([&address, port](const uvw::ListenEvent &, uvw::TcpHandle &handle) {
std::shared_ptr<uvw::TcpHandle> socket = handle.loop().resource<uvw::TcpHandle>();
server->once<uvw::ListenEvent>([&address, port](const uvw::ListenEvent &, uvw::TCPHandle &handle) {
std::shared_ptr<uvw::TCPHandle> socket = handle.loop().resource<uvw::TCPHandle>();
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::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); });
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::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); });
handle.accept(*socket);
socket->read();
@ -86,7 +86,7 @@ TEST(Tcp, SockPeer) {
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();
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 unsigned int port = 4242;
auto loop = uvw::Loop::getDefault();
auto server = loop->resource<uvw::TcpHandle>();
auto client = loop->resource<uvw::TcpHandle>();
auto server = loop->resource<uvw::TCPHandle>();
auto client = loop->resource<uvw::TCPHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); });
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TcpHandle &handle) {
std::shared_ptr<uvw::TcpHandle> socket = handle.loop().resource<uvw::TcpHandle>();
server->once<uvw::ListenEvent>([](const uvw::ListenEvent &, uvw::TCPHandle &handle) {
std::shared_ptr<uvw::TCPHandle> socket = handle.loop().resource<uvw::TCPHandle>();
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::EndEvent>([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); });
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::EndEvent>([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); });
handle.accept(*socket);
socket->read();
});
client->once<uvw::ShutdownEvent>([](const uvw::ShutdownEvent &, uvw::TcpHandle &handle) {
client->once<uvw::ShutdownEvent>([](const uvw::ShutdownEvent &, uvw::TCPHandle &handle) {
handle.close();
});
client->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) {
client->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) {
handle.shutdown();
});
@ -141,9 +141,9 @@ TEST(Tcp, Shutdown) {
}
TEST(Tcp, WriteError) {
TEST(TCP, WriteError) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::TcpHandle>();
auto handle = loop->resource<uvw::TCPHandle>();
bool checkWriteSmartPtrErrorEvent = false;
bool checkWriteNakedPtrErrorEvent = false;
@ -151,13 +151,13 @@ TEST(Tcp, WriteError) {
bool checkTryWriteNakedPtrErrorEvent = false;
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->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->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->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);
loop->run();

View File

@ -10,10 +10,10 @@ TEST(Timer, StartAndStop) {
bool checkTimerNoRepeatEvent = false;
bool checkTimerRepeatEvent = false;
handleNoRepeat->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
handleRepeat->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
handleNoRepeat->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TimerHandle &) { 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);
checkTimerNoRepeatEvent = true;
handle.stop();
@ -21,7 +21,7 @@ TEST(Timer, StartAndStop) {
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) {
handle.stop();
handle.close();
@ -55,12 +55,12 @@ TEST(Timer, Again) {
bool checkErrorEvent = 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);
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;
if(guard) {
@ -111,9 +111,8 @@ TEST(Timer, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::TimerHandle>();
auto l = [](const auto &, auto &) { FAIL(); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::TimerEvent>(l);
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TimerHandle &) { FAIL(); });
handle->on<uvw::TimerEvent>([](const uvw::TimerEvent &, uvw::TimerHandle &) { FAIL(); });
handle->start(uvw::TimerHandle::Time{0}, uvw::TimerHandle::Time{0});
handle->close();

View File

@ -9,14 +9,14 @@ TEST(TTY, Functionalities) {
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);
checkWriteEvent = true;
hndl.close();
});
timer->on<uvw::TimerEvent>([handle](const auto &, auto &hndl){
auto data = std::make_unique<char[]>('*');
timer->on<uvw::TimerEvent>([handle](const uvw::TimerEvent &, uvw::TimerHandle &hndl){
auto data = std::unique_ptr<char[]>(new char[1]{'*'});
handle->write(std::move(data), 1);
hndl.close();
});

View File

@ -2,7 +2,7 @@
#include <uvw.hpp>
TEST(Udp, Functionalities) {
TEST(UDP, Functionalities) {
auto loop = uvw::Loop::getDefault();
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 unsigned int port = 4242;
auto loop = uvw::Loop::getDefault();
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->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 unsigned int port = 4242;
@ -47,8 +47,8 @@ TEST(Udp, ReadTrySend) {
auto server = loop->resource<uvw::UDPHandle>();
auto client = loop->resource<uvw::UDPHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
server->once<uvw::UDPDataEvent>([&client](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
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 unsigned int port = 4242;
@ -78,8 +78,8 @@ TEST(Udp, ReadSend) {
auto server = loop->resource<uvw::UDPHandle>();
auto client = loop->resource<uvw::UDPHandle>();
server->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
server->once<uvw::UDPDataEvent>([](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
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 unsigned int port = 4242;
auto loop = uvw::Loop::getDefault();
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->recv();

View File

@ -71,6 +71,14 @@ TEST(Util, ScopedFlags) {
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) {
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_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::CheckHandle>{}, uvw::HandleType::CHECK);
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::PipeHandle>{}, uvw::HandleType::PIPE);
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::UDPHandle>{}, uvw::HandleType::UDP);
guessHandle(tag<uvw::SignalHandle>{}, uvw::HandleType::SIGNAL);

View File

@ -9,7 +9,7 @@ TEST(Work, RunTask) {
bool checkWorkEvent = 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) {
hndl.stop();
hndl.close();
@ -21,9 +21,9 @@ TEST(Work, RunTask) {
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);
checkWorkEvent = true;
});
@ -42,7 +42,7 @@ TEST(Work, Cancellation) {
bool checkErrorEvent = false;
handle->on<uvw::TimerEvent>([](const auto &, auto &hndl) {
handle->on<uvw::TimerEvent>([](const uvw::TimerEvent &, uvw::TimerHandle &hndl) {
hndl.stop();
hndl.close();
});
@ -50,8 +50,8 @@ TEST(Work, Cancellation) {
for(auto i = 0; i < 5 /* default uv thread pool size + 1 */; ++i) {
auto req = loop->resource<uvw::WorkReq>([]() {});
req->on<uvw::WorkEvent>([](const auto &, auto &) {});
req->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &) { checkErrorEvent = true; });
req->on<uvw::WorkEvent>([](const uvw::WorkEvent &, uvw::WorkReq &) {});
req->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::WorkReq &) { checkErrorEvent = true; });
req->queue();
req->cancel();