diff options
author | Michele Papalini <micpapal@cisco.com> | 2019-10-31 15:40:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2019-10-31 15:40:04 +0000 |
commit | bf592d6d757b2f258a4ffbc516c88eff275fbfcf (patch) | |
tree | 6dbd4fa1d51a76f6e5012f83bab64e0b6f9b2194 /libtransport/src/hicn/transport/interfaces/socket_consumer.h | |
parent | 7b8858d2b88e911371745bf01a8c5d9dc0915d3b (diff) | |
parent | 2fcb8ce4599ab94178aae1ac9f9ff800fd25cd0a (diff) |
Merge "[HICN-354] Fixed bug on raaqm when reassemblying packets"
Diffstat (limited to 'libtransport/src/hicn/transport/interfaces/socket_consumer.h')
-rw-r--r-- | libtransport/src/hicn/transport/interfaces/socket_consumer.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/libtransport/src/hicn/transport/interfaces/socket_consumer.h b/libtransport/src/hicn/transport/interfaces/socket_consumer.h index e3620b269..eceee2d34 100644 --- a/libtransport/src/hicn/transport/interfaces/socket_consumer.h +++ b/libtransport/src/hicn/transport/interfaces/socket_consumer.h @@ -282,9 +282,36 @@ class ConsumerSocket : public BaseSocket { ConsumerTimerCallback **socket_option_value); protected: + // If the thread calling lambda_func is not the same of io_service, this + // function reschedule the function on it template <typename Lambda, typename arg2> int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value, - Lambda lambda_func); + Lambda lambda_func) { + // To enforce type check + std::function<int(int, arg2)> func = lambda_func; + int result = SOCKET_OPTION_SET; + if (transport_protocol_->isRunning()) { + std::mutex mtx; + /* Condition variable for the wait */ + std::condition_variable cv; + bool done = false; + io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv, + &result, &done, &func]() { + std::unique_lock<std::mutex> lck(mtx); + done = true; + result = func(socket_option_key, socket_option_value); + cv.notify_all(); + }); + std::unique_lock<std::mutex> lck(mtx); + if (!done) { + cv.wait(lck); + } + } else { + result = func(socket_option_key, socket_option_value); + } + + return result; + } private: asio::io_service internal_io_service_; |