| helics 3.6.1

Public Member Functions | Static Public Member Functions | List of all members
ZmqContextManager Class Reference

`#include <ZmqContextManager.h>`

## Public Member Functions
| ~ZmqContextManager ()
const std::string & | getName () const
zmq::context_t & | getBaseContext () const

## Static Public Member Functions
static std::shared_ptr< ZmqContextManager > | getContextPointer (const std::string &contextName=std::string{})
static zmq::context_t & | getContext (const std::string &contextName=std::string{})
static void | startContext (const std::string &contextName=std::string{})
static void | closeContext (const std::string &contextName=std::string{})
static bool | setContextToLeakOnDelete (const std::string &contextName=std::string{})
static bool | setContextToNotLeakOnDelete (const std::string &contextName=std::string{})

## Detailed Description

class defining a global context manager for all zmq usage

the zmq::context_t is stored in global structure so more than one can exist, but most use cases it is just the equivalent of a singleton

## Constructor & Destructor Documentation

## ◆ ~ZmqContextManager()

ZmqContextManager::~ZmqContextManager | ( |  | ) |

destructor

## Member Function Documentation

## ◆ closeContext()

void ZmqContextManager::closeContext | ( | const std::string & | contextName = `std::string{}` | ) |
| static

close a ZMQ context if it exists

## ◆ getBaseContext()

zmq::context_t& ZmqContextManager::getBaseContext | ( |  | ) | const
| inline

get a reference to the underlying zmq::context_t for use with cppzmq library calls

## ◆ getContext()

zmq::context_t & ZmqContextManager::getContext | ( | const std::string & | contextName = `std::string{}` | ) |
| static

get an underlying zmq::context_t reference by name

References getContextPointer().

## ◆ getContextPointer()

std::shared_ptr< ZmqContextManager > ZmqContextManager::getContextPointer | ( | const std::string & | contextName = `std::string{}` | ) |
| static

get a shared_ptr to the context by name

Referenced by getContext(), and helics::apps::zmqBrokerServer::stopServer().

## ◆ getName()

const std::string& ZmqContextManager::getName | ( |  | ) | const
| inline

get the name of the context

## ◆ setContextToLeakOnDelete()

bool ZmqContextManager::setContextToLeakOnDelete | ( | const std::string & | contextName = `std::string{}` | ) |
| static

tell the context to free the pointer and leak the memory on delete

You may ask why, well in windows systems when operating in a DLL if this context is closed after certain other operations that happen when the DLL is unlinked bad things can happen, and since in nearly all cases this happens at Shutdown leaking really doesn't matter that much, it also seem to be required when the zmq library is built with curve instead of turning off the encryption or with sodium, in that case there seems to be some issues in the zmq library itself when closing the context, causing some issue that eventually leads to something trying to access a deleted mutex on program shutdown. Which is annoying.

Returns
  true if the context was found and the flag set, false otherwise

## ◆ setContextToNotLeakOnDelete()

bool ZmqContextManager::setContextToNotLeakOnDelete | ( | const std::string & | contextName = `std::string{}` | ) |
| static

turn off the leak on delete mode

## ◆ startContext()

void ZmqContextManager::startContext | ( | const std::string & | contextName = `std::string{}` | ) |
| static

start a ZMQ context if it hasn't been started already

The documentation for this class was generated from the following files:

- ZmqContextManager.h
- ZmqContextManager.cpp