refactor to more idiomatic RAII

* FairMQTransportFactoryZMQ: move the config invariant
    initialization to ctor
  * FairMQChannel: add new ctor that creates usable channel
  * FairMQSocket*: close sockets in dtor
  * FairMQTransportFactory*: terminate context in dtor
  * FairMQChannel: add Bind/Connect facades (for explicit control, e.g. timing)
This commit is contained in:
Dennis Klein
2017-05-14 17:10:57 +02:00
committed by Mohammad Al-Turany
parent 87252edbe0
commit 3205e0c378
12 changed files with 78 additions and 55 deletions

View File

@@ -33,6 +33,11 @@ FairMQTransportFactoryZMQ::FairMQTransportFactoryZMQ()
LOG(ERROR) << "failed creating context, reason: " << zmq_strerror(errno);
exit(EXIT_FAILURE);
}
if (zmq_ctx_set(fContext, ZMQ_MAX_SOCKETS, 10000) != 0)
{
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
}
}
void FairMQTransportFactoryZMQ::Initialize(const FairMQProgOptions* config)
@@ -51,12 +56,6 @@ void FairMQTransportFactoryZMQ::Initialize(const FairMQProgOptions* config)
{
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
}
// Set the maximum number of allowed sockets on the context.
if (zmq_ctx_set(fContext, ZMQ_MAX_SOCKETS, 10000) != 0)
{
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
}
}
FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage() const
@@ -130,3 +129,8 @@ void FairMQTransportFactoryZMQ::Terminate()
LOG(ERROR) << "shmem: Terminate(): context now available for shutdown";
}
}
FairMQTransportFactoryZMQ::~FairMQTransportFactoryZMQ()
{
Terminate();
}