From 79f6eb9f176756b3229802dc412118dd59a19f06 Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fl.fischer@fau.de>
Date: Thu, 18 Mar 2021 12:24:27 +0100
Subject: [PATCH] [IO] mark IO functions returning futures as nodiscard

Fix compilation error in LinkFutureTest where clsoe was used instead
of closeAndWait.
---
 emper/io.hpp             | 29 ++++++++++++++++-------------
 tests/LinkFutureTest.cpp |  2 +-
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/emper/io.hpp b/emper/io.hpp
index 10b22878..64efb93f 100644
--- a/emper/io.hpp
+++ b/emper/io.hpp
@@ -36,7 +36,8 @@ namespace emper::io {
  *
  * @return Future object which signals the completion of the recv request
  */
-inline auto recv(int socket, void *buffer, size_t length, int flags) -> std::unique_ptr<Future> {
+[[nodiscard]] inline auto recv(int socket, void *buffer, size_t length, int flags)
+		-> std::unique_ptr<Future> {
 	auto future = std::make_unique<RecvFuture>(socket, buffer, length, flags);
 	future->submit();
 	return future;
@@ -76,8 +77,8 @@ inline auto recvAndWait(int socket, void *buffer, size_t length, int flags) -> s
  *
  * @return Future object which signals the completion of the send request
  */
-inline auto send(int socket, const void *buffer, size_t length, int flags, bool send_all = true)
-		-> std::unique_ptr<Future> {
+[[nodiscard]] inline auto send(int socket, const void *buffer, size_t length, int flags,
+															 bool send_all = true) -> std::unique_ptr<Future> {
 	auto future = std::make_unique<SendFuture>(socket, buffer, length, flags, send_all);
 	future->submit();
 	return future;
@@ -124,7 +125,7 @@ inline auto sendAndWait(int socket, const void *buffer, size_t length, int flags
  *
  * @return Future object which signals the completion of the connect request
  */
-inline auto connect(int socket, const struct sockaddr *address, socklen_t address_len)
+[[nodiscard]] inline auto connect(int socket, const struct sockaddr *address, socklen_t address_len)
 		-> std::unique_ptr<Future> {
 	auto future = std::make_unique<ConnectFuture>(socket, address, address_len);
 	future->submit();
@@ -174,7 +175,7 @@ inline auto connectAndWait(int socket, const struct sockaddr *address, socklen_t
  *
  * @return Future object which signals the completion of the accept request
  */
-inline auto accept(int socket, struct sockaddr *address, socklen_t *address_len)
+[[nodiscard]] inline auto accept(int socket, struct sockaddr *address, socklen_t *address_len)
 		-> std::unique_ptr<Future> {
 	auto future = std::make_unique<AcceptFuture>(socket, address, address_len);
 	future->submit();
@@ -220,8 +221,8 @@ inline auto acceptAndWait(int socket, struct sockaddr *address, socklen_t *addre
  *
  * @return Future object which signals the completion of the read request
  */
-inline auto readFile(int fildes, void *buf, size_t nbyte, off_t offset = -1, bool read_all = false)
-		-> std::unique_ptr<Future> {
+[[nodiscard]] inline auto readFile(int fildes, void *buf, size_t nbyte, off_t offset = -1,
+																	 bool read_all = false) -> std::unique_ptr<Future> {
 	auto future = std::make_unique<ReadFuture>(fildes, buf, nbyte, offset, read_all);
 	future->submit();
 	return future;
@@ -267,8 +268,8 @@ inline auto readFileAndWait(int fildes, void *buf, size_t nbyte, off_t offset =
  *
  * @return Future object which signals the completion of the write request
  */
-inline auto writeFile(int fildes, const void *buf, size_t nbyte, off_t offset = -1,
-											bool write_all = true) -> std::unique_ptr<Future> {
+[[nodiscard]] inline auto writeFile(int fildes, const void *buf, size_t nbyte, off_t offset = -1,
+																		bool write_all = true) -> std::unique_ptr<Future> {
 	auto future = std::make_unique<WriteFuture>(fildes, buf, nbyte, offset, write_all);
 	future->submit();
 	return future;
@@ -311,7 +312,8 @@ inline auto writeFileAndWait(int fildes, const void *buf, size_t nbyte, off_t of
  *
  * @return Future object which signals the completion of the write request
  */
-inline auto writev(int fildes, const struct iovec *iov, int iovcnt) -> std::unique_ptr<Future> {
+[[nodiscard]] inline auto writev(int fildes, const struct iovec *iov, int iovcnt)
+		-> std::unique_ptr<Future> {
 	auto future = std::make_unique<WritevFuture>(fildes, iov, iovcnt);
 	future->submit();
 	return future;
@@ -348,7 +350,7 @@ inline auto writevAndWait(int fildes, const struct iovec *iov, int iovcnt) -> ss
  *
  * @return Future object which signals the completion of the openat request
  */
-inline auto openat(int dirfd, const char *pathname, int flags, mode_t mode = 0)
+[[nodiscard]] inline auto openat(int dirfd, const char *pathname, int flags, mode_t mode = 0)
 		-> std::unique_ptr<Future> {
 	auto future = std::make_unique<OpenatFuture>(dirfd, pathname, flags, mode);
 	future->submit();
@@ -386,7 +388,8 @@ inline auto openatAndWait(int dirfd, const char *pathname, int flags, mode_t mod
  *
  * @return Future object which signals the completion of the open request
  */
-inline auto open(const char *pathname, int flags, mode_t mode = 0) -> std::unique_ptr<Future> {
+[[nodiscard]] inline auto open(const char *pathname, int flags, mode_t mode = 0)
+		-> std::unique_ptr<Future> {
 	auto future = std::make_unique<OpenatFuture>(AT_FDCWD, pathname, flags, mode);
 	future->submit();
 	return future;
@@ -420,7 +423,7 @@ inline auto openAndWait(const char *pathname, int flags, mode_t mode = 0) -> siz
  *
  * @return Future object which signals the completion of the close request
  */
-inline auto close(int fd) -> std::unique_ptr<Future> {
+[[nodiscard]] inline auto close(int fd) -> std::unique_ptr<Future> {
 	auto future = std::make_unique<CloseFuture>(fd);
 	future->submit();
 	return future;
diff --git a/tests/LinkFutureTest.cpp b/tests/LinkFutureTest.cpp
index 9a05b036..6d3d0c7a 100644
--- a/tests/LinkFutureTest.cpp
+++ b/tests/LinkFutureTest.cpp
@@ -116,7 +116,7 @@ static void failureChainCorInvCor() {
 	res = correctFuture1.wait();
 	assert(res == (int32_t)buf.size());
 
-	emper::io::close(fd);
+	emper::io::closeAndWait(fd);
 }
 
 void emperTest() {
-- 
GitLab