diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index d1177ef5..52553fde 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -129,12 +129,12 @@ struct FsEvent : Event> { FsEvent(const char *path, std::unique_ptr data, ssize_t size) noexcept - : path{path}, data{std::move(data)}, size{size} + : path{path}, data{std::move(data)}, size(size) { } const char * path; /*!< The path affecting the request. */ std::unique_ptr data; /*!< A bunch of data read from the given path. */ - ssize_t size; /*!< The amount of data read from the given path. */ + std::size_t size; /*!< The amount of data read from the given path. */ }; @@ -149,11 +149,11 @@ struct FsEvent : Event> { FsEvent(const char *path, ssize_t size) noexcept - : path{path}, size{size} + : path{path}, size(size) { } const char * path; /*!< The path affecting the request. */ - ssize_t size; /*!< The amount of data written to the given path. */ + std::size_t size; /*!< The amount of data written to the given path. */ }; @@ -168,11 +168,11 @@ struct FsEvent : Event> { FsEvent(const char *path, ssize_t size) noexcept - : path{path}, size{size} + : path{path}, size(size) { } const char * path; /*!< The path affecting the request. */ - ssize_t size; /*!< The amount of data transferred. */ + std::size_t size; /*!< The amount of data transferred. */ }; @@ -187,7 +187,7 @@ struct FsEvent : Event> { FsEvent(const char *path, Stat stat) noexcept - : path{path}, stat(std::move(stat)) + : path{path}, stat{std::move(stat)} { } const char * path; /*!< The path affecting the request. */ @@ -206,7 +206,7 @@ struct FsEvent : Event> { FsEvent(const char *path, Stat stat) noexcept - : path{path}, stat(std::move(stat)) + : path{path}, stat{std::move(stat)} { } const char * path; /*!< The path affecting the request. */ @@ -225,7 +225,7 @@ struct FsEvent : Event> { FsEvent(const char *path, Stat stat) noexcept - : path{path}, stat(std::move(stat)) + : path{path}, stat{std::move(stat)} { } const char * path; /*!< The path affecting the request. */ @@ -244,11 +244,11 @@ struct FsEvent : Event> { FsEvent(const char *path, ssize_t size) noexcept - : path{path}, size{size} + : path{path}, size(size) { } const char * path; /*!< The path affecting the request. */ - ssize_t size; /*!< The number of directory entries selected. */ + std::size_t size; /*!< The number of directory entries selected. */ }; @@ -263,12 +263,12 @@ struct FsEvent : Event> { explicit FsEvent(const char *path, const char *data, ssize_t size) noexcept - : path{path}, data{data}, size{size} + : path{path}, data{data}, size(size) { } const char * path; /*!< The path affecting the request. */ const char * data; /*!< A bunch of data read from the given path. */ - ssize_t size; /*!< The amount of data read from the given path. */ + std::size_t size; /*!< The amount of data read from the given path. */ }; @@ -457,14 +457,15 @@ public: * * A bunch of data read from the given path. * * The amount of data read from the given path. */ - std::pair, ssize_t>> + std::pair, std::size_t>> readSync(int64_t offset, unsigned int len) { data = std::unique_ptr{new char[len]}; buffer = uv_buf_init(data.get(), len); uv_buf_t bufs[] = { buffer }; auto req = get(); cleanupAndInvokeSync(&uv_fs_read, parent(), req, file, bufs, 1, offset); - return std::make_pair(!(req->result < 0), std::make_pair(std::move(data), req->result)); + bool err = req->result < 0; + return std::make_pair(!err, std::make_pair(std::move(data), err ? 0 : std::size_t(req->result))); } /** @@ -477,7 +478,7 @@ public: * @param len The lenght of the submitted data. * @param offset Offset, as described in the official documentation. */ - void write(std::unique_ptr data, ssize_t len, int64_t offset) { + void write(std::unique_ptr data, std::size_t len, int64_t offset) { this->data = std::move(data); uv_buf_t bufs[] = { uv_buf_init(this->data.get(), len) }; cleanupAndInvoke(&uv_fs_write, parent(), get(), file, bufs, 1, offset, &fsResultCallback); @@ -494,12 +495,13 @@ public: * * A boolean value that is true in case of success, false otherwise. * * The amount of data written to the given path. */ - std::pair writeSync(std::unique_ptr data, ssize_t len, int64_t offset) { + std::pair writeSync(std::unique_ptr data, std::size_t len, int64_t offset) { this->data = std::move(data); uv_buf_t bufs[] = { uv_buf_init(this->data.get(), len) }; auto req = get(); cleanupAndInvokeSync(&uv_fs_write, parent(), req, file, bufs, 1, offset); - return std::make_pair(!(req->result < 0), req->result); + bool err = req->result < 0; + return std::make_pair(!err, err ? 0 : std::size_t(req->result)); } /** @@ -598,7 +600,7 @@ public: * @param offset Offset, as described in the official documentation. * @param length Length, as described in the official documentation. */ - void sendfile(FileHandle out, int64_t offset, size_t length) { + void sendfile(FileHandle out, int64_t offset, std::size_t length) { cleanupAndInvoke(&uv_fs_sendfile, parent(), get(), out, file, offset, length, &fsResultCallback); } @@ -613,10 +615,11 @@ public: * * A boolean value that is true in case of success, false otherwise. * * The amount of data transferred. */ - std::pair sendfileSync(FileHandle out, int64_t offset, size_t length) { + std::pair sendfileSync(FileHandle out, int64_t offset, std::size_t length) { auto req = get(); cleanupAndInvokeSync(&uv_fs_sendfile, parent(), req, out, file, offset, length); - return std::make_pair(!(req->result < 0), req->result); + bool err = req->result < 0; + return std::make_pair(!err, err ? 0 : std::size_t(req->result)); } /** @@ -867,10 +870,11 @@ public: * * A boolean value that is true in case of success, false otherwise. * * The number of directory entries selected. */ - std::pair scandirSync(std::string path, int flags) { + std::pair scandirSync(std::string path, int flags) { auto req = get(); cleanupAndInvokeSync(&uv_fs_scandir, parent(), req, path.data(), flags); - return std::make_pair(!(req->result < 0), req->result); + bool err = req->result < 0; + return std::make_pair(!err, err ? 0 : std::size_t(req->result)); } /** @@ -1151,11 +1155,12 @@ public: * * A bunch of data read from the given path. * * The amount of data read from the given path. */ - std::pair> + std::pair> readlinkSync(std::string path) { auto req = get(); cleanupAndInvokeSync(&uv_fs_readlink, parent(), req, path.data()); - return std::make_pair(!(req->result < 0), std::make_pair(static_cast(req->ptr), req->result)); + bool err = req->result < 0; + return std::make_pair(!err, std::make_pair(static_cast(req->ptr), err ? 0 : std::size_t(req->result))); } /** diff --git a/src/uvw/fs_poll.hpp b/src/uvw/fs_poll.hpp index 6000d420..d63b65b4 100644 --- a/src/uvw/fs_poll.hpp +++ b/src/uvw/fs_poll.hpp @@ -21,7 +21,7 @@ namespace uvw { */ struct FsPollEvent: Event { explicit FsPollEvent(Stat prev, Stat curr) noexcept - : prev(std::move(prev)), curr(std::move(curr)) + : prev{std::move(prev)}, curr{std::move(curr)} { } Stat prev; /*!< The old Stat struct. */ diff --git a/src/uvw/lib.hpp b/src/uvw/lib.hpp index d060209d..535a8685 100644 --- a/src/uvw/lib.hpp +++ b/src/uvw/lib.hpp @@ -20,8 +20,7 @@ namespace uvw { */ class SharedLib final { explicit SharedLib(std::shared_ptr ref, std::string filename) noexcept - : pLoop{std::move(ref)}, - lib{} + : pLoop{std::move(ref)}, lib{} { opened = (0 == uv_dlopen(filename.data(), &lib)); } diff --git a/src/uvw/signal.hpp b/src/uvw/signal.hpp index c5b76b7c..ca8f6eb7 100644 --- a/src/uvw/signal.hpp +++ b/src/uvw/signal.hpp @@ -18,7 +18,7 @@ namespace uvw { * It will be emitted by SignalHandle according with its functionalities. */ struct SignalEvent: Event { - explicit SignalEvent(int sig) noexcept: signum(sig) { } + explicit SignalEvent(int sig) noexcept: signum{sig} { } int signum; /*!< The signal being monitored by this handle. */ }; diff --git a/src/uvw/stream.hpp b/src/uvw/stream.hpp index 59b2019a..74b20e9a 100644 --- a/src/uvw/stream.hpp +++ b/src/uvw/stream.hpp @@ -63,11 +63,11 @@ struct WriteEvent: Event { }; */ struct DataEvent: Event { explicit DataEvent(std::unique_ptr data, ssize_t length) noexcept - : data{std::move(data)}, length{length} + : data{std::move(data)}, length(length) { } std::unique_ptr data; /*!< A bunch of data read on the stream. */ - ssize_t length; /*!< The amount of data read on the stream. */ + std::size_t length; /*!< The amount of data read on the stream. */ }; @@ -273,7 +273,7 @@ public: * @param data The data to be written to the stream. * @param len The lenght of the submitted data. */ - void write(std::unique_ptr data, ssize_t len) { + void write(std::unique_ptr data, std::size_t len) { const uv_buf_t bufs[] = { uv_buf_init(data.release(), len) }; auto listener = [ptr = this->shared_from_this()](const auto &event, details::WriteReq &) { @@ -304,7 +304,7 @@ public: * @param len The lenght of the submitted data. */ template - void write(S &send, std::unique_ptr data, ssize_t len) { + void write(S &send, std::unique_ptr data, std::size_t len) { const uv_buf_t bufs[] = { uv_buf_init(data.release(), len) }; auto listener = [ptr = this->shared_from_this()](const auto &event, details::WriteReq &) { @@ -328,7 +328,7 @@ public: * @param len The lenght of the submitted data. * @return Number of bytes written. */ - int tryWrite(std::unique_ptr data, ssize_t len) { + int tryWrite(std::unique_ptr data, std::size_t len) { uv_buf_t bufs[] = { uv_buf_init(data.get(), len) }; auto bw = uv_try_write(this->template get(), bufs, 1); diff --git a/src/uvw/thread.hpp b/src/uvw/thread.hpp index 945cb6f3..f30bc4d8 100644 --- a/src/uvw/thread.hpp +++ b/src/uvw/thread.hpp @@ -31,10 +31,7 @@ class Thread final { } explicit Thread(std::shared_ptr ref, InternalTask t, std::shared_ptr d = nullptr) noexcept - : pLoop{std::move(ref)}, - data{std::move(d)}, - thread{}, - task{std::move(t)} + : pLoop{std::move(ref)}, data{std::move(d)}, thread{}, task{std::move(t)} { } public: diff --git a/src/uvw/udp.hpp b/src/uvw/udp.hpp index 44cd77f6..45bd3b22 100644 --- a/src/uvw/udp.hpp +++ b/src/uvw/udp.hpp @@ -33,11 +33,11 @@ struct SendEvent: Event { }; */ struct UDPDataEvent: Event { explicit UDPDataEvent(Addr sender, std::unique_ptr data, ssize_t length, bool partial) noexcept - : data{std::move(data)}, length{length}, sender(std::move(sender)), partial{partial} + : data{std::move(data)}, length(length), sender{std::move(sender)}, partial{partial} { } std::unique_ptr data; /*!< A bunch of data read on the stream. */ - ssize_t length; /*!< The amount of data read on the stream. */ + std::size_t length; /*!< The amount of data read on the stream. */ Addr sender; /*!< A valid instance of Addr. */ bool partial; /*!< True if the message was truncated, false otherwise. */ }; @@ -318,7 +318,7 @@ public: * @param len The lenght of the submitted data. */ template - void send(std::string ip, unsigned int port, std::unique_ptr data, ssize_t len) { + void send(std::string ip, unsigned int port, std::unique_ptr data, std::size_t len) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); @@ -347,7 +347,7 @@ public: * @return Number of bytes written. */ template - int trySend(std::string ip, unsigned int port, std::unique_ptr data, ssize_t len) { + int trySend(std::string ip, unsigned int port, std::unique_ptr data, std::size_t len) { typename details::IpTraits::Type addr; details::IpTraits::addrFunc(ip.data(), port, &addr); diff --git a/test/uvw/file_req.cpp b/test/uvw/file_req.cpp index 8140f08c..e021e68f 100644 --- a/test/uvw/file_req.cpp +++ b/test/uvw/file_req.cpp @@ -104,13 +104,13 @@ TEST(FileReq, RWSync) { auto writeR = request->writeSync(std::unique_ptr{new char[1]{ 42 }}, 1, 0); ASSERT_TRUE(writeR.first); - ASSERT_EQ(writeR.second, 1); + ASSERT_EQ(writeR.second, std::size_t{1}); auto readR = request->readSync(0, 1); ASSERT_TRUE(readR.first); ASSERT_EQ(readR.second.first[0], 42); - ASSERT_EQ(readR.second.second, 1); + ASSERT_EQ(readR.second.second, std::size_t{1}); ASSERT_TRUE(request->closeSync()); loop->run();