/** * Destroy the ccnr instance, releasing all associated resources. */ PUBLIC void r_init_destroy(struct ccnr_handle **pccnr) { struct ccnr_handle *h = *pccnr; int stable; if (h == NULL) return; stable = h->active_in_fd == -1 ? 1 : 0; r_io_shutdown_all(h); ccnr_direct_client_stop(h); ccn_schedule_destroy(&h->sched); hashtb_destroy(&h->propagating_tab); hashtb_destroy(&h->nameprefix_tab); hashtb_destroy(&h->enum_state_tab); hashtb_destroy(&h->content_by_accession_tab); // SyncActions sync_stop method should be shutting down heartbeat if (h->sync_plumbing) { h->sync_plumbing->sync_methods->sync_stop(h->sync_plumbing, NULL); free(h->sync_plumbing); h->sync_plumbing = NULL; h->sync_base = NULL; // freed by sync_stop ? } r_store_final(h, stable); if (h->fds != NULL) { free(h->fds); h->fds = NULL; h->nfds = 0; } if (h->fdholder_by_fd != NULL) { free(h->fdholder_by_fd); h->fdholder_by_fd = NULL; h->face_limit = h->face_gen = 0; } if (h->content_by_cookie != NULL) { free(h->content_by_cookie); h->content_by_cookie = NULL; h->cookie_limit = 1; } ccn_charbuf_destroy(&h->scratch_charbuf); ccn_indexbuf_destroy(&h->skiplinks); ccn_indexbuf_destroy(&h->scratch_indexbuf); ccn_indexbuf_destroy(&h->unsol); if (h->parsed_policy != NULL) { ccn_indexbuf_destroy(&h->parsed_policy->namespaces); ccn_charbuf_destroy(&h->parsed_policy->store); free(h->parsed_policy); h->parsed_policy = NULL; } ccn_charbuf_destroy(&h->policy_name); ccn_charbuf_destroy(&h->policy_link_cob); ccn_charbuf_destroy(&h->ccnr_keyid); free(h); *pccnr = NULL; }
int main(int argc, char *argv[]) { const char *progname = argv[0]; struct ccn_ping_client client = {.sent = 0, .received = 0, .total = -1, .number = -1, .interval = 1}; struct ccn_closure in_content = {.p = &incoming_content}; struct hashtb_param param = {0}; int res; struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = &handle_interrupt; sigaction(SIGINT, &sa, &osa); memset(&sta, 0, sizeof(sta)); gettimeofday(&sta.start, 0); sta.min = INT_MAX; while ((res = getopt(argc, argv, "hi:c:n:")) != -1) { switch (res) { case 'c': client.total = atol(optarg); if (client.total <= 0) usage(progname); break; case 'i': client.interval = atof(optarg); if (client.interval < PING_MIN_INTERVAL) usage(progname); break; case 'n': client.number = atol(optarg); if (client.number < 0) usage(progname); break; case 'h': default: usage(progname); break; } } if (client.number < 0) srandom(time(NULL)); argc -= optind; argv += optind; if (argv[0] == NULL) usage(progname); sta.prefix = argv[0]; client.original_prefix = argv[0]; client.prefix = ccn_charbuf_create(); res = ccn_name_from_uri(client.prefix, argv[0]); if (res < 0) { fprintf(stderr, "%s: bad ccn URI: %s\n", progname, argv[0]); exit(1); } if (argv[1] != NULL) fprintf(stderr, "%s warning: extra arguments ignored\n", progname); //append "/ping" to the given name prefix res = ccn_name_append_str(client.prefix, PING_COMPONENT); if (res < 0) { fprintf(stderr, "%s: error constructing ccn URI: %s/%s\n", progname, argv[0], PING_COMPONENT); exit(1); } /* Connect to ccnd */ client.h = ccn_create(); if (ccn_connect(client.h, NULL) == -1) { perror("Could not connect to ccnd"); exit(1); } client.closure = &in_content; in_content.data = &client; client.ccn_ping_table = hashtb_create(sizeof(struct ccn_ping_entry), ¶m); client.sched = ccn_schedule_create(&client, &ccn_ping_ticker); client.event = ccn_schedule_event(client.sched, 0, &do_ping, NULL, 0); printf("CCNPING %s\n", client.original_prefix); res = 0; while (res >= 0 && (client.total <= 0 || client.sent < client.total || hashtb_n(client.ccn_ping_table) > 0)) { if (client.total <= 0 || client.sent < client.total) ccn_schedule_run(client.sched); res = ccn_run(client.h, 10); } ccn_schedule_destroy(&client.sched); ccn_destroy(&client.h); ccn_charbuf_destroy(&client.prefix); print_statistics(); return 0; }