From 7fda7c5072cdc1b78fc62b1cb1f2842e465cb02b Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 3 Jul 2023 14:40:46 +0200 Subject: [PATCH] pipe: use UV_PIPE_NO_TRUNCATE as needed --- src/uvw/pipe.cpp | 8 ++++---- src/uvw/pipe.h | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/uvw/pipe.cpp b/src/uvw/pipe.cpp index 0032ba9b..bf23a4b1 100644 --- a/src/uvw/pipe.cpp +++ b/src/uvw/pipe.cpp @@ -18,11 +18,11 @@ UVW_INLINE int pipe_handle::open(file_handle file) { return uv_pipe_open(raw(), file); } -UVW_INLINE int pipe_handle::bind(const std::string &name) { - return uv_pipe_bind(raw(), name.data()); +UVW_INLINE int pipe_handle::bind(const std::string &name, const bool no_truncate) { + return uv_pipe_bind2(raw(), name.data(), name.size(), no_truncate * UV_PIPE_NO_TRUNCATE); } -UVW_INLINE int pipe_handle::connect(const std::string &name) { +UVW_INLINE int pipe_handle::connect(const std::string &name, const bool no_truncate) { auto listener = [ptr = shared_from_this()](const auto &event, const auto &) { ptr->publish(event); }; @@ -31,7 +31,7 @@ UVW_INLINE int pipe_handle::connect(const std::string &name) { connect->on(listener); connect->on(listener); - return connect->connect(&uv_pipe_connect, raw(), name.data()); + return connect->connect(&uv_pipe_connect2, raw(), name.data(), name.size(), no_truncate * UV_PIPE_NO_TRUNCATE); } UVW_INLINE std::string pipe_handle::sock() const noexcept { diff --git a/src/uvw/pipe.h b/src/uvw/pipe.h index eaea5ebf..c73c0410 100644 --- a/src/uvw/pipe.h +++ b/src/uvw/pipe.h @@ -64,9 +64,10 @@ public: * Paths on Unix get truncated typically between 92 and 108 bytes. * * @param name A valid file path. + * @param no_truncate Force an error rather than allow truncating a path. * @return Underlying return value. */ - int bind(const std::string &name); + int bind(const std::string &name, const bool no_truncate = false); /** * @brief Connects to the Unix domain socket or the named pipe. @@ -76,9 +77,10 @@ public: * established. * * @param name A valid domain socket or named pipe. + * @param no_truncate Force an error rather than allow truncating a path. * @return Underlying return value. */ - int connect(const std::string &name); + int connect(const std::string &name, const bool no_truncate = false); /** * @brief Gets the name of the Unix domain socket or the named pipe.