mirror of https://gitee.com/bigwinds/arangodb
137 lines
4.6 KiB
Groff
137 lines
4.6 KiB
Groff
'\" t
|
|
.\" Title: zsocket
|
|
.\" Author: [see the "AUTHORS" section]
|
|
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
|
|
.\" Date: 08/30/2011
|
|
.\" Manual: czmq Manual
|
|
.\" Source: czmq 1.1.0
|
|
.\" Language: English
|
|
.\"
|
|
.TH "ZSOCKET" "7" "08/30/2011" "czmq 1\&.1\&.0" "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"
|
|
zsocket \- working with 0MQ sockets
|
|
.SH "SYNOPSIS"
|
|
.sp
|
|
.nf
|
|
// This port range is defined by IANA for dynamic or private ports
|
|
// We use this when choosing a port for dynamic binding\&.
|
|
#define ZSOCKET_DYNFROM 0xc000
|
|
#define ZSOCKET_DYNTO 0xffff
|
|
|
|
// Create a new socket within our czmq context, replaces zmq_socket\&.
|
|
// If the socket is a SUB socket, automatically subscribes to everything\&.
|
|
// Use this to get automatic management of the socket at shutdown\&.
|
|
void *
|
|
zsocket_new (zctx_t *self, int type);
|
|
|
|
// Destroy a socket within our czmq context, replaces zmq_close\&.
|
|
void
|
|
zsocket_destroy (zctx_t *self, void *socket);
|
|
|
|
// Bind a socket to a formatted endpoint\&. If the port is specified as
|
|
// \*(Aq*\*(Aq, binds to any free port from ZSOCKET_DYNFROM to ZSOCKET_DYNTO
|
|
// and returns the actual port number used\&. Otherwise asserts that the
|
|
// bind succeeded with the specified port number\&. Always returns the
|
|
// port number if successful\&.
|
|
int
|
|
zsocket_bind (void *socket, const char *format, \&.\&.\&.);
|
|
|
|
// Connect a socket to a formatted endpoint
|
|
// Checks with assertion that the connect was valid
|
|
void
|
|
zsocket_connect (void *socket, const char *format, \&.\&.\&.);
|
|
|
|
// Returns socket type as printable constant string
|
|
char *
|
|
zsocket_type_str (void *socket);
|
|
|
|
// Self test of this class
|
|
int
|
|
zsocket_test (Bool verbose);
|
|
.fi
|
|
.SH "DESCRIPTION"
|
|
.sp
|
|
The zsocket class provides helper functions for 0MQ sockets\&. It doesn\(cqt wrap the 0MQ socket type, to avoid breaking all libzmq socket\-related calls\&. Automatically subscribes SUB sockets to ""\&.
|
|
.SH "EXAMPLE"
|
|
.PP
|
|
\fBFrom zsocket_test method\fR.
|
|
.sp
|
|
.if n \{\
|
|
.RS 4
|
|
.\}
|
|
.nf
|
|
zctx_t *ctx = zctx_new ();
|
|
|
|
// Create a detached thread, let it run
|
|
char *interf = "*";
|
|
char *domain = "localhost";
|
|
int service = 5560;
|
|
|
|
void *writer = zsocket_new (ctx, ZMQ_PUSH);
|
|
void *reader = zsocket_new (ctx, ZMQ_PULL);
|
|
assert (streq (zsocket_type_str (writer), "PUSH"));
|
|
assert (streq (zsocket_type_str (reader), "PULL"));
|
|
int rc = zsocket_bind (writer, "tcp://%s:%d", interf, service);
|
|
assert (rc == service);
|
|
zsocket_connect (reader, "tcp://%s:%d", domain, service);
|
|
zstr_send (writer, "HELLO");
|
|
char *message = zstr_recv (reader);
|
|
assert (message);
|
|
assert (streq (message, "HELLO"));
|
|
free (message);
|
|
|
|
int port = zsocket_bind (writer, "tcp://%s:*", interf);
|
|
assert (port >= ZSOCKET_DYNFROM && port <= ZSOCKET_DYNTO);
|
|
|
|
zsocket_destroy (ctx, writer);
|
|
zctx_destroy (&ctx);
|
|
.fi
|
|
.if n \{\
|
|
.RE
|
|
.\}
|
|
.sp
|
|
.SH "SEE ALSO"
|
|
.sp
|
|
\fBczmq\fR(7)
|
|
.SH "AUTHORS"
|
|
.sp
|
|
The czmq manual was written by Pieter Hintjens<\m[blue]\fBph@imatix\&.com\fR\m[]\&\s-2\u[1]\d\s+2>\&.
|
|
.SH "RESOURCES"
|
|
.sp
|
|
Main web site: \m[blue]\fBhttp://czmq\&.zeromq\&.org/\fR\m[]
|
|
.sp
|
|
Report bugs to the 0MQ development mailing list: <\m[blue]\fBzeromq\-dev@lists\&.zeromq\&.org\fR\m[]\&\s-2\u[2]\d\s+2>
|
|
.SH "COPYRIGHT"
|
|
.sp
|
|
Copyright (c) 1991\-2010 iMatix Corporation and contributors\&. License LGPLv3+: GNU LGPL 3 or later <\m[blue]\fBhttp://gnu\&.org/licenses/lgpl\&.html\fR\m[]>\&. This is free software: you are free to change it and redistribute it\&. There is NO WARRANTY, to the extent permitted by law\&. For details see the files COPYING and COPYING\&.LESSER included with the czmq distribution\&.
|
|
.SH "NOTES"
|
|
.IP " 1." 4
|
|
ph@imatix.com
|
|
.RS 4
|
|
\%mailto:ph@imatix.com
|
|
.RE
|
|
.IP " 2." 4
|
|
zeromq-dev@lists.zeromq.org
|
|
.RS 4
|
|
\%mailto:zeromq-dev@lists.zeromq.org
|
|
.RE
|