예제 #1
0
파일: zyre_node.c 프로젝트: opedroso/zyre
static void
zyre_node_dump (zyre_node_t *self)
{
    void *item;

    zsys_info ("zyre_node: dump state");
    zsys_info (" - name=%s uuid=%s", self->name, zuuid_str (self->uuid));

    zsys_info (" - endpoint=%s", self->endpoint);
    if (self->beacon_port)
        zsys_info (" - discovery=beacon port=%d interval=%zu",
                   self->beacon_port, self->interval);
    else {
        zsys_info (" - discovery=gossip");
        if (self->gossip_bind)
            zsys_info ("   - bind endpoint=%s", self->gossip_bind);
        if (self->gossip_connect)
            zsys_info ("   - connect endpoint=%s", self->gossip_connect);
    }
    zsys_info (" - headers=%zu:", zhash_size (self->headers));
    for (item = zhash_first (self->headers); item != NULL;
            item = zhash_next (self->headers))
        zyre_node_log_pair (zhash_cursor (self->headers), item, self);

    zsys_info (" - peers=%zu:", zhash_size (self->peers));
    for (item = zhash_first (self->peers); item != NULL;
            item = zhash_next (self->peers))
        zyre_node_log_item (zhash_cursor (self->peers), item, self);

    zsys_info (" - own groups=%zu:", zlist_size (self->own_groups));
    const char *group = (const char *) zlist_first (self->own_groups);
    while (group) {
        zsys_info ("   - %s", group);
        group = (const char *) zlist_next (self->own_groups);
    }

    zsys_info (" - peer groups=%zu:", zhash_size (self->peer_groups));
    zlist_t *groups = zhash_keys (self->peer_groups);
    group = (const char *) zlist_first (groups);
    while (group) {
        zsys_info ("   - %s", group);
        zyre_group_t *rgroup = (zyre_group_t *) zhash_lookup (self->peer_groups, group);
        zlist_t *neighbors = zyre_group_peers (rgroup);
        char *neighbor = (char *) zlist_first (neighbors);
        while (neighbor) {
            zsys_info ("     - %s", neighbor);
            neighbor = (char *) zlist_next (neighbors);
        }
        zlist_destroy (&neighbors);
        group = (const char *) zlist_next (groups);
    }
    zlist_destroy (&groups);

}
예제 #2
0
//  --------------------------------------------------------------------------
//  Return json format for all nodes
char*
ztask_monitor_api_json (ztask_monitor_api_t *self)
{
	assert (self);

	if (!zhash_size (self->nodes)) {
		return 0;
	}


	char *data;
	if (asprintf(&data, "{ \"cluster\" : \"myname\", \"workers\" : [ ") < 0)
		data = NULL;

	assert (data);

	char *wk = (char *) zhash_first (self->nodes);
	while (wk) {

		if (asprintf(&data, "%s %s", data, wk) < 0)
			return NULL;
		wk = (char *) zhash_next (self->nodes);
		if (wk)
			if (asprintf(&data, "%s,", data) < 0)
				return NULL;
	}

	if (asprintf(&data, " %s ] }", data) < 0)
		return NULL;
	return data;
}
예제 #3
0
파일: zyre_node.c 프로젝트: opedroso/zyre
static zyre_peer_t *
zyre_node_require_peer (zyre_node_t *self, zuuid_t *uuid, const char *endpoint)
{
    assert (self);
    assert (endpoint);

    zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, zuuid_str (uuid));
    if (!peer) {
        //  Purge any previous peer on same endpoint
        void *item;
        for (item = zhash_first (self->peers); item != NULL;
                item = zhash_next (self->peers))
            zyre_node_purge_peer (zhash_cursor (self->peers), item, (char *) endpoint);

        peer = zyre_peer_new (self->peers, uuid);
        assert (peer);
        zyre_peer_set_origin (peer, self->name);
        zyre_peer_set_verbose (peer, self->verbose);
        zyre_peer_connect (peer, self->uuid, endpoint, self->expired_timeout);

        //  Handshake discovery by sending HELLO as first message
        zlist_t *groups = zlist_dup (self->own_groups);
        zhash_t *headers = zhash_dup (self->headers);
        zre_msg_t *msg = zre_msg_new (ZRE_MSG_HELLO);
        zre_msg_set_endpoint (msg, self->endpoint);
        zre_msg_set_groups (msg, &groups);
        zre_msg_set_status (msg, self->status);
        zre_msg_set_name (msg, self->name);
        zre_msg_set_headers (msg, &headers);
        zyre_peer_send (peer, &msg);
    }
    return peer;
}
예제 #4
0
파일: zgossip.c 프로젝트: PSG-Luna/czmq
static void
server_connect (server_t *self, const char *endpoint)
{
    zsock_t *remote = zsock_new (ZMQ_DEALER);
    assert (remote);          //  No recovery if exhausted

    //  Never block on sending; we use an infinite HWM and buffer as many
    //  messages as needed in outgoing pipes. Note that the maximum number
    //  is the overall tuple set size.
    zsock_set_unbounded (remote);
    if (zsock_connect (remote, "%s", endpoint)) {
        zsys_warning ("bad zgossip endpoint '%s'", endpoint);
        zsock_destroy (&remote);
        return;
    }
    //  Send HELLO and then PUBLISH for each tuple we have
    zgossip_msg_send_hello (remote);
    tuple_t *tuple = (tuple_t *) zhash_first (self->tuples);
    while (tuple) {
        int rc = zgossip_msg_send_publish (remote, tuple->key, tuple->value, 0);
        assert (rc == 0);
        tuple = (tuple_t *) zhash_next (self->tuples);
    }
    //  Now monitor this remote for incoming messages
    engine_handle_socket (self, remote, remote_handler);
    zlist_append (self->remotes, remote);
}
예제 #5
0
static
void dump_modules_hash(zhash_t *modules)
{
    const char* module = zhash_first(modules);
    while (module) {
        printf("[D] module: %s\n", module);
        module = zhash_next(modules);
    }
}
예제 #6
0
파일: zdir.c 프로젝트: diorcety/czmq
static int
s_on_read_timer (zloop_t *loop, int timer_id, void *arg)
{
    zdir_watch_t *watch = (zdir_watch_t *) arg;

    void *data;
    for (data = zhash_first (watch->subs); data != NULL; data = zhash_next (watch->subs))
    {
        zdir_watch_sub_t *sub = (zdir_watch_sub_t *) data;

        zdir_t *new_dir = zdir_new (zdir_path (sub->dir), NULL);
        if (!new_dir) {
            if (watch->verbose)
                zsys_error ("zdir_watch: Unable to create new zdir for path %s", zdir_path (sub->dir));
            continue;
        }

        // Determine if anything has changed.
        zlist_t *diff = zdir_diff (sub->dir, new_dir, "");

        // Do memory management before error handling...
        zdir_destroy (&sub->dir);
        sub->dir = new_dir;

        if (!diff) {
            if (watch->verbose)
                zsys_error ("zdir_watch: Unable to create diff for path %s", zdir_path (sub->dir));
            continue;
        }

        if (zlist_size (diff) > 0) {
            if (watch->verbose) {
                zdir_patch_t *patch = (zdir_patch_t *) zlist_first (diff);

                zsys_info ("zdir_watch: Found %d changes in %s:", zlist_size (diff), zdir_path (sub->dir));
                while (patch)
                {
                    zsys_info ("zdir_watch:   %s %s", zfile_filename (zdir_patch_file (patch), NULL), zdir_patch_op (patch) == ZDIR_PATCH_CREATE? "created": "deleted");
                    patch = (zdir_patch_t *) zlist_next (diff);
                }
            }

            if (zsock_send (watch->pipe, "sp", zdir_path (sub->dir), diff) != 0) {
                if (watch->verbose)
                    zsys_error ("zdir_watch: Unable to send patch list for path %s", zdir_path (sub->dir));
                zlist_destroy (&diff);
            }

            // Successfully sent `diff` list - now owned by receiver
        }
        else {
            zlist_destroy (&diff);
        }
    }

    return 0;
}
예제 #7
0
static
void dump_increments_hash(zhash_t *increments_hash)
{
    increments_t *increments = zhash_first(increments_hash);
    while (increments) {
        const char *action = zhash_cursor(increments_hash);
        dump_increments(action, increments);
        increments = zhash_next(increments_hash);
    }
}
예제 #8
0
파일: zhash.c 프로젝트: ritchiecarroll/czmq
void *
zhash_first (zhash_t *self)
{
    assert (self);
    //  Point to before or at first item
    self->cursor_index = 0;
    self->cursor_item = self->items [self->cursor_index];
    //  Now scan forwards to find it, leave cursor after item
    return zhash_next (self);
}
예제 #9
0
파일: simsrv.c 프로젝트: lipari/flux-sched
// Looks at the current state and launches the next trigger
static int handle_next_event (ctx_t *ctx)
{
    zhash_t *timers;
    sim_state_t *sim_state = ctx->sim_state;
    int rc = 0;

    // get the timer hashtable, make sure its full, and get a list of its keys
    timers = sim_state->timers;
    if (zhash_size (timers) < 1) {
        flux_log (ctx->h, LOG_ERR, "timer hashtable has no elements");
        return -1;
    }

    // Get the next occuring event time/module
    double min_event_time = -1;
    double *curr_event_time = NULL;
    const char *mod_name = NULL, *curr_name = NULL;

    for (curr_event_time = zhash_first (timers);
         curr_event_time;
         curr_event_time = zhash_next (timers)) {
        curr_name = zhash_cursor (timers);
        if (min_event_time < 0 ||
            occurs_before (*curr_event_time, min_event_time) ||
            breaks_tie (*curr_event_time, min_event_time, curr_name)) {
            min_event_time = *curr_event_time;
            mod_name = curr_name;
        }
    }

    if (min_event_time < 0) {
        return -1;
    }

    // advance time then send the trigger to the module with the next event
    if (min_event_time > sim_state->sim_time) {
        // flux_log (ctx->h, LOG_DEBUG, "Time was advanced from %f to %f while
        // triggering the next event for %s",
        //		  sim_state->sim_time, *min_event_time, mod_name);
        sim_state->sim_time = min_event_time;
    } else {
        // flux_log (ctx->h, LOG_DEBUG, "Time was not advanced while triggering
        // the next event for %s", mod_name);
    }
    flux_log (ctx->h,
              LOG_DEBUG,
              "Triggering %s.  Curr sim time: %f",
              mod_name,
              sim_state->sim_time);

    rc = send_trigger (ctx->h, mod_name, sim_state);

    return rc;
}
예제 #10
0
파일: zgossip.c 프로젝트: PSG-Luna/czmq
static void
get_next_tuple (client_t *self)
{
    tuple_t *tuple = (tuple_t *) zhash_next (self->server->tuples);
    if (tuple) {
        zgossip_msg_set_key (self->reply, tuple->key);
        zgossip_msg_set_value (self->reply, tuple->value);
        engine_set_next_event (self, ok_event);
    }
    else
        engine_set_next_event (self, finished_event);
}
예제 #11
0
파일: zcert.c 프로젝트: PSG-Luna/czmq
void
zcert_print (zcert_t *self)
{
    assert (self);
    zsys_info ("zcert: metadata");

    char *value = (char *) zhash_first (self->metadata);
    while (value) {
        zsys_info ("zcert:     %s = \"%s\"",
                   zhash_cursor (self->metadata), value);
        value = (char *) zhash_next (self->metadata);
    }
    zsys_info ("zcert: curve");
    zsys_info ("zcert:     public-key = \"%s\"", self->public_txt);
    zsys_info ("zcert:     secret-key = \"%s\"", self->secret_txt);
}
예제 #12
0
파일: zcert.c 프로젝트: drmplanet/kdlenv
void
zcert_fprint (zcert_t *self, FILE *file)
{
    assert (self);
    fprintf (file, "metadata\n");

    char *value = (char *) zhash_first (self->metadata);
    while (value) {
        fprintf (file, "    %s = \"%s\"\n",
                 zhash_cursor (self->metadata), value);
        value = (char *) zhash_next (self->metadata);
    }
    fprintf (file, "curve\n");
    fprintf (file, "    public-key = \"%s\"\n", self->public_txt);
    fprintf (file, "    secret-key = \"%s\"\n", self->secret_txt);
}
예제 #13
0
파일: simsrv.c 프로젝트: lipari/flux-sched
static void copy_new_state_data (ctx_t *ctx,
                                 sim_state_t *curr_sim_state,
                                 sim_state_t *reply_sim_state)
{
    if (reply_sim_state->sim_time > curr_sim_state->sim_time) {
        curr_sim_state->sim_time = reply_sim_state->sim_time;
    }

    void *item = NULL;
    const char *key = NULL;
    for (item = zhash_first (reply_sim_state->timers);
         item;
         item = zhash_next (reply_sim_state->timers)) {
        key = zhash_cursor (reply_sim_state->timers);
        check_for_new_timers (key, item, ctx);
    }
}
예제 #14
0
파일: maltcp_ctx.c 프로젝트: ccsdsmo/malc
int maltcp_ctx_connection_remove_socket(maltcp_ctx_t *self, int socket) {
  clog_debug(maltcp_logger, "maltcp_ctx_connection_remove_socket(%d).\n", socket);
  maltcp_ctx_connection_t *cnx_ptr =  (maltcp_ctx_connection_t*) zhash_first(self->cnx_table);
  while (cnx_ptr) {
    if (cnx_ptr->socket == socket) {
      // Close registered TCP connections
      clog_debug(maltcp_logger, "maltcp_ctx_connection_remove_socket: close and remove socket.\n");
      maltcp_ctx_socket_destroy(cnx_ptr);
      zhash_delete(self->cnx_table, zhash_cursor(self->cnx_table));
      // TODO: Should free the allocated string key and element structure.
      return 0;
    }
    cnx_ptr = (maltcp_ctx_connection_t*) zhash_next(self->cnx_table);
  }
  clog_debug(maltcp_logger, "maltcp_ctx_connection_remove_socket: socket (%d) not found.\n", socket);
  return 0;
}
예제 #15
0
파일: zcert.c 프로젝트: drmplanet/kdlenv
static void
s_save_metadata_all (zcert_t *self)
{
    zconfig_destroy (&self->config);
    self->config = zconfig_new ("root", NULL);
    zconfig_t *section = zconfig_new ("metadata", self->config);
    
    char *value = (char *) zhash_first (self->metadata);
    while (value) {
        zconfig_t *item = zconfig_new (zhash_cursor (self->metadata), section);
        zconfig_set_value (item, "%s", value);
        value = (char *) zhash_next (self->metadata);
    }
    char *timestr = zclock_timestr ();
    zconfig_set_comment (self->config,
        "   ****  Generated on %s by CZMQ  ****", timestr);
    zstr_free (&timestr);
}
예제 #16
0
파일: maltcp_ctx.c 프로젝트: ccsdsmo/malc
int maltcp_ctx_destroy(void **self_p) {
  clog_debug(maltcp_logger, "maltcp_ctx_destroy...\n");
  if (self_p && *self_p) {
    maltcp_ctx_t *self = (maltcp_ctx_t *) *self_p;


    // TODO(AF): zmq_close versus zsocket_destroy
    zsocket_set_linger(self->endpoints_socket, 0);
    clog_debug(maltcp_logger, "maltcp_ctx_destroy: linger=%d\n", zsocket_linger(self->endpoints_socket));
    zsocket_destroy(self->zmq_ctx, self->endpoints_socket);
  //  zmq_close(mal_ctx->endpoints_socket);

    // Free all structures in hash-table, close socket and destroy mutex.
    if (self->cnx_table) {
      maltcp_ctx_connection_t *cnx_ptr =  (maltcp_ctx_connection_t*) zhash_first(self->cnx_table);
      while (cnx_ptr) {
        // Close registered TCP connections
        clog_debug(maltcp_logger, "maltcp_ctx_destroy: close socket %d.\n", cnx_ptr->socket);
        maltcp_ctx_socket_destroy(cnx_ptr);
        // destroy all registered sockets
        cnx_ptr = (maltcp_ctx_connection_t*) zhash_next(self->cnx_table);
      }
    }

    // TODO (AF): Close all pollers?
    clog_debug(maltcp_logger, "maltcp_ctx_destroy: stopped.\n");

    free(self->maltcp_header);
    // Free all structures in hash-table, close socket and destroy mutex.
    if (self->cnx_table)
      zhash_destroy(&self->cnx_table);
    zloop_destroy(&self->zloop);
//    zsocket_destroy(self->zmq_ctx, self->endpoints_socket);
//    zmq_close(self->endpoints_socket);
    zctx_destroy(&self->zmq_ctx);

    free(self);
    *self_p = NULL;
  }
  clog_debug(maltcp_logger, "maltcp_ctx_destroy: destroyed.\n");
  return 0;
}
예제 #17
0
파일: zyre_node.c 프로젝트: opedroso/zyre
static void
zyre_node_remove_peer (zyre_node_t *self, zyre_peer_t *peer)
{
    void *item;
    //  Tell the calling application the peer has gone
    zstr_sendm (self->outbox, "EXIT");
    zstr_sendm (self->outbox, zyre_peer_identity (peer));
    zstr_send (self->outbox, zyre_peer_name (peer));

    if (self->verbose)
        zsys_info ("(%s) EXIT name=%s endpoint=%s",
                self->name, zyre_peer_name (peer), zyre_peer_endpoint (peer));

    //  Remove peer from any groups we've got it in
    for (item = zhash_first (self->peer_groups); item != NULL;
            item = zhash_next (self->peer_groups))
        zyre_node_delete_peer (zhash_cursor (self->peer_groups), item, peer);
    //  To destroy peer, we remove from peers hash table
    zhash_delete (self->peers, zyre_peer_identity (peer));
}
예제 #18
0
파일: sprk_dataset.c 프로젝트: emef/sprk
void
sprk_dataset_destroy (sprk_dataset_t **self_p)
{
    assert (self_p);
    if (*self_p) {
        sprk_dataset_t *self = *self_p;

        block_t *block = (block_t *) zhash_first (self->blocks);
        while (block != NULL) {
            block_destroy (&block);
            zhash_delete (self->blocks, zhash_cursor (self->blocks));
            block = (block_t *) zhash_next (self->blocks);
        }
        zhash_destroy (&self->blocks);

        //  Free object itself
        free (self);
        *self_p = NULL;
    }
}
예제 #19
0
static void client_destroy (client_t *c)
{
    subscription_t *sub;
    ctx_t *ctx = c->ctx;

    if (c->disconnect_notify) {
        struct disconnect_notify *d;

        d = zhash_first (c->disconnect_notify);
        while (d) {
            disconnect_destroy (c, d);
            d = zhash_next (c->disconnect_notify);
        }
        zhash_destroy (&c->disconnect_notify);
    }
    if (c->subscriptions) {
        while ((sub = zlist_pop (c->subscriptions)))
            subscription_destroy (ctx->h, sub);
        zlist_destroy (&c->subscriptions);
    }
    if (c->uuid)
        zuuid_destroy (&c->uuid);
    if (c->outqueue) {
        flux_msg_t *msg;
        while ((msg = zlist_pop (c->outqueue)))
            flux_msg_destroy (msg);
        zlist_destroy (&c->outqueue);
    }
    flux_fd_watcher_stop (ctx->h, c->outw);
    flux_fd_watcher_destroy (c->outw);
    flux_msg_iobuf_clean (&c->outbuf);

    flux_fd_watcher_stop (ctx->h, c->inw);
    flux_fd_watcher_destroy (c->inw);
    flux_msg_iobuf_clean (&c->inbuf);

    if (c->fd != -1)
        close (c->fd);

    free (c);
}
예제 #20
0
파일: zyre_event.c 프로젝트: zeromq/zyre
void
zyre_event_print (zyre_event_t *self)
{
    zsys_info ("zyre_event:");
    zsys_info (" - from name=%s uuid=%s",
        zyre_event_peer_name (self),
        zyre_event_peer_uuid (self));
    zsys_info (" - type=%s", self->type);

    if (streq (self->type, "ENTER")) {
        void *item;
        zsys_info (" - headers=%zu:", zhash_size (self->headers));
        for (item = zhash_first (self->headers); item != NULL;
                item = zhash_next (self->headers))
            zyre_event_log_pair (zhash_cursor (self->headers), item, self);
        zsys_info (" - address=%s", zyre_event_peer_addr (self));
    }
    else
    if (streq (self->type, "JOIN")) {
        zsys_info (" - group=%s", zyre_event_group (self));
    }
    else
    if (streq (self->type, "LEAVE")) {
        zsys_info (" - group=%s", zyre_event_group (self));
    }
    else
    if (streq (self->type, "SHOUT")) {
        zsys_info (" - message:");
        zmsg_print (self->msg);
    }
    else
    if (streq (self->type, "WHISPER")) {
        zsys_info (" - message:");
        zmsg_print (self->msg);
    }
    else
    if (streq (self->type, "LEADER")) {
        zsys_info (" - group=%s", zyre_event_group (self));
    }
}
예제 #21
0
int
zproto_example_send (zproto_example_t *self, zsock_t *output)
{
    assert (self);
    assert (output);

    if (zsock_type (output) == ZMQ_ROUTER)
        zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE);

    size_t frame_size = 2 + 1;          //  Signature and message ID
    switch (self->id) {
        case ZPROTO_EXAMPLE_LOG:
            frame_size += 2;            //  sequence
            frame_size += 2;            //  version
            frame_size += 1;            //  level
            frame_size += 1;            //  event
            frame_size += 2;            //  node
            frame_size += 2;            //  peer
            frame_size += 8;            //  time
            frame_size += 1 + strlen (self->host);
            frame_size += 4;
            if (self->data)
                frame_size += strlen (self->data);
            break;
        case ZPROTO_EXAMPLE_STRUCTURES:
            frame_size += 2;            //  sequence
            frame_size += 4;            //  Size is 4 octets
            if (self->aliases) {
                char *aliases = (char *) zlist_first (self->aliases);
                while (aliases) {
                    frame_size += 4 + strlen (aliases);
                    aliases = (char *) zlist_next (self->aliases);
                }
            }
            frame_size += 4;            //  Size is 4 octets
            if (self->headers) {
                self->headers_bytes = 0;
                char *item = (char *) zhash_first (self->headers);
                while (item) {
                    self->headers_bytes += 1 + strlen (zhash_cursor (self->headers));
                    self->headers_bytes += 4 + strlen (item);
                    item = (char *) zhash_next (self->headers);
                }
            }
            frame_size += self->headers_bytes;
            break;
        case ZPROTO_EXAMPLE_BINARY:
            frame_size += 2;            //  sequence
            frame_size += 4;            //  flags
            frame_size += 4;            //  Size is 4 octets
            if (self->public_key)
                frame_size += zchunk_size (self->public_key);
            frame_size += ZUUID_LEN;    //  identifier
            break;
        case ZPROTO_EXAMPLE_TYPES:
            frame_size += 2;            //  sequence
            frame_size += 1 + strlen (self->client_forename);
            frame_size += 1 + strlen (self->client_surname);
            frame_size += 1 + strlen (self->client_mobile);
            frame_size += 1 + strlen (self->client_email);
            frame_size += 1 + strlen (self->supplier_forename);
            frame_size += 1 + strlen (self->supplier_surname);
            frame_size += 1 + strlen (self->supplier_mobile);
            frame_size += 1 + strlen (self->supplier_email);
            break;
    }
    //  Now serialize message into the frame
    zmq_msg_t frame;
    zmq_msg_init_size (&frame, frame_size);
    self->needle = (byte *) zmq_msg_data (&frame);
    PUT_NUMBER2 (0xAAA0 | 0);
    PUT_NUMBER1 (self->id);
    bool have_content = false;
    size_t nbr_frames = 1;              //  Total number of frames to send

    switch (self->id) {
        case ZPROTO_EXAMPLE_LOG:
            PUT_NUMBER2 (self->sequence);
            PUT_NUMBER2 (3);
            PUT_NUMBER1 (self->level);
            PUT_NUMBER1 (self->event);
            PUT_NUMBER2 (self->node);
            PUT_NUMBER2 (self->peer);
            PUT_NUMBER8 (self->time);
            PUT_STRING (self->host);
            if (self->data) {
                PUT_LONGSTR (self->data);
            }
            else
                PUT_NUMBER4 (0);    //  Empty string
            break;

        case ZPROTO_EXAMPLE_STRUCTURES:
            PUT_NUMBER2 (self->sequence);
            if (self->aliases) {
                PUT_NUMBER4 (zlist_size (self->aliases));
                char *aliases = (char *) zlist_first (self->aliases);
                while (aliases) {
                    PUT_LONGSTR (aliases);
                    aliases = (char *) zlist_next (self->aliases);
                }
            }
            else
                PUT_NUMBER4 (0);    //  Empty string array
            if (self->headers) {
                PUT_NUMBER4 (zhash_size (self->headers));
                char *item = (char *) zhash_first (self->headers);
                while (item) {
                    PUT_STRING (zhash_cursor (self->headers));
                    PUT_LONGSTR (item);
                    item = (char *) zhash_next (self->headers);
                }
            }
            else
                PUT_NUMBER4 (0);    //  Empty hash
            break;

        case ZPROTO_EXAMPLE_BINARY:
            PUT_NUMBER2 (self->sequence);
            PUT_OCTETS (self->flags, 4);
            if (self->public_key) {
                PUT_NUMBER4 (zchunk_size (self->public_key));
                memcpy (self->needle,
                        zchunk_data (self->public_key),
                        zchunk_size (self->public_key));
                self->needle += zchunk_size (self->public_key);
            }
            else
                PUT_NUMBER4 (0);    //  Empty chunk
            if (self->identifier)
                zuuid_export (self->identifier, self->needle);
            else
                memset (self->needle, 0, ZUUID_LEN);
            self->needle += ZUUID_LEN;
            nbr_frames++;
            nbr_frames += self->content? zmsg_size (self->content): 1;
            have_content = true;
            break;

        case ZPROTO_EXAMPLE_TYPES:
            PUT_NUMBER2 (self->sequence);
            PUT_STRING (self->client_forename);
            PUT_STRING (self->client_surname);
            PUT_STRING (self->client_mobile);
            PUT_STRING (self->client_email);
            PUT_STRING (self->supplier_forename);
            PUT_STRING (self->supplier_surname);
            PUT_STRING (self->supplier_mobile);
            PUT_STRING (self->supplier_email);
            break;

    }
    //  Now send the data frame
    zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0);

    //  Now send any frame fields, in order
    if (self->id == ZPROTO_EXAMPLE_BINARY) {
        //  If address isn't set, send an empty frame
        if (self->address)
            zframe_send (&self->address, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0));
        else
            zmq_send (zsock_resolve (output), NULL, 0, (--nbr_frames? ZMQ_SNDMORE: 0));
    }
    //  Now send the content if necessary
    if (have_content) {
        if (self->content) {
            zframe_t *frame = zmsg_first (self->content);
            while (frame) {
                zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0));
                frame = zmsg_next (self->content);
            }
        }
        else
            zmq_send (zsock_resolve (output), NULL, 0, 0);
    }
    return 0;
}
예제 #22
0
파일: zargs.c 프로젝트: luccasmenezes/czmq
const char *
zargs_param_next (zargs_t *self) {
    assert (self);
    return (const char*) zhash_next (self->parameters);
}
예제 #23
0
void
zproto_example_print (zproto_example_t *self)
{
    assert (self);
    switch (self->id) {
        case ZPROTO_EXAMPLE_LOG:
            zsys_debug ("ZPROTO_EXAMPLE_LOG:");
            zsys_debug ("    sequence=%ld", (long) self->sequence);
            zsys_debug ("    version=3");
            zsys_debug ("    level=%ld", (long) self->level);
            zsys_debug ("    event=%ld", (long) self->event);
            zsys_debug ("    node=%ld", (long) self->node);
            zsys_debug ("    peer=%ld", (long) self->peer);
            zsys_debug ("    time=%ld", (long) self->time);
            zsys_debug ("    host='%s'", self->host);
            if (self->data)
                zsys_debug ("    data='%s'", self->data);
            else
                zsys_debug ("    data=");
            break;

        case ZPROTO_EXAMPLE_STRUCTURES:
            zsys_debug ("ZPROTO_EXAMPLE_STRUCTURES:");
            zsys_debug ("    sequence=%ld", (long) self->sequence);
            zsys_debug ("    aliases=");
            if (self->aliases) {
                char *aliases = (char *) zlist_first (self->aliases);
                while (aliases) {
                    zsys_debug ("        '%s'", aliases);
                    aliases = (char *) zlist_next (self->aliases);
                }
            }
            zsys_debug ("    headers=");
            if (self->headers) {
                char *item = (char *) zhash_first (self->headers);
                while (item) {
                    zsys_debug ("        %s=%s", zhash_cursor (self->headers), item);
                    item = (char *) zhash_next (self->headers);
                }
            }
            else
                zsys_debug ("(NULL)");
            break;

        case ZPROTO_EXAMPLE_BINARY:
            zsys_debug ("ZPROTO_EXAMPLE_BINARY:");
            zsys_debug ("    sequence=%ld", (long) self->sequence);
            zsys_debug ("    flags=[ ... ]");
            zsys_debug ("    public_key=[ ... ]");
            zsys_debug ("    identifier=");
            if (self->identifier)
                zsys_debug ("        %s", zuuid_str_canonical (self->identifier));
            else
                zsys_debug ("        (NULL)");
            zsys_debug ("    address=");
            if (self->address)
                zframe_print (self->address, NULL);
            else
                zsys_debug ("(NULL)");
            zsys_debug ("    content=");
            if (self->content)
                zmsg_print (self->content);
            else
                zsys_debug ("(NULL)");
            break;

        case ZPROTO_EXAMPLE_TYPES:
            zsys_debug ("ZPROTO_EXAMPLE_TYPES:");
            zsys_debug ("    sequence=%ld", (long) self->sequence);
            zsys_debug ("    client_forename='%s'", self->client_forename);
            zsys_debug ("    client_surname='%s'", self->client_surname);
            zsys_debug ("    client_mobile='%s'", self->client_mobile);
            zsys_debug ("    client_email='%s'", self->client_email);
            zsys_debug ("    supplier_forename='%s'", self->supplier_forename);
            zsys_debug ("    supplier_surname='%s'", self->supplier_surname);
            zsys_debug ("    supplier_mobile='%s'", self->supplier_mobile);
            zsys_debug ("    supplier_email='%s'", self->supplier_email);
            break;

    }
}
예제 #24
0
파일: zyre_node.c 프로젝트: opedroso/zyre
void
zyre_node_actor (zsock_t *pipe, void *args)
{
    //  Create node instance to pass around
    zyre_node_t *self = zyre_node_new (pipe, args);
    if (!self)                  //  Interrupted
        return;

    //  Signal actor successfully initialized
    zsock_signal (self->pipe, 0);

    //  Loop until the agent is terminated one way or another
    int64_t reap_at = zclock_mono () + REAP_INTERVAL;
    while (!self->terminated) {

        // Start beacon as soon as we can
        if (self->beacon && self->port <= 0) {
            //  Our hostname is provided by zbeacon
            zsock_send(self->beacon, "si", "CONFIGURE", self->beacon_port);
            char *hostname = zstr_recv(self->beacon);

            // Is UDP broadcast interface available?
            if (!streq(hostname, "")) {
                if (zsys_ipv6())
                    self->port = zsock_bind(self->inbox, "tcp://%s%%%s:*", zsys_ipv6_address(), zsys_interface());
                else
                    self->port = zsock_bind(self->inbox, "tcp://%s:*", hostname);

                if (self->port > 0) {
                    assert(!self->endpoint);   //  If caller set this, we'd be using gossip
                    if (streq(zsys_interface(), "*")) {
                        char *hostname = zsys_hostname();
                        self->endpoint = zsys_sprintf("tcp://%s:%d", hostname, self->port);
                        zstr_free(&hostname);
                    }
                    else {
                        self->endpoint = strdup(zsock_endpoint(self->inbox));
                    }

                    //  Set broadcast/listen beacon
                    beacon_t beacon;
                    beacon.protocol[0] = 'Z';
                    beacon.protocol[1] = 'R';
                    beacon.protocol[2] = 'E';
                    beacon.version = BEACON_VERSION;
                    beacon.port = htons(self->port);
                    zuuid_export(self->uuid, beacon.uuid);
                    zsock_send(self->beacon, "sbi", "PUBLISH",
                        (byte *)&beacon, sizeof(beacon_t), self->interval);
                    zsock_send(self->beacon, "sb", "SUBSCRIBE", (byte *) "ZRE", 3);
                    zpoller_add(self->poller, self->beacon);

                    //  Start polling on inbox
                    zpoller_add(self->poller, self->inbox);
                }
            }
            zstr_free(&hostname);
        }

        int timeout = (int) (reap_at - zclock_mono ());
        if (timeout > REAP_INTERVAL)
            timeout = REAP_INTERVAL;
        else
        if (timeout < 0)
            timeout = 0;

        zsock_t *which = (zsock_t *) zpoller_wait (self->poller, timeout);
        if (which == self->pipe)
            zyre_node_recv_api (self);
        else
        if (which == self->inbox)
            zyre_node_recv_peer (self);
        else
        if (self->beacon
        && (void *) which == self->beacon)
            zyre_node_recv_beacon (self);
        else
        if (self->gossip
        && (zactor_t *) which == self->gossip)
            zyre_node_recv_gossip (self);
        else
        if (zpoller_terminated (self->poller))
            break;          //  Interrupted, check before expired
        else
        if (zpoller_expired (self->poller)) {
            if (zclock_mono () >= reap_at) {
                void *item;
                reap_at = zclock_mono () + REAP_INTERVAL;
                //  Ping all peers and reap any expired ones
                for (item = zhash_first (self->peers); item != NULL;
                        item = zhash_next (self->peers))
                    zyre_node_ping_peer (zhash_cursor (self->peers), item, self);
            }
        }
    }
    zyre_node_destroy (&self);
}
예제 #25
0
파일: static_data.c 프로젝트: Quinchu/R1EMU
void staticDataDebug(StaticData *self, void (*printer)(void *object)) {
    for (void *object = zhash_first(self->hashtable); object != NULL; object = zhash_next(self->hashtable)) {
        printer(object);
    }
}
예제 #26
0
파일: zyre_node.c 프로젝트: opedroso/zyre
static void
zyre_node_recv_api (zyre_node_t *self)
{
    //  Get the whole message off the pipe in one go
    zmsg_t *request = zmsg_recv (self->pipe);
    if (!request)
        return;                 //  Interrupted

    char *command = zmsg_popstr (request);
    if (streq (command, "UUID"))
        zstr_send (self->pipe, zuuid_str (self->uuid));
    else
    if (streq (command, "NAME"))
        zstr_send (self->pipe, self->name);
    else
    if (streq (command, "SET NAME")) {
        free (self->name);
        self->name = zmsg_popstr (request);
        assert (self->name);
    }
    else
    if (streq (command, "SET HEADER")) {
        char *name = zmsg_popstr (request);
        char *value = zmsg_popstr (request);
        zhash_update (self->headers, name, value);
        zstr_free (&name);
        zstr_free (&value);
    }
    else
    if (streq (command, "SET VERBOSE"))
        self->verbose = true;
    else
    if (streq (command, "SET PORT")) {
        char *value = zmsg_popstr (request);
        self->beacon_port = atoi (value);
        zstr_free (&value);
    }
    else
    if (streq (command, "SET EVASIVE TIMEOUT")) {
        char *value = zmsg_popstr (request);
        self->evasive_timeout = atoi (value);
        zstr_free (&value);
    }
    else
    if (streq (command, "SET EXPIRED TIMEOUT")) {
        char *value = zmsg_popstr (request);
        self->expired_timeout = atoi (value);
        zstr_free (&value);
    }
    else
    if (streq (command, "SET INTERVAL")) {
        char *value = zmsg_popstr (request);
        self->interval = atol (value);
        zstr_free (&value);
    }
    else
    if (streq (command, "SET ENDPOINT")) {
        zyre_node_gossip_start (self);
        char *endpoint = zmsg_popstr (request);
        if (zsock_bind (self->inbox, "%s", endpoint) != -1) {
            zstr_free (&self->endpoint);
            self->endpoint = endpoint;
            zsock_signal (self->pipe, 0);
        }
        else {
            zstr_free (&endpoint);
            zsock_signal (self->pipe, 1);
        }
    }
    else
    if (streq (command, "GOSSIP BIND")) {
        zyre_node_gossip_start (self);
        zstr_free (&self->gossip_bind);
        self->gossip_bind = zmsg_popstr (request);
        zstr_sendx (self->gossip, "BIND", self->gossip_bind, NULL);
    }
    else
    if (streq (command, "GOSSIP CONNECT")) {
        zyre_node_gossip_start (self);
        zstr_free (&self->gossip_connect);
        self->gossip_connect = zmsg_popstr (request);
        zstr_sendx (self->gossip, "CONNECT", self->gossip_connect, NULL);
    }
    else
    if (streq (command, "START"))
        zsock_signal (self->pipe, zyre_node_start (self));
    else
    if (streq (command, "STOP"))
        zsock_signal (self->pipe, zyre_node_stop (self));
    else
    if (streq (command, "WHISPER")) {
        //  Get peer to send message to
        char *identity = zmsg_popstr (request);
        zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, identity);

        //  Send frame on out to peer's mailbox, drop message
        //  if peer doesn't exist (may have been destroyed)
        if (peer) {
            zre_msg_t *msg = zre_msg_new (ZRE_MSG_WHISPER);
            zre_msg_set_content (msg, &request);
            zyre_peer_send (peer, &msg);
        }
        zstr_free (&identity);
    }
    else
    if (streq (command, "SHOUT")) {
        //  Get group to send message to
        char *name = zmsg_popstr (request);
        zyre_group_t *group = (zyre_group_t *) zhash_lookup (self->peer_groups, name);
        if (group) {
            zre_msg_t *msg = zre_msg_new (ZRE_MSG_SHOUT);
            zre_msg_set_group (msg, name);
            zre_msg_set_content (msg, &request);
            zyre_group_send (group, &msg);
        }
        zstr_free (&name);
    }
    else
    if (streq (command, "JOIN")) {
        char *name = zmsg_popstr (request);
        if (!zlist_exists (self->own_groups, name)) {
            void *item;
            //  Only send if we're not already in group
            zlist_append (self->own_groups, name);
            zre_msg_t *msg = zre_msg_new (ZRE_MSG_JOIN);
            zre_msg_set_group (msg, name);
            //  Update status before sending command
            zre_msg_set_status (msg, ++(self->status));
            for (item = zhash_first (self->peers); item != NULL;
                    item = zhash_next (self->peers))
                zyre_node_send_peer (zhash_cursor (self->peers), item, msg);
            zre_msg_destroy (&msg);
            if (self->verbose)
                zsys_info ("(%s) JOIN group=%s", self->name, name);
        }
        zstr_free (&name);
    }
    else
    if (streq (command, "LEAVE")) {
        char *name = zmsg_popstr (request);
        if (zlist_exists (self->own_groups, name)) {
            void *item;
            //  Only send if we are actually in group
            zre_msg_t *msg = zre_msg_new (ZRE_MSG_LEAVE);
            zre_msg_set_group (msg, name);
            //  Update status before sending command
            zre_msg_set_status (msg, ++(self->status));
            for (item = zhash_first (self->peers); item != NULL;
                    item = zhash_next (self->peers))
                zyre_node_send_peer (zhash_cursor (self->peers), item, msg);
            zre_msg_destroy (&msg);
            zlist_remove (self->own_groups, name);
            if (self->verbose)
                zsys_info ("(%s) LEAVE group=%s", self->name, name);
        }
        zstr_free (&name);
    }
    else
    if (streq (command, "PEERS"))
        zsock_send (self->pipe, "p", zhash_keys (self->peers));
    else
    if (streq (command, "GROUP PEERS")) {
        char *name = zmsg_popstr (request);
        zyre_group_t *group = (zyre_group_t *) zhash_lookup (self->peer_groups, name);
        if (group)
            zsock_send (self->pipe, "p", zyre_group_peers (group));
        else
            zsock_send (self->pipe, "p", NULL);

        zstr_free (&name);
    }
    else
    if (streq (command, "PEER ENDPOINT")) {
        char *uuid = zmsg_popstr (request);
        zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, uuid);
        assert (peer);
        zsock_send (self->pipe, "s", zyre_peer_endpoint (peer));
        zstr_free (&uuid);
    }
    else
    if (streq (command, "PEER NAME")) {
        char *uuid = zmsg_popstr (request);
        zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, uuid);
        assert (peer);
        zsock_send (self->pipe, "s", zyre_peer_name (peer));
        zstr_free (&uuid);
    }
    else
    if (streq (command, "PEER HEADER")) {
        char *uuid = zmsg_popstr (request);
        char *key = zmsg_popstr (request);
        zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, uuid);
        if (!peer)
            zstr_send (self->pipe, "");
        else
            zstr_send (self->pipe, zyre_peer_header (peer, key, NULL));
        zstr_free (&uuid);
        zstr_free (&key);
    }
    else
    if (streq (command, "PEER GROUPS"))
        zsock_send (self->pipe, "p", zhash_keys (self->peer_groups));
    else
    if (streq (command, "OWN GROUPS"))
        zsock_send (self->pipe, "p", zlist_dup (self->own_groups));
    else
    if (streq (command, "DUMP"))
        zyre_node_dump (self);
    else
    if (streq (command, "$TERM"))
        self->terminated = true;
    else {
        zsys_error ("invalid command '%s'", command);
        assert (false);
    }
    zstr_free (&command);
    zmsg_destroy (&request);
}
예제 #27
0
파일: qzhash.cpp 프로젝트: atocall/zyre
///
//  Simple iterator; returns next item in hash table, in no given order, 
//  or NULL if the last item was already returned. Use this together with
//  zhash_first() to process all items in a hash table. If you need the  
//  items in sorted order, use zhash_keys() and then zlist_sort(). To    
//  access the key for this item use zhash_cursor(). NOTE: do NOT modify 
//  the table while iterating.                                           
void * QZhash::next ()
{
    void * rv = zhash_next (self);
    return rv;
}
예제 #28
0
파일: attr.c 프로젝트: tpatki/flux-core
const char *attr_next (attr_t *attrs)
{
    struct entry *e = zhash_next (attrs->hash);
    return e ? e->name : NULL;
}
예제 #29
0
파일: fmq_msg.c 프로젝트: hintjens/filemq
int
fmq_msg_send (fmq_msg_t *self, zsock_t *output)
{
    assert (self);
    assert (output);

    if (zsock_type (output) == ZMQ_ROUTER)
        zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE);

    size_t frame_size = 2 + 1;          //  Signature and message ID
    switch (self->id) {
        case FMQ_MSG_OHAI:
            frame_size += 1 + strlen ("FILEMQ");
            frame_size += 2;            //  version
            break;
        case FMQ_MSG_ICANHAZ:
            frame_size += 4;
            if (self->path)
                frame_size += strlen (self->path);
            frame_size += 4;            //  Size is 4 octets
            if (self->options) {
                self->options_bytes = 0;
                char *item = (char *) zhash_first (self->options);
                while (item) {
                    self->options_bytes += 1 + strlen (zhash_cursor (self->options));
                    self->options_bytes += 4 + strlen (item);
                    item = (char *) zhash_next (self->options);
                }
            }
            frame_size += self->options_bytes;
            frame_size += 4;            //  Size is 4 octets
            if (self->cache) {
                self->cache_bytes = 0;
                char *item = (char *) zhash_first (self->cache);
                while (item) {
                    self->cache_bytes += 1 + strlen (zhash_cursor (self->cache));
                    self->cache_bytes += 4 + strlen (item);
                    item = (char *) zhash_next (self->cache);
                }
            }
            frame_size += self->cache_bytes;
            break;
        case FMQ_MSG_NOM:
            frame_size += 8;            //  credit
            frame_size += 8;            //  sequence
            break;
        case FMQ_MSG_CHEEZBURGER:
            frame_size += 8;            //  sequence
            frame_size += 1;            //  operation
            frame_size += 4;
            if (self->filename)
                frame_size += strlen (self->filename);
            frame_size += 8;            //  offset
            frame_size += 1;            //  eof
            frame_size += 4;            //  Size is 4 octets
            if (self->headers) {
                self->headers_bytes = 0;
                char *item = (char *) zhash_first (self->headers);
                while (item) {
                    self->headers_bytes += 1 + strlen (zhash_cursor (self->headers));
                    self->headers_bytes += 4 + strlen (item);
                    item = (char *) zhash_next (self->headers);
                }
            }
            frame_size += self->headers_bytes;
            frame_size += 4;            //  Size is 4 octets
            if (self->chunk)
                frame_size += zchunk_size (self->chunk);
            break;
        case FMQ_MSG_SRSLY:
            frame_size += 1 + strlen (self->reason);
            break;
        case FMQ_MSG_RTFM:
            frame_size += 1 + strlen (self->reason);
            break;
    }
    //  Now serialize message into the frame
    zmq_msg_t frame;
    zmq_msg_init_size (&frame, frame_size);
    self->needle = (byte *) zmq_msg_data (&frame);
    PUT_NUMBER2 (0xAAA0 | 3);
    PUT_NUMBER1 (self->id);
    size_t nbr_frames = 1;              //  Total number of frames to send

    switch (self->id) {
        case FMQ_MSG_OHAI:
            PUT_STRING ("FILEMQ");
            PUT_NUMBER2 (FMQ_MSG_VERSION);
            break;

        case FMQ_MSG_ICANHAZ:
            if (self->path) {
                PUT_LONGSTR (self->path);
            }
            else
                PUT_NUMBER4 (0);    //  Empty string
            if (self->options) {
                PUT_NUMBER4 (zhash_size (self->options));
                char *item = (char *) zhash_first (self->options);
                while (item) {
                    PUT_STRING (zhash_cursor (self->options));
                    PUT_LONGSTR (item);
                    item = (char *) zhash_next (self->options);
                }
            }
            else
                PUT_NUMBER4 (0);    //  Empty hash
            if (self->cache) {
                PUT_NUMBER4 (zhash_size (self->cache));
                char *item = (char *) zhash_first (self->cache);
                while (item) {
                    PUT_STRING (zhash_cursor (self->cache));
                    PUT_LONGSTR (item);
                    item = (char *) zhash_next (self->cache);
                }
            }
            else
                PUT_NUMBER4 (0);    //  Empty hash
            break;

        case FMQ_MSG_NOM:
            PUT_NUMBER8 (self->credit);
            PUT_NUMBER8 (self->sequence);
            break;

        case FMQ_MSG_CHEEZBURGER:
            PUT_NUMBER8 (self->sequence);
            PUT_NUMBER1 (self->operation);
            if (self->filename) {
                PUT_LONGSTR (self->filename);
            }
            else
                PUT_NUMBER4 (0);    //  Empty string
            PUT_NUMBER8 (self->offset);
            PUT_NUMBER1 (self->eof);
            if (self->headers) {
                PUT_NUMBER4 (zhash_size (self->headers));
                char *item = (char *) zhash_first (self->headers);
                while (item) {
                    PUT_STRING (zhash_cursor (self->headers));
                    PUT_LONGSTR (item);
                    item = (char *) zhash_next (self->headers);
                }
            }
            else
                PUT_NUMBER4 (0);    //  Empty hash
            if (self->chunk) {
                PUT_NUMBER4 (zchunk_size (self->chunk));
                memcpy (self->needle,
                        zchunk_data (self->chunk),
                        zchunk_size (self->chunk));
                self->needle += zchunk_size (self->chunk);
            }
            else
                PUT_NUMBER4 (0);    //  Empty chunk
            break;

        case FMQ_MSG_SRSLY:
            PUT_STRING (self->reason);
            break;

        case FMQ_MSG_RTFM:
            PUT_STRING (self->reason);
            break;

    }
    //  Now send the data frame
    zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0);

    return 0;
}
예제 #30
0
파일: fmq_msg.c 프로젝트: hintjens/filemq
void
fmq_msg_print (fmq_msg_t *self)
{
    assert (self);
    switch (self->id) {
        case FMQ_MSG_OHAI:
            zsys_debug ("FMQ_MSG_OHAI:");
            zsys_debug ("    protocol=filemq");
            zsys_debug ("    version=fmq_msg_version");
            break;

        case FMQ_MSG_OHAI_OK:
            zsys_debug ("FMQ_MSG_OHAI_OK:");
            break;

        case FMQ_MSG_ICANHAZ:
            zsys_debug ("FMQ_MSG_ICANHAZ:");
            if (self->path)
                zsys_debug ("    path='%s'", self->path);
            else
                zsys_debug ("    path=");
            zsys_debug ("    options=");
            if (self->options) {
                char *item = (char *) zhash_first (self->options);
                while (item) {
                    zsys_debug ("        %s=%s", zhash_cursor (self->options), item);
                    item = (char *) zhash_next (self->options);
                }
            }
            else
                zsys_debug ("(NULL)");
            zsys_debug ("    cache=");
            if (self->cache) {
                char *item = (char *) zhash_first (self->cache);
                while (item) {
                    zsys_debug ("        %s=%s", zhash_cursor (self->cache), item);
                    item = (char *) zhash_next (self->cache);
                }
            }
            else
                zsys_debug ("(NULL)");
            break;

        case FMQ_MSG_ICANHAZ_OK:
            zsys_debug ("FMQ_MSG_ICANHAZ_OK:");
            break;

        case FMQ_MSG_NOM:
            zsys_debug ("FMQ_MSG_NOM:");
            zsys_debug ("    credit=%ld", (long) self->credit);
            zsys_debug ("    sequence=%ld", (long) self->sequence);
            break;

        case FMQ_MSG_CHEEZBURGER:
            zsys_debug ("FMQ_MSG_CHEEZBURGER:");
            zsys_debug ("    sequence=%ld", (long) self->sequence);
            zsys_debug ("    operation=%ld", (long) self->operation);
            if (self->filename)
                zsys_debug ("    filename='%s'", self->filename);
            else
                zsys_debug ("    filename=");
            zsys_debug ("    offset=%ld", (long) self->offset);
            zsys_debug ("    eof=%ld", (long) self->eof);
            zsys_debug ("    headers=");
            if (self->headers) {
                char *item = (char *) zhash_first (self->headers);
                while (item) {
                    zsys_debug ("        %s=%s", zhash_cursor (self->headers), item);
                    item = (char *) zhash_next (self->headers);
                }
            }
            else
                zsys_debug ("(NULL)");
            zsys_debug ("    chunk=[ ... ]");
            break;

        case FMQ_MSG_HUGZ:
            zsys_debug ("FMQ_MSG_HUGZ:");
            break;

        case FMQ_MSG_HUGZ_OK:
            zsys_debug ("FMQ_MSG_HUGZ_OK:");
            break;

        case FMQ_MSG_KTHXBAI:
            zsys_debug ("FMQ_MSG_KTHXBAI:");
            break;

        case FMQ_MSG_SRSLY:
            zsys_debug ("FMQ_MSG_SRSLY:");
            zsys_debug ("    reason='%s'", self->reason);
            break;

        case FMQ_MSG_RTFM:
            zsys_debug ("FMQ_MSG_RTFM:");
            zsys_debug ("    reason='%s'", self->reason);
            break;

    }
}