void *zmq_init (int app_threads_, int io_threads_, int flags_) { // There should be at least a single application thread managed // by the dispatcher. There's no need for I/O threads if 0MQ is used // only for inproc messaging if (app_threads_ < 1 || io_threads_ < 0 || app_threads_ > 63 || io_threads_ > 63) { errno = EINVAL; return NULL; } #if defined ZMQ_HAVE_OPENPGM // Unfortunately, OpenPGM doesn't support refcounted init/shutdown, thus, // let's fail if it was initialised beforehand. zmq_assert (!pgm_supported ()); // Init PGM transport. Ensure threading and timer are enabled. Find PGM // protocol ID. Note that if you want to use gettimeofday and sleep for // openPGM timing, set environment variables PGM_TIMER to "GTOD" and // PGM_SLEEP to "USLEEP". GError *pgm_error = NULL; int rc = pgm_init (&pgm_error); if (rc != TRUE) { if (pgm_error->domain == PGM_IF_ERROR && ( pgm_error->code == PGM_IF_ERROR_INVAL || pgm_error->code == PGM_IF_ERROR_XDEV || pgm_error->code == PGM_IF_ERROR_NODEV || pgm_error->code == PGM_IF_ERROR_NOTUNIQ || pgm_error->code == PGM_IF_ERROR_ADDRFAMILY || pgm_error->code == PGM_IF_ERROR_FAMILY || pgm_error->code == PGM_IF_ERROR_NODATA || pgm_error->code == PGM_IF_ERROR_NONAME || pgm_error->code == PGM_IF_ERROR_SERVICE)) { g_error_free (pgm_error); errno = EINVAL; return NULL; } zmq_assert (false); } #endif // Create 0MQ context. zmq::dispatcher_t *dispatcher = new (std::nothrow) zmq::dispatcher_t ( app_threads_, io_threads_, flags_); zmq_assert (dispatcher); return (void*) dispatcher; }
// TODO: app_threads and flags parameters are not used anymore... // Reflect this in the API/ABI. void *zmq_init (int /*app_threads_*/, int io_threads_, int /*flags_*/) { if (io_threads_ < 0) { errno = EINVAL; return NULL; } #if defined ZMQ_HAVE_OPENPGM // Unfortunately, OpenPGM doesn't support refcounted init/shutdown, thus, // let's fail if it was initialised beforehand. zmq_assert (!pgm_supported ()); // Init PGM transport. Ensure threading and timer are enabled. Find PGM // protocol ID. Note that if you want to use gettimeofday and sleep for // openPGM timing, set environment variables PGM_TIMER to "GTOD" and // PGM_SLEEP to "USLEEP". GError *pgm_error = NULL; int rc = pgm_init (&pgm_error); if (rc != TRUE) { if (pgm_error->domain == PGM_IF_ERROR && ( pgm_error->code == PGM_IF_ERROR_INVAL || pgm_error->code == PGM_IF_ERROR_XDEV || pgm_error->code == PGM_IF_ERROR_NODEV || pgm_error->code == PGM_IF_ERROR_NOTUNIQ || pgm_error->code == PGM_IF_ERROR_ADDRFAMILY || pgm_error->code == PGM_IF_ERROR_FAMILY || pgm_error->code == PGM_IF_ERROR_NODATA || pgm_error->code == PGM_IF_ERROR_NONAME || pgm_error->code == PGM_IF_ERROR_SERVICE)) { g_error_free (pgm_error); errno = EINVAL; return NULL; } zmq_assert (false); } #endif // Create 0MQ context. zmq::ctx_t *ctx = new (std::nothrow) zmq::ctx_t ((uint32_t) io_threads_); zmq_assert (ctx); return (void*) ctx; }