From a204675781bf43b7f062d11f61ac7edaf391c691 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 25 Aug 2016 18:06:26 +0200 Subject: [PATCH 1/2] minor changes --- src/uvw/tcp.hpp | 2 ++ src/uvw/udp.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/uvw/tcp.hpp b/src/uvw/tcp.hpp index 2e809db7..b5093e7d 100644 --- a/src/uvw/tcp.hpp +++ b/src/uvw/tcp.hpp @@ -46,6 +46,8 @@ class TcpHandle final: public StreamHandle { public: using Time = std::chrono::seconds; using Bind = details::UVTcpFlags; + using IPv4 = uvw::IPv4; + using IPv6 = uvw::IPv6; /** * @brief Creates a new tcp handle. diff --git a/src/uvw/udp.hpp b/src/uvw/udp.hpp index cc039203..f9cc28c7 100644 --- a/src/uvw/udp.hpp +++ b/src/uvw/udp.hpp @@ -139,6 +139,8 @@ class UDPHandle final: public Handle { public: using Membership = details::UVMembership; using Bind = details::UVUdpFlags; + using IPv4 = uvw::IPv4; + using IPv6 = uvw::IPv6; /** * @brief Creates a new udp handle. From a2f09298a023bbaaf1c61d98e57c7dc6ed99a033 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 25 Aug 2016 18:06:57 +0200 Subject: [PATCH 2/2] added Utilities::replaceAllocator --- src/uvw/util.hpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index 97c0e8f0..c7eca473 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -302,6 +302,12 @@ std::string path(F &&f, H *handle) noexcept { * Miscellaneous functions that don’t really belong to any other class. */ struct Utilities { + using MallocFuncType = void*(*)(size_t); + using ReallocFuncType = void*(*)(void*, size_t); + using CallocFuncType = void*(*)(size_t, size_t); + using FreeFuncType = void(*)(void*); + + /** * @brief Gets the type of the stream to be used with the given descriptor. * @@ -402,13 +408,39 @@ struct Utilities { return interfaces; } + + + /** + * @brief Override the use of some standard library’s functions. + * + * Override the use of the standard library’s memory allocation + * functions.
+ * This method must be invoked before any other `uvw` function is called or + * after all resources have been freed and thus the underlying library + * doesn’t reference any allocated memory chunk. + * + * If any of the function pointers is _null_, the invokation will fail. + * + * **Note**: there is no protection against changing the allocator multiple + * times. If the user changes it they are responsible for making sure the + * allocator is changed while no memory was allocated with the previous + * allocator, or that they are compatible. + * + * @param mallocFunc Replacement function for _malloc_. + * @param reallocFunc Replacement function for _realloc_. + * @param callocFunc Replacement function for _calloc_. + * @param freeFunc Replacement function for _free_. + * @return True in case of success, false otherwise. + */ + static bool replaceAllocator(MallocFuncType mallocFunc, ReallocFuncType reallocFunc, CallocFuncType callocFunc, FreeFuncType freeFunc) { + return (0 == uv_replace_allocator(mallocFunc, reallocFunc, callocFunc, freeFunc)); + } }; /** * TODO * - * * uv_replace_allocator * * uv_uptime * * uv_getrusage * * uv_cpu_info