void zctx_destroy (zctx_t **self_p) { assert (self_p); if (*self_p) { zctx_t *self = *self_p; while (zlist_size (self->sockets)) zctx__socket_destroy (self, zlist_first (self->sockets)); zlist_destroy (&self->sockets); if (self->main && self->context) zmq_term (self->context); free (self); *self_p = NULL; } }
void * zthread_fork (zctx_t *ctx, zthread_attached_fn *thread_fn, void *args) { shim_t *shim = NULL; // Create our end of the pipe void *pipe = zctx__socket_pipe (ctx); if (pipe) zsocket_bind (pipe, "inproc://zctx-pipe-%p", pipe); else return NULL; // Prepare argument shim for child thread shim = (shim_t *) zmalloc (sizeof (shim_t)); if (shim) { shim->attached = thread_fn; shim->args = args; shim->ctx = zctx_shadow (ctx); if (!shim->ctx) { zctx__socket_destroy (ctx, pipe); return NULL; } } else return NULL; // Connect child pipe to our pipe shim->pipe = zctx__socket_pipe (shim->ctx); if (!shim->pipe) { zctx__socket_destroy (ctx, pipe); return NULL; } zsocket_connect (shim->pipe, "inproc://zctx-pipe-%p", pipe); s_thread_start (shim); return pipe; }
void zctx_destroy (zctx_t **self_p) { assert (self_p); if (*self_p) { zctx_t *self = *self_p; // Destroy all sockets while (zlist_size (self->sockets)) zctx__socket_destroy (self, zlist_first (self->sockets)); zlist_destroy (&self->sockets); zmutex_destroy (&self->mutex); // ZMQ context may not yet be instantiated if (self->context && !self->shadow) zmq_term (self->context); free (self); *self_p = NULL; } }
void zsocket_destroy (zctx_t *ctx, void *self) { if (self) zctx__socket_destroy (ctx, self); }
void zsocket_destroy (zctx_t *ctx, void *socket) { zctx__socket_destroy (ctx, socket); }
void zsocket_destroy (zctx_t *ctx, void *zocket) { if (zocket) zctx__socket_destroy (ctx, zocket); }