Skip to content
Snippets Groups Projects
Commit d8461928 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'shutdown_future' into 'master'

[IO] add shutdown(3) support

See merge request i4/manycore/emper!190
parents 7214c422 6b069c65
No related branches found
No related tags found
1 merge request!190[IO] add shutdown(3) support
Pipeline #67143 passed
......@@ -334,11 +334,9 @@ class Client {
}
}
::shutdown(sock, SHUT_RDWR);
// ShutdownFuture shut_f(sock, SHUT_RDWR);
ShutdownFuture shut_f(sock, SHUT_RDWR);
CloseFuture cf(sock);
// cf.setDependency(shut_f);
cf.setDependency(shut_f);
cf.submit();
cf.wait();
......
......@@ -169,5 +169,7 @@ auto emper_openat(int dirfd, const char* pathname, int flags, ...) -> int {
return emper::io::openatAndWait(dirfd, pathname, flags);
}
auto emper_shutdown(int sockfd, int how) -> int { return emper::io::shutdownAndWait(sockfd, how); }
auto emper_close(int fd) -> int { return emper::io::closeAndWait(fd); }
#endif
......@@ -96,6 +96,9 @@ int emper_open(const char* pathname, int flags, ...);
// NOLINTNEXTLINE(modernize-use-trailing-return-type)
int emper_openat(int dirfd, const char* pathname, int flags, ...);
// NOLINTNEXTLINE(modernize-use-trailing-return-type)
int emper_shutdown(int sockfd, int how);
// NOLINTNEXTLINE(modernize-use-trailing-return-type)
int emper_close(int fd);
#endif
......
......@@ -516,6 +516,41 @@ inline auto openAndWait(const char *pathname, int flags, mode_t mode = 0) -> int
return future.waitAndSetErrno();
}
/**
* @brief Non-blocking shutdown mimicking POSIX shutdown(3)
*
* This method must be called from inside the emper runtime because it uses
* the worker-local IoContext
*
* @param sockfd socket file descriptor to shut down
* @param how type of shutdown
*
* @return Future object which signals the completion of the shutdown request
*/
[[nodiscard]] inline auto shutdown(int sockfd, int how) -> std::unique_ptr<Future> {
auto future = std::make_unique<ShutdownFuture>(sockfd, how);
future->submit();
return future;
}
/**
* @brief Blocking shutdown mimicking POSIX shutdown(3)
*
* This method must be called from inside the emper runtime because it uses
* the worker-local IoContext
*
* @param sockfd socket file descriptor to shut down
* @param how type of shutdown
*
* @return 0 on success, -1 on error
*/
inline auto shutdownAndWait(int sockfd, int how) -> int {
ShutdownFuture future(sockfd, how);
future.submit();
return future.waitAndSetErrno();
}
/**
* @brief Non-blocking close mimicking POSIX close(3)
*
......
......@@ -611,6 +611,13 @@ class CloseFuture : public Future {
void submitAndForget() { Future::submitAndForget(); }
};
class ShutdownFuture : public Future {
void prepareSqe(io_uring_sqe* sqe) override { io_uring_prep_shutdown(sqe, fd, flags); }
public:
ShutdownFuture(int sockfd, int how) : Future(Operation::SHUTDOWN, sockfd, nullptr, 0, how){};
};
/*
* @brief Add a timeout to any Future not already submitted.
*
......
......@@ -35,6 +35,9 @@ auto operator<<(std::ostream& os, const Operation& op) -> std::ostream& {
case Operation::CLOSE:
os << "close";
break;
case Operation::SHUTDOWN:
os << "shutdown";
break;
case Operation::LINK_TIMEOUT:
os << "linked timeout";
break;
......
......@@ -16,6 +16,7 @@ enum class Operation {
WRITE,
WRITEV,
CLOSE,
SHUTDOWN,
LINK_TIMEOUT,
TIMEOUT,
CANCEL,
......
......@@ -101,5 +101,5 @@ void echo_client(std::string& host, std::string& port, const std::vector<std::st
}
}
shutdown(sockfd, SHUT_RDWR);
emper::io::shutdownAndWait(sockfd, SHUT_RDWR);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment