mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
add demo-chat
This commit is contained in:
parent
bffa8ae6b8
commit
e88a4cf865
17
build/chat.pro
Normal file
17
build/chat.pro
Normal file
@ -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
|
||||||
37
demo/chat/main.cpp
Normal file
37
demo/chat/main.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#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<char const *>(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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user