本文整理汇总了C++中zlist_new函数的典型用法代码示例。如果您正苦于以下问题:C++ zlist_new函数的具体用法?C++ zlist_new怎么用?C++ zlist_new使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zlist_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_service_require
static service_t *
s_service_require (broker_t *self, zframe_t *service_frame)
{
assert (service_frame);
char *name = zframe_strdup (service_frame);
service_t *service =
(service_t *) zhash_lookup (self->services, name);
if (service == NULL) {
service = (service_t *) zmalloc (sizeof (service_t));
service->broker = self;
service->name = name;
service->requests = zlist_new ();
service->waiting = zlist_new ();
service->blacklist = zlist_new ();
zhash_insert (self->services, name, service);
zhash_freefn (self->services, name, s_service_destroy);
if (self->verbose)
zclock_log ("I: added service: %s", name);
}
else
free (name);
return service;
}
示例2: broker_new
broker_t *
broker_new (const char *contexts_uri, const char *executors_uri)
{
broker_t *self = (broker_t *) malloc (sizeof (broker_t));
assert (self);
printf ("[BROKER] binding to frontend %s\n", contexts_uri);
self->contexts = zsock_new_router (contexts_uri);
assert(self->contexts);
printf ("[BROKER] binding to backend %s\n", executors_uri);
self->executors = zsock_new_router (executors_uri);
assert (self->executors);
zsock_set_router_mandatory (self->executors, true);
// Only poll on executors until we have executors available.
self->poller = zpoller_new (self->executors, NULL);
assert (self->poller);
self->executor_lb = zlist_new ();
assert (self->executor_lb);
self->backlog = zlist_new ();
assert (self->backlog);
return self;
}
示例3: zloop_new
zloop_t *
zloop_new (void)
{
zloop_t
*self;
self = (zloop_t *) zmalloc (sizeof (zloop_t));
if (self) {
self->readers = zlist_new ();
self->pollers = zlist_new ();
self->timers = zlist_new ();
self->zombies = zlist_new ();
self->last_timer_id = 0;
if (!self->readers
|| !self->pollers
|| !self->timers
|| !self->zombies) {
zlist_destroy (&self->readers);
zlist_destroy (&self->pollers);
zlist_destroy (&self->timers);
zlist_destroy (&self->zombies);
free (self);
return NULL;
}
}
return self;
}
示例4: rb_czmq_ctx_socket
static VALUE rb_czmq_ctx_socket(VALUE obj, VALUE type)
{
VALUE socket;
int socket_type;
struct nogvl_socket_args args;
zmq_sock_wrapper *sock = NULL;
errno = 0;
ZmqGetContext(obj);
if (TYPE(type) != T_FIXNUM && TYPE(type) != T_SYMBOL) rb_raise(rb_eTypeError, "wrong socket type %s (expected Fixnum or Symbol)", RSTRING_PTR(rb_obj_as_string(type)));
socket_type = FIX2INT((SYMBOL_P(type)) ? rb_const_get_at(rb_mZmq, rb_to_id(type)) : type);
socket = Data_Make_Struct(rb_czmq_ctx_socket_klass(socket_type), zmq_sock_wrapper, rb_czmq_mark_sock, rb_czmq_free_sock_gc, sock);
args.ctx = ctx->ctx;
args.type = socket_type;
sock->socket = (void*)rb_thread_blocking_region(rb_czmq_nogvl_socket_new, (void *)&args, RUBY_UBF_IO, 0);
ZmqAssertObjOnAlloc(sock->socket, sock);
#ifndef HAVE_RB_THREAD_BLOCKING_REGION
sock->str_buffer = zlist_new();
sock->frame_buffer = zlist_new();
sock->msg_buffer = zlist_new();
#endif
sock->handler = Qnil;
sock->flags = 0;
sock->ctx = ctx->ctx;
sock->verbose = FALSE;
sock->state = ZMQ_SOCKET_PENDING;
sock->endpoint = Qnil;
sock->thread = rb_thread_current();
sock->recv_timeout = ZMQ_SOCKET_DEFAULT_TIMEOUT;
sock->send_timeout = ZMQ_SOCKET_DEFAULT_TIMEOUT;
rb_obj_call_init(socket, 0, NULL);
return socket;
}
示例5: flux_aux_get
static struct dispatch *dispatch_get (flux_t h)
{
struct dispatch *d = flux_aux_get (h, "flux::dispatch");
if (!d) {
flux_reactor_t *r = flux_get_reactor (h);
if (!(d = malloc (sizeof (*d))))
goto nomem;
memset (d, 0, sizeof (*d));
d->usecount = 1;
if (!(d->handlers = zlist_new ()))
goto nomem;
if (!(d->handlers_new = zlist_new ()))
goto nomem;
d->h = h;
d->w = flux_handle_watcher_create (r, h, FLUX_POLLIN, handle_cb, d);
if (!d->w)
goto nomem;
fastpath_init (&d->norm);
fastpath_init (&d->group);
flux_aux_set (h, "flux::dispatch", d, dispatch_destroy);
}
return d;
nomem:
dispatch_destroy (d);
errno = ENOMEM;
return NULL;
}
示例6: subscriber_sub_socket_new
static
zsock_t* subscriber_sub_socket_new(subscriber_state_t *state)
{
zsock_t *socket = zsock_new(ZMQ_SUB);
assert(socket);
zsock_set_rcvhwm(socket, state->rcv_hwm);
// set subscription
if (!state->subscriptions || zlist_size(state->subscriptions) == 0) {
if (!state->subscriptions)
state->subscriptions = zlist_new();
zlist_append(state->subscriptions, zconfig_resolve(state->config, "/logjam/subscription", ""));
}
char *subscription = zlist_first(state->subscriptions);
bool subscribed_to_all = false;
while (subscription) {
printf("[I] subscriber: subscribing to '%s'\n", subscription);
if (streq(subscription, ""))
subscribed_to_all = true;
zsock_set_subscribe(socket, subscription);
subscription = zlist_next(state->subscriptions);
}
if (!subscribed_to_all)
zsock_set_subscribe(socket, "heartbeat");
if (!state->devices || zlist_size(state->devices) == 0) {
// convert config file to list of devices
if (!state->devices)
state->devices = zlist_new();
zconfig_t *endpoints = zconfig_locate(state->config, "/logjam/endpoints");
if (!endpoints) {
zlist_append(state->devices, "tcp://localhost:9606");
} else {
zconfig_t *endpoint = zconfig_child(endpoints);
while (endpoint) {
char *spec = zconfig_value(endpoint);
char *new_spec = augment_zmq_connection_spec(spec, 9606);
zlist_append(state->devices, new_spec);
endpoint = zconfig_next(endpoint);
}
}
}
char* device = zlist_first(state->devices);
while (device) {
printf("[I] subscriber: connecting SUB socket to logjam-device via %s\n", device);
int rc = zsock_connect(socket, "%s", device);
log_zmq_error(rc, __FILE__, __LINE__);
assert(rc == 0);
device = zlist_next(state->devices);
}
return socket;
}
示例7: s_engine_new
static engine_t *
s_engine_new (char *broker, char *service, int verbose)
{
engine_t *self = (engine_t *) zmalloc (sizeof *self);
// Initialize engine state
self->worker = mdp_worker_new (NULL, broker, service, verbose);
self->sell_orders = zlist_new ();
self->buy_orders = zlist_new ();
return self;
}
示例8: vocket_new
static vocket_t *
vocket_new (driver_t *driver, int socktype, char *vtxname)
{
assert (driver);
vocket_t *self = (vocket_t *) zmalloc (sizeof (vocket_t));
self->driver = driver;
self->vtxname = strdup (vtxname);
self->binding_hash = zhash_new ();
self->peering_hash = zhash_new ();
self->peering_list = zlist_new ();
self->live_peerings = zlist_new ();
self->socktype = socktype;
uint index;
for (index = 0; index < tblsize (s_vocket_config); index++)
if (socktype == s_vocket_config [index].socktype)
break;
if (index < tblsize (s_vocket_config)) {
self->routing = s_vocket_config [index].routing;
self->nomnom = s_vocket_config [index].nomnom;
self->min_peerings = s_vocket_config [index].min_peerings;
self->max_peerings = s_vocket_config [index].max_peerings;
}
else {
zclock_log ("E: invalid vocket type %d", socktype);
exit (1);
}
// Create msgpipe vocket and connect over inproc to vtxname
self->msgpipe = zsocket_new (driver->ctx, ZMQ_PAIR);
assert (self->msgpipe);
zsocket_connect (self->msgpipe, "inproc://%s", vtxname);
// If we drop on no peerings, start routing input now
if (self->min_peerings == 0) {
// Ask reactor to start monitoring vocket's msgpipe pipe
zmq_pollitem_t item = { self->msgpipe, 0, ZMQ_POLLIN, 0 };
zloop_poller (driver->loop, &item, s_vocket_input, self);
}
// Store this vocket per driver so that driver can cleanly destroy
// all its vockets when it is destroyed.
zlist_push (driver->vockets, self);
//* Start transport-specific work
self->inbuf_max = VTX_TCP_INBUF_MAX;
self->outbuf_max = VTX_TCP_OUTBUF_MAX;
//* End transport-specific work
return self;
}
示例9: client_create
static client_t * client_create (ctx_t *ctx, int fd)
{
client_t *c;
socklen_t crlen = sizeof (c->ucred);
flux_t h = ctx->h;
c = xzmalloc (sizeof (*c));
c->fd = fd;
if (!(c->uuid = zuuid_new ()))
oom ();
c->ctx = ctx;
if (!(c->disconnect_notify = zhash_new ()))
oom ();
if (!(c->subscriptions = zlist_new ()))
oom ();
if (!(c->outqueue = zlist_new ()))
oom ();
if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &c->ucred, &crlen) < 0) {
flux_log (h, LOG_ERR, "getsockopt SO_PEERCRED: %s", strerror (errno));
goto error;
}
assert (crlen == sizeof (c->ucred));
/* Deny connections by uid other than session owner for now.
*/
if (c->ucred.uid != ctx->session_owner) {
flux_log (h, LOG_ERR, "connect by uid=%d pid=%d denied",
c->ucred.uid, (int)c->ucred.pid);
goto error;
}
c->inw = flux_fd_watcher_create (fd, FLUX_POLLIN, client_read_cb, c);
c->outw = flux_fd_watcher_create (fd, FLUX_POLLOUT, client_write_cb, c);
if (!c->inw || !c->outw) {
flux_log (h, LOG_ERR, "flux_fd_watcher_create: %s", strerror (errno));
goto error;
}
flux_fd_watcher_start (h, c->inw);
flux_msg_iobuf_init (&c->inbuf);
flux_msg_iobuf_init (&c->outbuf);
if (set_nonblock (c->fd, true) < 0) {
flux_log (h, LOG_ERR, "set_nonblock: %s", strerror (errno));
goto error;
}
return (c);
error:
client_destroy (c);
return NULL;
}
示例10: xzmalloc
static ctx_t *getctx (flux_t h)
{
int saved_errno;
ctx_t *ctx = (ctx_t *)flux_aux_get (h, "req");
if (!ctx) {
ctx = xzmalloc (sizeof (*ctx));
ctx->h = h;
ctx->ping_requests = zhash_new ();
ctx->clog_requests = zlist_new ();
if (!ctx->clog_requests || !ctx->ping_requests) {
saved_errno = ENOMEM;
goto error;
}
if (flux_get_rank (h, &ctx->rank) < 0) {
saved_errno = errno;
goto error;
}
flux_aux_set (h, "req", ctx, freectx);
}
return ctx;
error:
freectx (ctx);
errno = saved_errno;
return NULL;
}
示例11: sched_loop_setup
int sched_loop_setup (flux_t h)
{
curr_reservation_depth = 0;
if (!completion_times)
completion_times = zlist_new ();
return 0;
}
示例12: zctx_new
zctx_t *
zctx_new (void)
{
zctx_t
*self;
self = (zctx_t *) zmalloc (sizeof (zctx_t));
if (!self)
return NULL;
self->sockets = zlist_new ();
if (!self->sockets) {
free (self);
return NULL;
}
self->iothreads = 1;
self->main = TRUE;
self->hwm = 1;
#if defined (__UNIX__)
// Install signal handler for SIGINT and SIGTERM
struct sigaction action;
action.sa_handler = s_signal_handler;
action.sa_flags = 0;
sigemptyset (&action.sa_mask);
sigaction (SIGINT, &action, NULL);
sigaction (SIGTERM, &action, NULL);
#endif
return self;
}
示例13: get_update
zlist_t *
get_update (uint64_t from_state)
{
printf("[ST] GET_UPDATE\n");
zlist_t *filemeta_list = zlist_new ();
DIR *dir;
struct dirent *ent;
if ((dir = opendir ("./syncfolder")) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
if (strcmp (ent->d_name, ".") != 0 && strcmp (ent->d_name, "..") != 0) {
struct stat st;
stat(ent->d_name, &st);
zs_fmetadata_t *fmetadata = zs_fmetadata_new ();
zs_fmetadata_set_path (fmetadata, "%s", ent->d_name);
zs_fmetadata_set_size (fmetadata, st.st_size);
zs_fmetadata_set_operation (fmetadata, ZS_FILE_OP_UPD);
zs_fmetadata_set_timestamp (fmetadata, st.st_ctime);
zs_fmetadata_set_checksum (fmetadata, 0x3312AFFDE12);
zlist_append(filemeta_list, fmetadata);
}
}
closedir (dir);
}
if (zlist_size (filemeta_list) > 0) {
return filemeta_list;
}
else {
return NULL;
}
}
示例14: kdt_point_new
kdt_point_t *
kdt_point_new (void) {
kdt_point_t *self = (kdt_point_t *) zmalloc (sizeof (kdt_point_t));
assert (self);
self->list = zlist_new ();
return self;
}
示例15: sprk_block_new
sprk_block_t *
sprk_block_new (sprk_descriptor_t *descriptor, zlist_t *applied_transforms)
{
sprk_block_t *self = (sprk_block_t *) zmalloc (sizeof (sprk_block_t));
assert (self);
if (!applied_transforms) {
applied_transforms = zlist_new();
}
self->descriptor = descriptor;
self->applied_transforms = applied_transforms;
self->queued_transforms = zlist_new ();
return self;
}