summaryrefslogtreecommitdiff
path: root/modules/io/examples/echo_client.cpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-03-08 19:57:18 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-03-08 19:57:18 +0100
commit21f52f91ddbaf409c45663a71d84033fbde22198 (patch)
treeebe7d664b89e506240ec255f878feb7b6bfaf5d5 /modules/io/examples/echo_client.cpp
parent7a097bd3bdb288342cc7314f6942347274811030 (diff)
io: Preparing example env
Diffstat (limited to 'modules/io/examples/echo_client.cpp')
-rw-r--r--modules/io/examples/echo_client.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/io/examples/echo_client.cpp b/modules/io/examples/echo_client.cpp
new file mode 100644
index 0000000..9e56f6b
--- /dev/null
+++ b/modules/io/examples/echo_client.cpp
@@ -0,0 +1,35 @@
+#include "../c++/io.hpp"
+
+#include <iostream>
+
+#include "echo.hpp"
+
+int main(){
+ /**
+ * Create EventLoop
+ * Setup EventPort to the outside world
+ * And setup the io comms to the outside.
+ */
+ auto eo_aio = saw::setup_async_io();
+ if(eo_aio.is_error()){
+ auto& err = eo_aio.get_error();
+ std::cerr<<err.get_message()<<std::endl;
+ return err.get_id();
+ }
+ auto& aio = eo_aio.get_value();
+ /**
+ * Make the event loop the current event loop on this thread
+ */
+ saw::wait_scope wait_scope{aio.event_loop};
+
+ bool keep_running = true;
+ aio.event_port.on_signal(saw::Signal::Terminate).then([&keep_running](){
+ keep_running = false;
+ }).detach();
+
+ while(keep_running){
+ wait_scope.wait();
+ }
+
+ return 0;
+}