Use the builtin sync capability of the transport object.
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/vespalib/util/gate.h>
#include <vespa/fastos/thread.h>
#include <thread>
@@ -32,36 +31,6 @@ namespace mbus {
namespace {
-/**
- * Implements a helper class for {@link RPCNetwork#sync()}. It provides a
- * blocking method {@link #await()} that will wait until the internal state
- * of this object is set to 'done'. By scheduling this task in the network
- * thread and then calling this method, we achieve handshaking with the network
- * thread.
- */
-class SyncTask : public FNET_Task {
-private:
- vespalib::Gate _gate;
-
-public:
- SyncTask(FNET_Scheduler &s) :
- FNET_Task(&s),
- _gate() {
- ScheduleNow();
- }
- ~SyncTask() override {
- Kill();
- }
-
- void await() {
- _gate.await();
- }
-
- void PerformTask() override {
- _gate.countDown();
- }
-};
-
struct TargetPoolTask : public FNET_Task {
RPCTargetPool &_pool;
@@ -412,8 +381,8 @@ RPCNetwork::send(RPCNetwork::SendContext &ctx)
void
RPCNetwork::sync()
{
- SyncTask task(_scheduler);
- task.await();
+ _transport->sync(); // Ensure transport loop run at least once to execute task scheduled for NOW
+ _transport->sync(); // And then once more to ensure they are all done.
}
void
