From 1b52f1cb8c47dd2c0195d2fd65d7b6a4c2f10704 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期一, 12 四月 2021 18:29:41 +0800
Subject: [PATCH] add fail-resend support.

---
 src/socket.h |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/socket.h b/src/socket.h
index ee25d81..5973ab6 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -77,7 +77,7 @@
 	template <class Body>
 	bool Send(const void *valid_remote, const BHMsgHead &head, const Body &body, const int timeout_ms, const RecvCB &cb)
 	{
-		auto DoSend = [&](MsgI &msg) { return mq().Send(*static_cast<const MQId *>(valid_remote), msg, timeout_ms, [&]() { async_cbs_->Add(head.msg_id(), cb); }); };
+		auto DoSend = [&](MsgI &msg) { return mq().Send(*static_cast<const MQId *>(valid_remote), msg, timeout_ms, [&]() { per_msg_cbs_->Add(head.msg_id(), cb); }); };
 		MsgI msg;
 		return msg.Make(shm(), head, body) && SendImpl(msg, timeout_ms, DoSend);
 	}
@@ -109,12 +109,15 @@
 					reply.swap(msg);
 					reply_head.Swap(&head);
 					st->cv.notify_one();
-				} else {
+				} else { // ignore
 				}
 			};
 
 			std::unique_lock<std::mutex> lk(st->mutex);
 			bool sendok = Send(remote, head, body, timeout_ms, OnRecv);
+			if (!sendok) {
+				printf("send timeout\n");
+			}
 			if (sendok && st->cv.wait_until(lk, endtime) == std::cv_status::no_timeout) {
 				return true;
 			} else {
@@ -161,7 +164,7 @@
 		}
 	};
 
-	Synced<AsyncCBs> async_cbs_;
+	Synced<AsyncCBs> per_msg_cbs_;
 };
 
 #endif // end of include guard: SOCKET_GWTJHBPO

--
Gitblit v1.8.0