You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					222 lines
				
				7.1 KiB
			
		
		
			
		
	
	
					222 lines
				
				7.1 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								'\" t
							 | 
						||
| 
								 | 
							
								.\"     Title: zctx
							 | 
						||
| 
								 | 
							
								.\"    Author: [see the "AUTHORS" section]
							 | 
						||
| 
								 | 
							
								.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
							 | 
						||
| 
								 | 
							
								.\"      Date: 09/14/2016
							 | 
						||
| 
								 | 
							
								.\"    Manual: CZMQ Manual
							 | 
						||
| 
								 | 
							
								.\"    Source: CZMQ 3.0.2
							 | 
						||
| 
								 | 
							
								.\"  Language: English
							 | 
						||
| 
								 | 
							
								.\"
							 | 
						||
| 
								 | 
							
								.TH "ZCTX" "3" "09/14/2016" "CZMQ 3\&.0\&.2" "CZMQ Manual"
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" * Define some portability stuff
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
							 | 
						||
| 
								 | 
							
								.\" http://bugs.debian.org/507673
							 | 
						||
| 
								 | 
							
								.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
							 | 
						||
| 
								 | 
							
								.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
							 | 
						||
| 
								 | 
							
								.ie \n(.g .ds Aq \(aq
							 | 
						||
| 
								 | 
							
								.el       .ds Aq '
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" * set default formatting
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" disable hyphenation
							 | 
						||
| 
								 | 
							
								.nh
							 | 
						||
| 
								 | 
							
								.\" disable justification (adjust text to left margin only)
							 | 
						||
| 
								 | 
							
								.ad l
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.\" * MAIN CONTENT STARTS HERE *
							 | 
						||
| 
								 | 
							
								.\" -----------------------------------------------------------------
							 | 
						||
| 
								 | 
							
								.SH "NAME"
							 | 
						||
| 
								 | 
							
								zctx \- working with 0MQ contexts (deprecated)
							 | 
						||
| 
								 | 
							
								.SH "SYNOPSIS"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.nf
							 | 
						||
| 
								 | 
							
								//  Create new context, returns context object, replaces zmq_init
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT zctx_t *
							 | 
						||
| 
								 | 
							
								    zctx_new (void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Destroy context and all sockets in it, replaces zmq_term
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_destroy (zctx_t **self_p);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Create new shadow context, returns context object
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT zctx_t *
							 | 
						||
| 
								 | 
							
								    zctx_shadow (zctx_t *self);
							 | 
						||
| 
								 | 
							
								//  Raise default I/O threads from 1, for crazy heavy applications
							 | 
						||
| 
								 | 
							
								//  The rule of thumb is one I/O thread per gigabyte of traffic in
							 | 
						||
| 
								 | 
							
								//  or out\&. Call this method before creating any sockets on the context,
							 | 
						||
| 
								 | 
							
								//  or calling zctx_shadow, or the setting will have no effect\&.
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_set_iothreads (zctx_t *self, int iothreads);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Set msecs to flush sockets when closing them, see the ZMQ_LINGER
							 | 
						||
| 
								 | 
							
								//  man page section for more details\&. By default, set to zero, so
							 | 
						||
| 
								 | 
							
								//  any in\-transit messages are discarded when you destroy a socket or
							 | 
						||
| 
								 | 
							
								//  a context\&.
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_set_linger (zctx_t *self, int linger);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Set initial high\-water mark for inter\-thread pipe sockets\&. Note that
							 | 
						||
| 
								 | 
							
								//  this setting is separate from the default for normal sockets\&. You
							 | 
						||
| 
								 | 
							
								//  should change the default for pipe sockets *with care*\&. Too low values
							 | 
						||
| 
								 | 
							
								//  will cause blocked threads, and an infinite setting can cause memory
							 | 
						||
| 
								 | 
							
								//  exhaustion\&. The default, no matter the underlying ZeroMQ version, is
							 | 
						||
| 
								 | 
							
								//  1,000\&.
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_set_pipehwm (zctx_t *self, int pipehwm);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Set initial send HWM for all new normal sockets created in context\&.
							 | 
						||
| 
								 | 
							
								//  You can set this per\-socket after the socket is created\&.
							 | 
						||
| 
								 | 
							
								//  The default, no matter the underlying ZeroMQ version, is 1,000\&.
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_set_sndhwm (zctx_t *self, int sndhwm);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Set initial receive HWM for all new normal sockets created in context\&.
							 | 
						||
| 
								 | 
							
								//  You can set this per\-socket after the socket is created\&.
							 | 
						||
| 
								 | 
							
								//  The default, no matter the underlying ZeroMQ version, is 1,000\&.
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_set_rcvhwm (zctx_t *self, int rcvhwm);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Return low\-level 0MQ context object, will be NULL before first socket
							 | 
						||
| 
								 | 
							
								//  is created\&. Use with care\&.
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void *
							 | 
						||
| 
								 | 
							
								    zctx_underlying (zctx_t *self);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Self test of this class
							 | 
						||
| 
								 | 
							
								CZMQ_EXPORT void
							 | 
						||
| 
								 | 
							
								    zctx_test (bool verbose);
							 | 
						||
| 
								 | 
							
								.fi
							 | 
						||
| 
								 | 
							
								.SH "DESCRIPTION"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								The zctx class wraps 0MQ contexts\&. It manages open sockets in the context and automatically closes these before terminating the context\&. It provides a simple way to set the linger timeout on sockets, and configure contexts for number of I/O threads\&. Sets\-up signal (interrupt) handling for the process\&.
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								The zctx class has these main features:
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.ie n \{\
							 | 
						||
| 
								 | 
							
								\h'-04'\(bu\h'+03'\c
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.el \{\
							 | 
						||
| 
								 | 
							
								.sp -1
							 | 
						||
| 
								 | 
							
								.IP \(bu 2.3
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								Tracks all open sockets and automatically closes them before calling zmq_term()\&. This avoids an infinite wait on open sockets\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.ie n \{\
							 | 
						||
| 
								 | 
							
								\h'-04'\(bu\h'+03'\c
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.el \{\
							 | 
						||
| 
								 | 
							
								.sp -1
							 | 
						||
| 
								 | 
							
								.IP \(bu 2.3
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								Automatically configures sockets with a ZMQ_LINGER timeout you can define, and which defaults to zero\&. The default behavior of zctx is therefore like 0MQ/2\&.0, immediate termination with loss of any pending messages\&. You can set any linger timeout you like by calling the zctx_set_linger() method\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.ie n \{\
							 | 
						||
| 
								 | 
							
								\h'-04'\(bu\h'+03'\c
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.el \{\
							 | 
						||
| 
								 | 
							
								.sp -1
							 | 
						||
| 
								 | 
							
								.IP \(bu 2.3
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								Moves the iothreads configuration to a separate method, so that default usage is 1 I/O thread\&. Lets you configure this value\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.ie n \{\
							 | 
						||
| 
								 | 
							
								\h'-04'\(bu\h'+03'\c
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.el \{\
							 | 
						||
| 
								 | 
							
								.sp -1
							 | 
						||
| 
								 | 
							
								.IP \(bu 2.3
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								Sets up signal (SIGINT and SIGTERM) handling so that blocking calls such as zmq_recv() and zmq_poll() will return when the user presses Ctrl\-C\&.
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.if n \{\
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.it 1 an-trap
							 | 
						||
| 
								 | 
							
								.nr an-no-space-flag 1
							 | 
						||
| 
								 | 
							
								.nr an-break-flag 1
							 | 
						||
| 
								 | 
							
								.br
							 | 
						||
| 
								 | 
							
								.ps +1
							 | 
						||
| 
								 | 
							
								\fBNote\fR
							 | 
						||
| 
								 | 
							
								.ps -1
							 | 
						||
| 
								 | 
							
								.br
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								this class is deprecated in favor of zsock, which does not expose contexts in the API at all\&. All zsock instances use the same global context\&.
							 | 
						||
| 
								 | 
							
								.sp .5v
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.SH "EXAMPLE"
							 | 
						||
| 
								 | 
							
								.PP
							 | 
						||
| 
								 | 
							
								\fBFrom zctx_test method\fR. 
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.if n \{\
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.nf
							 | 
						||
| 
								 | 
							
								//  Create and destroy a context without using it
							 | 
						||
| 
								 | 
							
								zctx_t *ctx = zctx_new ();
							 | 
						||
| 
								 | 
							
								assert (ctx);
							 | 
						||
| 
								 | 
							
								zctx_destroy (&ctx);
							 | 
						||
| 
								 | 
							
								assert (ctx == NULL);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//  Create a context with many busy sockets, destroy it
							 | 
						||
| 
								 | 
							
								ctx = zctx_new ();
							 | 
						||
| 
								 | 
							
								assert (ctx);
							 | 
						||
| 
								 | 
							
								zctx_set_iothreads (ctx, 1);
							 | 
						||
| 
								 | 
							
								zctx_set_linger (ctx, 5);       //  5 msecs
							 | 
						||
| 
								 | 
							
								void *s1 = zctx__socket_new (ctx, ZMQ_PAIR);
							 | 
						||
| 
								 | 
							
								assert (s1);
							 | 
						||
| 
								 | 
							
								void *s2 = zctx__socket_new (ctx, ZMQ_XREQ);
							 | 
						||
| 
								 | 
							
								assert (s2);
							 | 
						||
| 
								 | 
							
								void *s3 = zctx__socket_new (ctx, ZMQ_REQ);
							 | 
						||
| 
								 | 
							
								assert (s3);
							 | 
						||
| 
								 | 
							
								void *s4 = zctx__socket_new (ctx, ZMQ_REP);
							 | 
						||
| 
								 | 
							
								assert (s4);
							 | 
						||
| 
								 | 
							
								void *s5 = zctx__socket_new (ctx, ZMQ_PUB);
							 | 
						||
| 
								 | 
							
								assert (s5);
							 | 
						||
| 
								 | 
							
								void *s6 = zctx__socket_new (ctx, ZMQ_SUB);
							 | 
						||
| 
								 | 
							
								assert (s6);
							 | 
						||
| 
								 | 
							
								int rc = zsocket_connect (s1, "tcp://127\&.0\&.0\&.1:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								rc = zsocket_connect (s2, "tcp://127\&.0\&.0\&.1:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								rc = zsocket_connect (s3, "tcp://127\&.0\&.0\&.1:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								rc = zsocket_connect (s4, "tcp://127\&.0\&.0\&.1:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								rc = zsocket_connect (s5, "tcp://127\&.0\&.0\&.1:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								rc = zsocket_connect (s6, "tcp://127\&.0\&.0\&.1:5555");
							 | 
						||
| 
								 | 
							
								assert (rc == 0);
							 | 
						||
| 
								 | 
							
								assert (zctx_underlying (ctx));
							 | 
						||
| 
								 | 
							
								zctx_destroy (&ctx);
							 | 
						||
| 
								 | 
							
								.fi
							 | 
						||
| 
								 | 
							
								.if n \{\
							 | 
						||
| 
								 | 
							
								.RE
							 | 
						||
| 
								 | 
							
								.\}
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								.SH "AUTHORS"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								The czmq manual was written by the authors in the AUTHORS file\&.
							 | 
						||
| 
								 | 
							
								.SH "RESOURCES"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								Main web site: \m[blue]\fB\%\fR\m[]
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								Report bugs to the email <\m[blue]\fBzeromq\-dev@lists\&.zeromq\&.org\fR\m[]\&\s-2\u[1]\d\s+2>
							 | 
						||
| 
								 | 
							
								.SH "COPYRIGHT"
							 | 
						||
| 
								 | 
							
								.sp
							 | 
						||
| 
								 | 
							
								Copyright (c) 1991\-2012 iMatix Corporation \-\- http://www\&.imatix\&.com Copyright other contributors as noted in the AUTHORS file\&. This file is part of CZMQ, the high\-level C binding for 0MQ: http://czmq\&.zeromq\&.org This Source Code Form is subject to the terms of the Mozilla Public License, v\&. 2\&.0\&. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla\&.org/MPL/2\&.0/\&. LICENSE included with the czmq distribution\&.
							 | 
						||
| 
								 | 
							
								.SH "NOTES"
							 | 
						||
| 
								 | 
							
								.IP " 1." 4
							 | 
						||
| 
								 | 
							
								zeromq-dev@lists.zeromq.org
							 | 
						||
| 
								 | 
							
								.RS 4
							 | 
						||
| 
								 | 
							
								\%mailto:zeromq-dev@lists.zeromq.org
							 | 
						||
| 
								 | 
							
								.RE
							 |