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
This commit is contained in:
parent
1c930cdcb5
commit
68ed09d929
@ -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();
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
39
README.md
39
README.md
@ -30,15 +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>();
|
||||
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(); });
|
||||
|
||||
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();
|
||||
});
|
||||
@ -48,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();
|
||||
@ -203,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/>
|
||||
@ -211,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();
|
||||
```
|
||||
|
||||
@ -273,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.
|
||||
|
||||
@ -284,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();
|
||||
});
|
||||
@ -300,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.
|
||||
@ -320,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();
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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> {
|
||||
@ -314,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.
|
||||
*
|
||||
@ -353,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.
|
||||
*
|
||||
|
||||
@ -18,7 +18,7 @@ namespace uvw {
|
||||
namespace details {
|
||||
|
||||
|
||||
enum class UVTcpFlags: typename std::underlying_type<uv_tcp_flags>::type {
|
||||
enum class UVTCPFlags: typename std::underlying_type<uv_tcp_flags>::type {
|
||||
IPV6ONLY = UV_TCP_IPV6ONLY
|
||||
};
|
||||
|
||||
@ -27,13 +27,13 @@ enum class UVTcpFlags: typename std::underlying_type<uv_tcp_flags>::type {
|
||||
|
||||
|
||||
/**
|
||||
* @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: typename std::underlying_type<uv_tcp_flags>::type {
|
||||
* [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.
|
||||
|
||||
@ -45,7 +45,7 @@ struct UDPDataEvent {
|
||||
namespace details {
|
||||
|
||||
|
||||
enum class UVUdpFlags: typename std::underlying_type<uv_udp_flags>::type {
|
||||
enum class UVUDPFlags: typename std::underlying_type<uv_udp_flags>::type {
|
||||
IPV6ONLY = UV_UDP_IPV6ONLY,
|
||||
REUSEADDR = UV_UDP_REUSEADDR
|
||||
};
|
||||
@ -81,13 +81,13 @@ private:
|
||||
|
||||
|
||||
/**
|
||||
* @brief The UdpHandle handle.
|
||||
* @brief The UDPHandle handle.
|
||||
*
|
||||
* UDP handles encapsulate UDP communication for both clients 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 an `UdpHandle` through a `Loop`, arguments follow:
|
||||
* To create an `UDPHandle` through a `Loop`, arguments follow:
|
||||
*
|
||||
* * An optional integer value that indicates optional flags used to initialize
|
||||
* the socket.
|
||||
@ -96,12 +96,12 @@ private:
|
||||
* [documentation](http://docs.libuv.org/en/v1.x/udp.html#c.uv_udp_init_ex)
|
||||
* for further details.
|
||||
*/
|
||||
class UdpHandle final: public Handle<UdpHandle, uv_udp_t> {
|
||||
class UDPHandle final: public Handle<UDPHandle, uv_udp_t> {
|
||||
template<typename I>
|
||||
static void recvCallback(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const sockaddr *addr, unsigned flags) {
|
||||
const typename details::IpTraits<I>::Type *aptr = reinterpret_cast<const typename details::IpTraits<I>::Type *>(addr);
|
||||
|
||||
UdpHandle &udp = *(static_cast<UdpHandle*>(handle->data));
|
||||
UDPHandle &udp = *(static_cast<UDPHandle*>(handle->data));
|
||||
// data will be destroyed no matter of what the value of nread is
|
||||
std::unique_ptr<const char[]> data{buf->base};
|
||||
|
||||
@ -121,13 +121,13 @@ 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;
|
||||
|
||||
using Handle::Handle;
|
||||
|
||||
explicit UdpHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, unsigned int f)
|
||||
explicit UDPHandle(ConstructorAccess ca, std::shared_ptr<Loop> ref, unsigned int f)
|
||||
: Handle{ca, std::move(ref)}, tag{FLAGS}, flags{f}
|
||||
{}
|
||||
|
||||
|
||||
@ -378,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);
|
||||
|
||||
|
||||
@ -6,23 +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;
|
||||
});
|
||||
|
||||
auto ptr = srv.shared_from_this();
|
||||
client->on<uvw::CloseEvent>([ptr](const uvw::CloseEvent &, uvw::TcpHandle &) {
|
||||
client->on<uvw::CloseEvent>([ptr](const uvw::CloseEvent &, uvw::TCPHandle &) {
|
||||
std::cout << "close" << std::endl;
|
||||
ptr->close();
|
||||
});
|
||||
@ -35,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; });
|
||||
@ -51,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;
|
||||
});
|
||||
|
||||
@ -61,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' });
|
||||
@ -83,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;
|
||||
});
|
||||
|
||||
|
||||
@ -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 uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); });
|
||||
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { 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 uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); });
|
||||
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { 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 uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); });
|
||||
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TcpHandle &) { 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 uvw::ErrorEvent &, uvw::TcpHandle &) { 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 uvw::ErrorEvent &, uvw::TcpHandle &) { checkWriteNakedPtrErrorEvent = true; });
|
||||
handle->once<uvw::ErrorEvent>([&checkWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkWriteNakedPtrErrorEvent = true; });
|
||||
handle->write(nullptr, 0);
|
||||
handle->once<uvw::ErrorEvent>([&checkTryWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TcpHandle &) { 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 uvw::ErrorEvent &, uvw::TcpHandle &) { checkTryWriteNakedPtrErrorEvent = true; });
|
||||
handle->once<uvw::ErrorEvent>([&checkTryWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkTryWriteNakedPtrErrorEvent = true; });
|
||||
handle->tryWrite(nullptr, 0);
|
||||
|
||||
loop->run();
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
#include <uvw.hpp>
|
||||
|
||||
|
||||
TEST(Udp, Functionalities) {
|
||||
TEST(UDP, Functionalities) {
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::UdpHandle>();
|
||||
auto handle = loop->resource<uvw::UDPHandle>();
|
||||
|
||||
ASSERT_FALSE(handle->multicastMembership("0.0.0.0", "127.0.0.1", uvw::UdpHandle::Membership::JOIN_GROUP));
|
||||
ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UdpHandle::Membership::JOIN_GROUP));
|
||||
ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UdpHandle::Membership::LEAVE_GROUP));
|
||||
ASSERT_FALSE(handle->multicastMembership("0.0.0.0", "127.0.0.1", uvw::UDPHandle::Membership::JOIN_GROUP));
|
||||
ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UDPHandle::Membership::JOIN_GROUP));
|
||||
ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UDPHandle::Membership::LEAVE_GROUP));
|
||||
ASSERT_TRUE(handle->multicastLoop(true));
|
||||
ASSERT_TRUE(handle->multicastTtl(42));
|
||||
ASSERT_TRUE(handle->multicastInterface("127.0.0.1"));
|
||||
@ -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>();
|
||||
auto handle = loop->resource<uvw::UDPHandle>();
|
||||
|
||||
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); });
|
||||
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||
|
||||
handle->bind(address, port);
|
||||
handle->recv();
|
||||
@ -39,18 +39,18 @@ TEST(Udp, BindRecvStop) {
|
||||
}
|
||||
|
||||
|
||||
TEST(Udp, ReadTrySend) {
|
||||
TEST(UDP, ReadTrySend) {
|
||||
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::UdpHandle>();
|
||||
auto client = loop->resource<uvw::UdpHandle>();
|
||||
auto server = loop->resource<uvw::UDPHandle>();
|
||||
auto client = loop->resource<uvw::UDPHandle>();
|
||||
|
||||
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); });
|
||||
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UdpHandle &) { 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) {
|
||||
server->once<uvw::UDPDataEvent>([&client](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
|
||||
client->close();
|
||||
handle.close();
|
||||
});
|
||||
@ -70,22 +70,22 @@ TEST(Udp, ReadTrySend) {
|
||||
}
|
||||
|
||||
|
||||
TEST(Udp, ReadSend) {
|
||||
TEST(UDP, ReadSend) {
|
||||
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::UdpHandle>();
|
||||
auto client = loop->resource<uvw::UdpHandle>();
|
||||
auto server = loop->resource<uvw::UDPHandle>();
|
||||
auto client = loop->resource<uvw::UDPHandle>();
|
||||
|
||||
server->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); });
|
||||
client->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UdpHandle &) { 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) {
|
||||
server->once<uvw::UDPDataEvent>([](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) {
|
||||
handle.close();
|
||||
});
|
||||
|
||||
client->once<uvw::SendEvent>([](const uvw::SendEvent &, uvw::UdpHandle &handle) {
|
||||
client->once<uvw::SendEvent>([](const uvw::SendEvent &, 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>();
|
||||
auto handle = loop->resource<uvw::UDPHandle>();
|
||||
|
||||
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); });
|
||||
handle->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); });
|
||||
|
||||
handle->bind(address, port);
|
||||
handle->recv();
|
||||
|
||||
@ -113,9 +113,9 @@ 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::UDPHandle>{}, uvw::HandleType::UDP);
|
||||
guessHandle(tag<uvw::SignalHandle>{}, uvw::HandleType::SIGNAL);
|
||||
|
||||
auto cpuInfo = uvw::Utilities::cpuInfo();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user