File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ project (send_recv)
2+
3+ include_directories (
4+ ${LIBIPC_PROJECT_DIR} /3rdparty)
5+
6+ file (GLOB SRC_FILES ./*.cpp)
7+ file (GLOB HEAD_FILES ./*.h)
8+
9+ add_executable (${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES} )
10+
11+ target_link_libraries (${PROJECT_NAME} ipc)
Original file line number Diff line number Diff line change 1+
2+ #include < iostream>
3+ #include < string>
4+ #include < thread>
5+ #include < chrono>
6+
7+ #include " libipc/ipc.h"
8+
9+ namespace {
10+
11+ void do_send (int size, int interval) {
12+ ipc::channel ipc {" ipc" , ipc::sender};
13+ std::string buffer (size, ' A' );
14+ while (true ) {
15+ std::cout << " send size: " << buffer.size () + 1 << " \n " ;
16+ ipc.send (buffer, 0 /* tm*/ );
17+ std::this_thread::sleep_for (std::chrono::milliseconds (interval));
18+ }
19+ }
20+
21+ void do_recv (int interval) {
22+ ipc::channel ipc {" ipc" , ipc::receiver};
23+ while (true ) {
24+ ipc::buff_t recv;
25+ for (int k = 1 ; recv.empty (); ++k) {
26+ std::cout << " recv waiting... " << k << " \n " ;
27+ recv = ipc.recv (interval);
28+ }
29+ std::cout << " recv size: " << recv.size () << " \n " ;
30+ }
31+ }
32+
33+ } // namespace
34+
35+ int main (int argc, char ** argv) {
36+ if (argc < 3 ) return -1 ;
37+ std::string mode {argv[1 ]};
38+ if (mode == " send" ) {
39+ if (argc < 4 ) return -1 ;
40+ do_send (std::stoi (argv[2 ]) /* size*/ ,
41+ std::stoi (argv[3 ]) /* interval*/ );
42+ } else if (mode == " recv" ) {
43+ do_recv (std::stoi (argv[2 ]) /* interval*/ );
44+ }
45+ return 0 ;
46+ }
You can’t perform that action at this time.
0 commit comments