From e88a4cf865b32631620a5062765da8a94c692e28 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Wed, 13 Feb 2019 15:48:55 +0800 Subject: [PATCH] add demo-chat --- build/chat.pro | 17 +++++++++++++++++ demo/chat/main.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 build/chat.pro create mode 100644 demo/chat/main.cpp diff --git a/build/chat.pro b/build/chat.pro new file mode 100644 index 0000000..8acbdfb --- /dev/null +++ b/build/chat.pro @@ -0,0 +1,17 @@ +TEMPLATE = app + +CONFIG += console +CONFIG += c++14 c++1z # may be useless +CONFIG -= app_bundle +CONFIG -= qt + +DESTDIR = ../output + +INCLUDEPATH += \ + ../include + +SOURCES += \ + ../demo/chat/main.cpp + +LIBS += \ + -L$${DESTDIR} -lipc diff --git a/demo/chat/main.cpp b/demo/chat/main.cpp new file mode 100644 index 0000000..c560aae --- /dev/null +++ b/demo/chat/main.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +#include "ipc.h" + +namespace { + +char name__[] = "ipc-chat"; +char quit__[] = "q"; + +} // namespace + +int main() { + std::string buf; + ipc::channel cc { name__ }; + + std::thread r {[] { + ipc::channel cc { name__ }; + while (1) { + auto buf = cc.recv(); + if (buf.empty()) continue; + std::string dat { static_cast(buf.data()), buf.size() - 1 }; + if (dat == quit__) return; + std::cout << dat << std::endl; + } + }}; + + while (1) { + std::cin >> buf; + cc.send(buf); + if (buf == quit__) break; + } + + r.join(); + return 0; +}