mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
38 lines
696 B
C++
38 lines
696 B
C++
#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;
|
|
}
|