| | |
| | | body.set_data(str); |
| | | auto head(InitMsgHead(GetType(body), proc_id)); |
| | | msg.MakeRC(shm, head, body); |
| | | assert(msg.IsCounted()); |
| | | DEFER1(msg.Release(shm);); |
| | | |
| | | for (uint64_t i = 0; i < n; ++i) { |
| | |
| | | SharedMemory shm(shm_name, 1024 * 1024 * 50); |
| | | auto Avail = [&]() { return shm.get_free_memory(); }; |
| | | auto init_avail = Avail(); |
| | | ShmMsgQueue srv(shm, qlen); |
| | | ShmMsgQueue cli(shm, qlen); |
| | | ShmSocket srv(shm, qlen); |
| | | ShmSocket cli(shm, qlen); |
| | | |
| | | MsgI request_rc; |
| | | MsgRequestTopic req_body; |
| | |
| | | req_body.set_topic("topic"); |
| | | req_body.set_data(msg_content); |
| | | auto req_head(InitMsgHead(GetType(req_body), client_proc_id)); |
| | | return cli.Send(srv.Id(), req_head, req_body, 100); |
| | | return cli.Send(&srv.id(), req_head, req_body, 100); |
| | | }; |
| | | auto ReqRC = [&]() { return cli.Send(srv.Id(), request_rc, 1000); }; |
| | | auto ReqRC = [&]() { return cli.Send(&srv.id(), request_rc, 1000); }; |
| | | |
| | | if (!ReqRC()) { |
| | | printf("********** client send error.\n"); |
| | |
| | | } |
| | | MsgI msg; |
| | | BHMsgHead head; |
| | | if (!cli.Recv(msg, 1000)) { |
| | | if (!cli.SyncRecv(msg, head, 1000)) { |
| | | printf("********** client recv error.\n"); |
| | | } else { |
| | | DEFER1(msg.Release(shm)); |
| | |
| | | BHMsgHead req_head; |
| | | |
| | | while (!stop) { |
| | | if (srv.Recv(req, 100)) { |
| | | if (srv.SyncRecv(req, req_head, 100)) { |
| | | DEFER1(req.Release(shm)); |
| | | |
| | | if (req.ParseHead(req_head) && req_head.type() == kMsgTypeRequestTopic) { |
| | | auto &mqid = req_head.route()[0].mq_id(); |
| | | MQId src_id; |
| | |
| | | reply_body.set_topic("topic"); |
| | | reply_body.set_data(msg_content); |
| | | auto reply_head(InitMsgHead(GetType(reply_body), server_proc_id, req_head.msg_id())); |
| | | return srv.Send(src_id, reply_head, reply_body, 100); |
| | | return srv.Send(&src_id, reply_head, reply_body, 100); |
| | | }; |
| | | auto ReplyRC = [&]() { return srv.Send(src_id, reply_rc, 100); }; |
| | | auto ReplyRC = [&]() { return srv.Send(&src_id, reply_rc, 100); }; |
| | | |
| | | if (ReplyRC()) { |
| | | } |