本文整理汇总了C++中zhash_new函数的典型用法代码示例。如果您正苦于以下问题:C++ zhash_new函数的具体用法?C++ zhash_new怎么用?C++ zhash_new使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zhash_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_agent_new
static agent_t *
s_agent_new (zctx_t *ctx, void *pipe)
{
agent_t *self = (agent_t *) zmalloc (sizeof (agent_t));
if (!self)
return NULL;
self->ctx = ctx;
self->pipe = pipe;
self->whitelist = zhash_new ();
if (self->whitelist)
self->blacklist = zhash_new ();
// Create ZAP handler and get ready for requests
if (self->blacklist)
self->handler = zsocket_new (self->ctx, ZMQ_REP);
if (self->handler) {
if (zsocket_bind (self->handler, ZAP_ENDPOINT) == 0)
zstr_send (self->pipe, "OK");
else
zstr_send (self->pipe, "ERROR");
}
else
s_agent_destroy (&self);
return self;
}
示例2: zyre_node_new
static zyre_node_t *
zyre_node_new (zsock_t *pipe, void *args)
{
zyre_node_t *self = (zyre_node_t *) zmalloc (sizeof (zyre_node_t));
self->inbox = zsock_new (ZMQ_ROUTER);
if (self->inbox == NULL) {
free (self);
return NULL; // Could not create new socket
}
// Use ZMQ_ROUTER_HANDOVER so that when a peer disconnects and
// then reconnects, the new client connection is treated as the
// canonical one, and any old trailing commands are discarded.
zsock_set_router_handover (self->inbox, 1);
self->pipe = pipe;
self->outbox = (zsock_t *) args;
self->poller = zpoller_new (self->pipe, NULL);
self->beacon_port = ZRE_DISCOVERY_PORT;
self->interval = 0; // Use default
self->uuid = zuuid_new ();
self->peers = zhash_new ();
self->peer_groups = zhash_new ();
self->own_groups = zhash_new ();
self->headers = zhash_new ();
zhash_autofree (self->headers);
// Default name for node is first 6 characters of UUID:
// the shorter string is more readable in logs
self->name = (char *) zmalloc (7);
memcpy (self->name, zuuid_str (self->uuid), 6);
return self;
}
示例3: zyre_node_new
static zyre_node_t *
zyre_node_new (zctx_t *ctx, void *pipe)
{
zyre_node_t *self = (zyre_node_t *) zmalloc (sizeof (zyre_node_t));
self->ctx = ctx;
self->pipe = pipe;
self->inbox = zsocket_new (ctx, ZMQ_ROUTER);
if (self->inbox == NULL) {
free (self);
return NULL; // Interrupted 0MQ call
}
self->port = zsocket_bind (self->inbox, "tcp://*:*");
if (self->port < 0) {
free (self);
return NULL; // Interrupted 0MQ call
}
self->beacon = zbeacon_new (self->ctx, ZRE_DISCOVERY_PORT);
if (!self->beacon) {
free (self);
return NULL; // Exhausted process sockets
}
self->uuid = zuuid_new ();
self->peers = zhash_new ();
self->peer_groups = zhash_new ();
self->own_groups = zhash_new ();
self->headers = zhash_new ();
zhash_autofree (self->headers);
return self;
}
示例4: s_agent_new
static agent_t *
s_agent_new (zctx_t *ctx, void *control)
{
agent_t *self = (agent_t *) zmalloc (sizeof (agent_t));
self->ctx = ctx;
self->control = control;
self->router = zsocket_new (ctx, ZMQ_ROUTER);
// Connect our data socket to caller's endpoint
self->data = zsocket_new (ctx, ZMQ_PAIR);
char *endpoint = zstr_recv (self->control);
int rc = zsocket_connect (self->data, "%s", endpoint);
assert (rc != -1);
free (endpoint);
// Create new client codec using cert from API
byte public_key [32];
byte secret_key [32];
rc = zmq_recv (self->control, public_key, 32, 0);
assert (rc == 32);
rc = zmq_recv (self->control, secret_key, 32, 0);
assert (rc == 32);
self->cert = zcert_new_from (public_key, secret_key);
self->metadata = zhash_new ();
zhash_autofree (self->metadata);
self->clients = zhash_new ();
self->max_clients = 100;
self->max_pending = 10;
self->client_ttl = 3600; // 60 minutes
self->pending_ttl = 60; // 60 seconds
return self;
}
示例5: zsync_node_new
static zsync_node_t *
zsync_node_new ()
{
int rc;
zsync_node_t *self = (zsync_node_t *) zmalloc (sizeof (zsync_node_t));
self->ctx = zctx_new ();
assert (self->ctx);
self->zyre = zyre_new (self->ctx);
assert (self->zyre);
// Obtain permanent UUID
self->own_uuid = zuuid_new ();
if (zsys_file_exists (UUID_FILE)) {
// Read uuid from file
zfile_t *uuid_file = zfile_new (".", UUID_FILE);
int rc = zfile_input (uuid_file); // open file for reading
assert (rc == 0);
zchunk_t *uuid_chunk = zfile_read (uuid_file, 16, 0);
assert (zchunk_size (uuid_chunk) == 16); // make sure read succeeded
zuuid_set (self->own_uuid, zchunk_data (uuid_chunk));
zfile_destroy (&uuid_file);
} else {
// Write uuid to file
zfile_t *uuid_file = zfile_new (".", UUID_FILE);
rc = zfile_output (uuid_file); // open file for writing
assert (rc == 0);
zchunk_t *uuid_bin = zchunk_new ( zuuid_data (self->own_uuid), 16);
rc = zfile_write (uuid_file, uuid_bin, 0);
assert (rc == 0);
zfile_destroy (&uuid_file);
}
// Obtain peers and states
self->peers = zlist_new ();
if (zsys_file_exists (PEER_STATES_FILE)) {
zhash_t *peer_states = zhash_new ();
int rc = zhash_load (peer_states, PEER_STATES_FILE);
assert (rc == 0);
zlist_t *uuids = zhash_keys (peer_states);
char *uuid = zlist_first (uuids);
while (uuid) {
char * state_str = zhash_lookup (peer_states, uuid);
uint64_t state;
sscanf (state_str, "%"SCNd64, &state);
zlist_append (self->peers, zsync_peer_new (uuid, state));
uuid = zlist_next (uuids);
}
}
self->zyre_peers = zhash_new ();
self->terminated = false;
return self;
}
示例6: server_initialize
static int
server_initialize (server_t *self)
{
// Construct properties here
self->services = zhash_new();
self->workers = zhash_new();
self->waiting = zlist_new();
s_server_t *server = (s_server_t *) self;
self->router = server->router;
return 0;
}
示例7: agent_new
static agent_t *
agent_new (zctx_t *ctx, void *pipe)
{
void *inbox = zsocket_new (ctx, ZMQ_ROUTER);
if (!inbox) // Interrupted
return NULL;
agent_t *self = (agent_t *) zmalloc (sizeof (agent_t));
self->ctx = ctx;
self->pipe = pipe;
self->udp = zre_udp_new (ZRE_DISCOVERY_PORT);
self->inbox = inbox;
self->host = zre_udp_host (self->udp);
self->port = zsocket_bind (self->inbox, "tcp://*:*");
sprintf (self->endpoint, "%s:%d", self->host, self->port);
if (self->port < 0) { // Interrupted
zre_udp_destroy (&self->udp);
free (self);
return NULL;
}
self->uuid = zre_uuid_new ();
self->identity = strdup (zre_uuid_str (self->uuid));
self->peers = zhash_new ();
self->peer_groups = zhash_new ();
self->own_groups = zhash_new ();
self->headers = zhash_new ();
zhash_autofree (self->headers);
self->log = zre_log_new (self->endpoint);
// Set up content distribution network: Each server binds to an
// ephemeral port and publishes a temporary directory that acts
// as the outbox for this node.
//
sprintf (self->fmq_outbox, "%s/send/%s", s_tmpdir (), self->identity);
zfile_mkdir (self->fmq_outbox);
sprintf (self->fmq_inbox, "%s/recv/%s", s_tmpdir (), self->identity);
zfile_mkdir (self->fmq_inbox);
self->fmq_server = fmq_server_new ();
self->fmq_service = fmq_server_bind (self->fmq_server, "tcp://*:*");
fmq_server_publish (self->fmq_server, self->fmq_outbox, "/");
fmq_server_set_anonymous (self->fmq_server, true);
char publisher [32];
sprintf (publisher, "tcp://%s:%d", self->host, self->fmq_service);
zhash_update (self->headers, "X-FILEMQ", publisher);
// Client will connect as it discovers new nodes
self->fmq_client = fmq_client_new ();
fmq_client_set_inbox (self->fmq_client, self->fmq_inbox);
fmq_client_set_resync (self->fmq_client, true);
fmq_client_subscribe (self->fmq_client, "/");
return self;
}
示例8: zmalloc
static broker_t *s_broker_new (int verbose)
{
broker_t *self = (broker_t *) zmalloc (sizeof (broker_t));
self->ctx = zctx_new ();
self->socket = zsocket_new (self->ctx, ZMQ_ROUTER);
self->verbose = verbose;
self->services = zhash_new ();
self->workers = zhash_new ();
self->waiting = zlist_new ();
self->heartbeat_at = zclock_time () + HEARTBEAT_INTERVAL;
return self;
}
示例9: 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;
}
示例10: extract_raw_pdescs
static int extract_raw_pdescs (flux_t *h, int64_t j, int64_t n, json_object *jcb)
{
int rc = -1;
int64_t i = 0;
char *hnm;
const char *cmd = NULL;
zhash_t *eh = NULL; /* hash holding a set of unique exec_names */
zhash_t *hh = NULL; /* hash holding a set of unique host_names */
json_object *o = NULL;
json_object *po = NULL;
json_object *pa = Jnew_ar ();
json_object *hns = Jnew_ar ();
json_object *ens = Jnew_ar ();
if (!(eh = zhash_new ()) || !(hh = zhash_new ()))
oom ();
for (i=0; i < (int) n; i++) {
int64_t eix = 0, hix = 0;
int64_t pid = 0, nid = 0;
if (extract_raw_pdesc (h, j, i, &o) != 0)
goto done;
if (!fetch_rank_pdesc (o, &pid, &nid, &cmd))
goto done;
eix = build_name_array (eh, cmd, ens);
/* FIXME: we need a hostname service */
hnm = xasprintf ("%"PRId64, nid);
hix = build_name_array (hh, hnm, hns);
po = build_parray_elem (pid, eix, hix);
json_object_array_add (pa, po);
po = NULL;
Jput (o);
o = NULL;
free (hnm);
}
add_pdescs_to_jcb (&hns, &ens, &pa, jcb);
rc = 0;
done:
if (o) Jput (o);
if (po) Jput (po);
if (pa) Jput (pa);
if (hns) Jput (hns);
if (ens) Jput (ens);
zhash_destroy (&eh);
zhash_destroy (&hh);
return rc;
}
示例11: s_broker_new
static broker_t *
s_broker_new (int verbose)
{
broker_t *self = (broker_t *) calloc (1, sizeof (broker_t));
// Initialize broker state
self->context = zmq_init (1);
self->socket = zmq_socket (self->context, ZMQ_XREP);
self->verbose = verbose;
self->services = zhash_new ();
self->workers = zhash_new ();
self->waiting = zlist_new ();
self->heartbeat_at = s_clock () + HEARTBEAT_INTERVAL;
return self;
}
示例12: main
int main (void)
{
// Prepare our context and publisher socket
zctx_t *ctx = zctx_new ();
void *publisher = zsocket_new (ctx, ZMQ_PUB);
zsocket_set_hwm (publisher, 0);
zsocket_bind (publisher, "tcp://*:5556");
zclock_sleep (200);
zhash_t *kvmap = zhash_new ();
int64_t sequence = 0;
srandom ((unsigned) time (NULL));
while (!zctx_interrupted) {
// Distribute as key-value message
kvmsg_t *kvmsg = kvmsg_new (++sequence);
kvmsg_fmt_key (kvmsg, "%d", randof (10000));
kvmsg_fmt_body (kvmsg, "%d", randof (1000000));
kvmsg_send (kvmsg, publisher);
kvmsg_store (&kvmsg, kvmap);
}
printf (" Interrupted\n%d messages out\n", (int) sequence);
zhash_destroy (&kvmap);
zctx_destroy (&ctx);
return 0;
}
示例13: xzmalloc
struct cache *cache_create (void)
{
struct cache *cache = xzmalloc (sizeof (*cache));
if (!(cache->zh = zhash_new ()))
oom ();
return cache;
}
示例14: mod_main
int mod_main (flux_t *h, int argc, char **argv)
{
int saved_errno;
flux_msg_handler_t **handlers = NULL;
if (argc == 1 && !strcmp (argv[0], "--init-failure")) {
flux_log (h, LOG_INFO, "aborting during init per test request");
errno = EIO;
goto error;
}
if (!(modules = zhash_new ())) {
errno = ENOMEM;
goto error;
}
if (flux_get_rank (h, &rank) < 0)
goto error;
if (flux_msg_handler_addvec (h, htab, NULL, &handlers) < 0)
goto error;
if (flux_reactor_run (flux_get_reactor (h), 0) < 0) {
flux_log_error (h, "flux_reactor_run");
goto error;
}
zhash_destroy (&modules);
return 0;
error:
saved_errno = errno;
flux_msg_handler_delvec (handlers);
zhash_destroy (&modules);
errno = saved_errno;
return -1;
}
示例15: server_initialize
static int
server_initialize (server_t *self)
{
zsys_notice ("starting zpipes service");
self->pipes = zhash_new ();
return 0;
}