ZMQ_CTX_SET(3)

πŸ’– ZMQ_CTX_SET(3) β€” the 0MQ manual, but make it cute πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about zmq_ctx_set β€” yes that's the one from the 0MQ manual, and yes she's lowkey iconic once you get to know her 🫢


✨ NAME ✨

zmq_ctx_set β€” set context options. that's it, that's the whole vibe check πŸ’…


🌸 SYNOPSIS 🌸

int zmq_ctx_set (void *context, int option_name, int option_value);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, the zmq_ctx_set() function shall set the option that option_name points at to the value living in option_value. that's the entire job description. main character energy, minimal effort, we respect it πŸ’œ

and here's the full menu of options zmq_ctx_set() accepts, no skips, no "you don't need to know that one":


πŸ‘‘ ZMQ_BLOCKY: Fix blocky behavior

by default the context will block, forever, on a zmq_ctx_term call. the whole assumption behind this behavior is that abrupt termination will cause message loss (rip your messages 😭). most real applications use some form of handshaking to make sure applications receive termination messages, and then terminate the context with ZMQ_LINGER set to zero on all sockets. this setting is literally just an easier way to get the same result. when ZMQ_BLOCKY is set to false, all new sockets are given a linger timeout of zero. you must still close all sockets before calling zmq_ctx_term β€” no shortcuts, bestie, that part is non-negotiable βœ‹

  • Default value β€” true (old behavior)

🧚 ZMQ_IO_THREADS: Set number of I/O threads

the ZMQ_IO_THREADS argument specifies the size of the 0MQ thread pool that handles I/O operations. if your application is only using the inproc transport for messaging you may set this to zero, otherwise set it to at least one. heads up though: this option only applies before creating any sockets on the context ⚠️

  • Default value β€” 1

🌈 ZMQ_THREAD_SCHED_POLICY: Set scheduling policy for I/O threads

the ZMQ_THREAD_SCHED_POLICY argument sets the scheduling policy for the internal context's thread pool. this option is not available on windows 🚫πŸͺŸ. supported values for this option can be found in the sched.h file, or at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. and again: this option only applies before creating any sockets on the context.

  • Default value β€” -1

⭐ ZMQ_THREAD_PRIORITY: Set scheduling priority for I/O threads

the ZMQ_THREAD_PRIORITY argument sets scheduling priority for the internal context's thread pool. this option is not available on windows. supported values for this option depend on the chosen scheduling policy. on Linux, when the scheduler policy is SCHED_OTHER, SCHED_IDLE or SCHED_BATCH, the OS scheduler will not use the thread priority but rather the thread "nice value"; in those cases, if ZMQ_THREAD_PRIORITY is set to a strictly positive value, the system call "nice" will be used to set the nice value to -20 (max priority) instead of adjusting the thread priority (which must be zero for those scheduling policies). details can be found in the sched.h file, or at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. this option only applies before creating any sockets on the context.

  • Default value β€” -1

πŸ’œ ZMQ_THREAD_AFFINITY_CPU_ADD: Add a CPU to list of affinity for I/O threads

the ZMQ_THREAD_AFFINITY_CPU_ADD argument adds a specific CPU to the affinity list for the internal context's thread pool. this option is only supported on Linux 🐧. this option only applies before creating any sockets on the context. the default affinity list is empty, which means that no explicit CPU-affinity will be set on the internal context's threads.

  • Default value β€” -1

πŸ“ ZMQ_THREAD_AFFINITY_CPU_REMOVE: Remove a CPU to list of affinity for I/O threads

the ZMQ_THREAD_AFFINITY_CPU_REMOVE argument removes a specific CPU to the affinity list for the internal context's thread pool. this option is only supported on Linux. this option only applies before creating any sockets on the context. the default affinity list is empty, which means that no explicit CPU-affinity will be set on the internal context's threads.

  • Default value β€” -1

πŸŽ€ ZMQ_THREAD_NAME_PREFIX: Set name prefix for I/O threads

the ZMQ_THREAD_NAME_PREFIX argument sets a numeric prefix to each thread created for the internal context's thread pool. this option is only supported on Linux. this option is useful to help debugging done via top -H or gdb; in case multiple processes on the system are using ZeroMQ it's useful to provide through this context option an application-specific prefix so you can tell apart the ZeroMQ background threads that belong to different processes. so basically: name your threads so you can find them in a crowd, iykyk πŸ”. this option only applies before creating any sockets on the context.

  • Default value β€” -1

πŸ”₯ ZMQ_MAX_MSGSZ: Set maximum message size

the ZMQ_MAX_MSGSZ argument sets the maximum allowed size of a message sent in the context. you can query the maximal allowed value with zmq_ctx_get(3) using the ZMQ_MAX_MSGSZ option.

  • Default value β€” INT_MAX
  • Maximum value β€” INT_MAX

πŸ™ˆ ZMQ_ZERO_COPY_RECV: Specify message decoding strategy

the ZMQ_ZERO_COPY_RECV argument specifies whether the message decoder should use a zero copy strategy when receiving messages. the zero copy strategy can lead to increased memory usage in some cases. this option allows you to use the older copying strategy. you can query the value of this option with zmq_ctx_get(3) using the ZMQ_ZERO_COPY_RECV option.

NOTE: in DRAFT state, not yet available in stable releases. πŸ‘€ she's not out yet bestie, don't go looking for her in your stable install.
  • Default value β€” 1

πŸ’… ZMQ_MAX_SOCKETS: Set maximum number of sockets

the ZMQ_MAX_SOCKETS argument sets the maximum number of sockets allowed on the context. you can query the maximal allowed value with zmq_ctx_get(3) using the ZMQ_SOCKET_LIMIT option.

  • Default value β€” 1023

🌸 ZMQ_IPV6: Set IPv6 option

the ZMQ_IPV6 argument sets the IPv6 value for all sockets created in the context from this point onwards. a value of 1 means IPv6 is enabled, while 0 means the socket will use only IPv4. when IPv6 is enabled, a socket will connect to, or accept connections from, both IPv4 and IPv6 hosts. dual-stack queen, we love her πŸ’–

  • Default value β€” 0

🫢 RETURN VALUE 🫢

the zmq_ctx_set() function returns zero if successful. otherwise it returns -1 and sets errno to one of the values defined below. sad girl hours 😭


πŸ’€ ERRORS πŸ’€

  • EINVAL β€” the requested option option_name is unknown. (translation: she has no idea what you just asked for.)

🌟 EXAMPLE 🌟

setting a limit on the number of sockets. so slay of her:

void *context = zmq_ctx_new ();
zmq_ctx_set (context, ZMQ_MAX_SOCKETS, 256);
int max_sockets = zmq_ctx_get (context, ZMQ_MAX_SOCKETS);
assert (max_sockets == 256);

πŸ¦„ SEE ALSO πŸ¦„

zmq_ctx_get(3) zmq(7)


πŸ’œ AUTHORS πŸ’œ

this page was written by the 0MQ community. to make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. (yes, they're accepting applications, the group chat is open 🫢)


and that's the whole page bestie β€” this manual page came to you from 0MQ 4.3.5, dated 10/09/2023, page name ZMQ_CTX_SET(3), in the 0MQ Manual. go forth and set your context options, no cap βœ¨πŸ’…πŸŽ€

πŸ“¦ where this page comes from