mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 17:26:48 +08:00
channel::send will wait for a while & return false if there is no receiver
This commit is contained in:
parent
0eb61b8745
commit
b815a5e50f
@ -134,7 +134,8 @@ std::size_t channel::recv_count() const {
|
||||
|
||||
template <typename... P>
|
||||
inline bool channel_send(route& rt, P&&... params) {
|
||||
while (rt.recv_count() == 0) {
|
||||
for (int k = 0; rt.recv_count() == 0; ++k) {
|
||||
if (k >= 1024) return false;
|
||||
std::this_thread::yield();
|
||||
}
|
||||
return rt.send(params...); // no need std::forward
|
||||
|
||||
@ -425,7 +425,7 @@ void Unit::test_channel_rtt() {
|
||||
auto dd = cc.recv();
|
||||
if (dd.size() < 2) return;
|
||||
// std::cout << "recving: " << i << "-[" << dd.size() << "]" << std::endl;
|
||||
cc.send(ipc::buff_t { 'a' });
|
||||
while (!cc.send(ipc::buff_t { 'a' })) {}
|
||||
}
|
||||
}};
|
||||
|
||||
@ -434,7 +434,7 @@ void Unit::test_channel_rtt() {
|
||||
sw.start();
|
||||
for (std::size_t i = 0; i < LoopCount; ++i) {
|
||||
// std::cout << "sending: " << i << "-[" << datas__[i].size() << "]" << std::endl;
|
||||
cc.send(datas__[i]);
|
||||
while (!cc.send(datas__[i])) {}
|
||||
/*auto dd = */cc.recv();
|
||||
// if (dd.size() != 1 || dd[0] != 'a') {
|
||||
// QVERIFY(false);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user