diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-09-22 18:06:51 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-09-22 18:06:51 +0200 |
| commit | 676586f2034ff112b309dccc430893d73e919191 (patch) | |
| tree | 2571918ca87edde3fcb4cd5955a6051d535d57fa /apps | |
| parent | 1212a302b500c37420613086a1b85f0659f09d57 (diff) | |
| download | ttwhy-676586f2034ff112b309dccc430893d73e919191.tar.xz ttwhy-676586f2034ff112b309dccc430893d73e919191.zip | |
apps: extract applications
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/echo.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/apps/echo.cpp b/apps/echo.cpp new file mode 100644 index 0000000..ab635a7 --- /dev/null +++ b/apps/echo.cpp @@ -0,0 +1,36 @@ +#include <asio.hpp> +#include <asio/experimental/awaitable_operators.hpp> + +#include <stdio.h> + +import ttwhy.io; +import ttwhy.routers; + +auto app(int in, int out, int error) -> asio::awaitable<void> +{ + using namespace asio::experimental::awaitable_operators; + + auto terminal_attributes = ttwhy::io::scoped_attributes{fileno(stdin)} // + .canonical_mode(false) + .echo(false); + + auto executor = co_await asio::this_coro::executor; + + auto input_stream = asio::posix::stream_descriptor{executor, in}; + auto output_stream = asio::posix::stream_descriptor{executor, out}; + auto error_stream = asio::posix::stream_descriptor{executor, error}; + + auto router = ttwhy::routers::echo{output_stream}; + + co_await (ttwhy::io::handle_signals(error_stream, terminal_attributes) || + ttwhy::io::read_events(input_stream, router)); +} + +auto main() -> int +{ + auto context = asio::io_context{}; + + asio::co_spawn(context, app(::fileno(::stdin), ::fileno(::stdout), ::fileno(::stderr)), asio::detached); + + context.run(); +} |
