zmq-usually use api

为啥 zmq 的文档找起来这么费劲,4.0.x

zsocket_new

//  Create a new socket within our CZMQ context, replaces zmq_socket.
// Use this to get automatic management of the socket at shutdown.
// Note: SUB sockets do not automatically subscribe to everything; you
// must set filters explicitly.
CZMQ_EXPORT void * zsocket_new (zctx_t *self, int type);

zsocket_bind

//  Bind a socket to a formatted endpoint. If the port is specified as
// '*', 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.
CZMQ_EXPORT int zsocket_bind (void *self, const char *format, ...);

thread

zactor

//  This is a stable class, and may not change except for emergencies. It
// is provided in stable builds.
// This class has draft methods, which may change over time. They are not
// in stable releases, by default. Use --enable-drafts to enable.
// Actors get a pipe and arguments from caller
typedef void (zactor_fn) (
zsock_t *pipe, void *args);

// Create a new actor passing arbitrary arguments reference.
CZMQ_EXPORT zactor_t *
zactor_new (zactor_fn task, void *args);

// Destroy an actor.
CZMQ_EXPORT void
zactor_destroy (zactor_t **self_p);

// Send a zmsg message to the actor, take ownership of the message
// and destroy when it has been sent.
CZMQ_EXPORT int
zactor_send (zactor_t *self, zmsg_t **msg_p);

// Receive a zmsg message from the actor. Returns NULL if the actor
// was interrupted before the message could be received, or if there
// was a timeout on the actor.
// Caller owns return value and must destroy it when done.
CZMQ_EXPORT zmsg_t *
zactor_recv (zactor_t *self);

// Probe the supplied object, and report if it looks like a zactor_t.
CZMQ_EXPORT bool
zactor_is (void *self);

// Probe the supplied reference. If it looks like a zactor_t instance,
// return the underlying libzmq actor handle; else if it looks like
// a libzmq actor handle, return the supplied value.
CZMQ_EXPORT void *
zactor_resolve (void *self);

// Return the actor's zsock handle. Use this when you absolutely need
// to work with the zsock instance rather than the actor.
CZMQ_EXPORT zsock_t *
zactor_sock (zactor_t *self);

// Self test of this class.
CZMQ_EXPORT void
zactor_test (bool verbose);

#ifdef CZMQ_BUILD_DRAFT_API
// Function to be called on zactor_destroy. Default behavior is to send zmsg_t with string "$TERM" in a first frame.
//
// An example - to send $KTHXBAI string
//
// if (zstr_send (self, "$KTHXBAI") == 0)
// zsock_wait (self);
typedef void (zactor_destructor_fn) (
zactor_t *self);

// *** Draft method, for development use, may change without warning ***
// Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
CZMQ_EXPORT void
zactor_set_destructor (zactor_t *self, zactor_destructor_fn destructor);

#endif // CZMQ_BUILD_DRAFT_API
Please add '@interface' section in './../src/zactor.c'.

zthread_fork

//  Create an attached thread. An attached thread gets a ctx and a PAIR
// pipe back to its parent. It must monitor its pipe, and exit if the
// pipe becomes unreadable. Do not destroy the ctx, the thread does this
// automatically when it ends.
CZMQ_EXPORT void * zthread_fork (zctx_t *ctx, zthread_attached_fn *thread_fn, void *args);

zsocket_wait

//  Wait on a signal. Use this to coordinate between threads, over
// pipe pairs. Returns -1 on error, 0 on success.
CZMQ_EXPORT int zsocket_wait (void *self);

zmq_proxy

在当前线程内开始ZMQ内置代理。
代理将一个前端socket连接到一个后端。一般来说,数据会从前端流向后端。根据socket的类型,数据可能向相反的方向流动。方向指示概念上的;代理是完全对称的,在技术上前端和后端没有什么区别。
zmq_proxy()函数在当前的线程空间中运行,并且只有在当前使用的context被关闭之后才会返回。

//  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

// Callback function for zero-copy methods
typedef void (zsocket_free_fn) (void *data, void *arg);



// Destroy a socket within our CZMQ context, replaces zmq_close.
CZMQ_EXPORT void
zsocket_destroy (zctx_t *ctx, void *self);


// Unbind a socket from a formatted endpoint.
// Returns 0 if OK, -1 if the endpoint was invalid or the function
// isn't supported.
CZMQ_EXPORT int
zsocket_unbind (void *self, const char *format, ...);

// Connect a socket to a formatted endpoint
// Returns 0 if OK, -1 if the endpoint was invalid.
CZMQ_EXPORT int
zsocket_connect (void *self, const char *format, ...);

// Disconnect a socket from a formatted endpoint
// Returns 0 if OK, -1 if the endpoint was invalid or the function
// isn't supported.
CZMQ_EXPORT int
zsocket_disconnect (void *self, const char *format, ...);

// Poll for input events on the socket. Returns TRUE if there is input
// ready on the socket, else FALSE.
CZMQ_EXPORT bool
zsocket_poll (void *self, int msecs);

// Returns socket type as printable constant string
CZMQ_EXPORT const char *
zsocket_type_str (void *self);

// Send data over a socket as a single message frame.
// Accepts these flags: ZFRAME_MORE and ZFRAME_DONTWAIT.
// Returns -1 on error, 0 on success
CZMQ_EXPORT int
zsocket_sendmem (void *self, const void *data, size_t size, int flags);

// Send a signal over a socket. A signal is a zero-byte message.
// Signals are used primarily between threads, over pipe sockets.
// Returns -1 if there was an error sending the signal.
CZMQ_EXPORT int
zsocket_signal (void *self);



// Self test of this class
CZMQ_EXPORT void
zsocket_test (bool verbose);