本文整理汇总了C++中ccn_charbuf_destroy函数的典型用法代码示例。如果您正苦于以下问题:C++ ccn_charbuf_destroy函数的具体用法?C++ ccn_charbuf_destroy怎么用?C++ ccn_charbuf_destroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ccn_charbuf_destroy函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: SyncCacheEntryFetch
extern int
SyncCacheEntryFetch(struct SyncHashCacheEntry *ce) {
// causes the cache entry to fetched from the repo
char *here = "Sync.SyncCacheEntryFetch";
int res = 0;
if (ce == NULL) {
// not an entry
res = -1;
} else if (ce->ncL != NULL) {
// it's already here
res = 0;
} else if ((ce->state & SyncHashState_stored) == 0) {
// it's never been stored, fail quietly
res = -1;
} else {
// at this point we try to fetch it from the local repo
// a failure should complain
struct SyncRootStruct *root = ce->head->root;
struct SyncBaseStruct *base = root->base;
struct ccn_charbuf *name = SyncNameForLocalNode(root, ce->hash);
struct ccn_charbuf *content = ccn_charbuf_create();
char *why = "no fetch";
struct ccn_parsed_ContentObject pcos;
res = SyncLocalRepoFetch(base, name, content, &pcos);
if (res >= 0) {
// parse the object
const unsigned char *xp = NULL;
size_t xs = 0;
// get the encoded node
res = ccn_content_get_value(content->buf, content->length,
&pcos, &xp, &xs);
if (res < 0)
why = "ccn_content_get_value failed";
else {
struct ccn_buf_decoder ds;
struct ccn_buf_decoder *d = ccn_buf_decoder_start(&ds, xp, xs);
struct SyncNodeComposite *nc = SyncAllocComposite(root->base);
res |= SyncParseComposite(nc, d);
if (res < 0) {
// failed, so back out of the allocations
why = "bad parse";
SyncFreeComposite(nc);
nc = NULL;
} else {
res = 1;
SyncNodeIncRC(nc);
ce->ncL = nc;
ce->state |= SyncHashState_stored;
}
}
}
if (res < 0)
if (root->base->debug >= CCNL_ERROR)
SyncNoteUri(root, here, why, name);
ccn_charbuf_destroy(&name);
ccn_charbuf_destroy(&content);
}
return res;
}
开发者ID:GabrielLiz,项目名称:ccnx,代码行数:60,代码来源:SyncHashCache.c
示例2: r_store_write_stable_point
/**
* Write a file named index/stable that contains the size of
* repoFile1 when the repository is shut down.
*/
static int
r_store_write_stable_point(struct ccnr_handle *h)
{
struct ccn_charbuf *path = NULL;
struct ccn_charbuf *cb = NULL;
int fd;
path = ccn_charbuf_create();
cb = ccn_charbuf_create();
ccn_charbuf_putf(path, "%s/index/stable", h->directory);
unlink(ccn_charbuf_as_string(path)); /* Should not exist, but just in case. */
fd = open(ccn_charbuf_as_string(path),
O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666);
if (fd == -1) {
ccnr_msg(h, "cannot write stable mark %s: %s",
ccn_charbuf_as_string(path), strerror(errno));
unlink(ccn_charbuf_as_string(path));
}
else {
ccn_charbuf_putf(cb, "%ju", (uintmax_t)(h->stable));
write(fd, cb->buf, cb->length);
close(fd);
if (CCNSHOULDLOG(h, dfsdf, CCNL_INFO))
ccnr_msg(h, "Index marked stable - %s", ccn_charbuf_as_string(cb));
}
ccn_charbuf_destroy(&path);
ccn_charbuf_destroy(&cb);
return(0);
}
开发者ID:Emat12,项目名称:ccnx,代码行数:33,代码来源:ccnr_store.c
示例3: ccn_fetch_close
/**
* Ends the download stream
*/
void CCNGet::endStream()
{
stream = ccn_fetch_close(stream);
ccn_destroy(&ccn);
ccn_charbuf_destroy(&templ);
ccn_charbuf_destroy(&name);
}
开发者ID:rodolfo-s-antunes,项目名称:ccnx-relations-streaming-experiment-cpp,代码行数:10,代码来源:CCNComm.cpp
示例4: get_orig_router_from_info_content_name
char *
get_orig_router_from_info_content_name(struct ccn_charbuf * content_name)
{
int start,end;
start=0;
struct ccn_indexbuf *comps=ccn_indexbuf_create();
ccn_name_split (content_name, comps);
end=check_for_name_component_in_name(content_name,comps,"nlsr");
struct ccn_charbuf *temp=ccn_charbuf_create();
ccn_name_init(temp);
ccn_name_append_components( temp, content_name->buf,
comps->buf[start],
comps->buf[end]);
struct ccn_charbuf *temp1=ccn_charbuf_create();
ccn_uri_append(temp1, temp->buf, temp->length, 0);
char *orig_router=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
sizeof(char));
memcpy(orig_router,ccn_charbuf_as_string(temp1),
strlen(ccn_charbuf_as_string(temp1)));
orig_router[strlen(orig_router)]='\0';
ccn_charbuf_destroy(&temp);
ccn_charbuf_destroy(&temp1);
ccn_indexbuf_destroy(&comps);
return orig_router;
}
开发者ID:akaash-nigam,项目名称:NLSR0.0,代码行数:35,代码来源:nlsr_km.c
示例5: ccns_slice_name
int
ccns_slice_name(struct ccn_charbuf *nm, struct ccns_slice *s)
{
struct ccn_charbuf *c;
struct ccn_digest *digest = NULL;
struct ccn_charbuf *hash = NULL;
int res = 0;
c = ccn_charbuf_create();
if (c == NULL)
return (-1);
res = append_slice(c, s);
if (res < 0)
goto Cleanup;
digest = ccn_digest_create(CCN_DIGEST_SHA256);
hash = ccn_charbuf_create_n(ccn_digest_size(digest));
if (hash == NULL)
goto Cleanup;
ccn_digest_init(digest);
res |= ccn_digest_update(digest, c->buf, c->length);
res |= ccn_digest_final(digest, hash->buf, hash->limit);
if (res < 0)
goto Cleanup;
hash->length = hash->limit;
if (ccn_name_from_uri(nm, "ccnx:/%C1.M.S.localhost/%C1.S.cs") < 0)
res = -1;
res |= ccn_name_append(nm, hash->buf, hash->length);
Cleanup:
ccn_charbuf_destroy(&c);
ccn_digest_destroy(&digest);
ccn_charbuf_destroy(&hash);
return (res);
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:35,代码来源:sync_api.c
示例6: seqw_incoming_interest
static enum ccn_upcall_res
seqw_incoming_interest(
struct ccn_closure *selfp,
enum ccn_upcall_kind kind,
struct ccn_upcall_info *info)
{
int res;
struct ccn_charbuf *cob = NULL;
struct ccn_seqwriter *w = selfp->data;
if (w == NULL || selfp != &(w->cl))
abort();
switch (kind) {
case CCN_UPCALL_FINAL:
ccn_charbuf_destroy(&w->nb);
ccn_charbuf_destroy(&w->nv);
ccn_charbuf_destroy(&w->buffer);
ccn_charbuf_destroy(&w->cob0);
free(w);
break;
case CCN_UPCALL_INTEREST:
if (w->closed || w->buffer->length > 0) {
cob = seqw_next_cob(w);
if (cob == NULL)
return(CCN_UPCALL_RESULT_OK);
if (ccn_content_matches_interest(cob->buf, cob->length,
1, NULL,
info->interest_ccnb,
info->pi->offset[CCN_PI_E],
info->pi)) {
w->interests_possibly_pending = 0;
res = ccn_put(info->h, cob->buf, cob->length);
if (res >= 0) {
w->buffer->length = 0;
w->seqnum++;
return(CCN_UPCALL_RESULT_INTEREST_CONSUMED);
}
}
ccn_charbuf_destroy(&cob);
}
if (w->cob0 != NULL) {
cob = w->cob0;
if (ccn_content_matches_interest(cob->buf, cob->length,
1, NULL,
info->interest_ccnb,
info->pi->offset[CCN_PI_E],
info->pi)) {
w->interests_possibly_pending = 0;
ccn_put(info->h, cob->buf, cob->length);
return(CCN_UPCALL_RESULT_INTEREST_CONSUMED);
}
}
w->interests_possibly_pending = 1;
break;
default:
break;
}
return(CCN_UPCALL_RESULT_OK);
}
开发者ID:hamhei,项目名称:ccnx,代码行数:59,代码来源:ccn_seqwriter.c
示例7: ccn_charbuf_create
/**
*
* Create new face by sending out a request Interest
* The actual new face instance is returned
*
*/
static
struct ccn_face_instance *create_face(struct ccn *h, struct ccn_charbuf *local_scope_template,
struct ccn_charbuf *no_name, struct ccn_face_instance *face_instance)
{
struct ccn_charbuf *newface = NULL;
struct ccn_charbuf *signed_info = NULL;
struct ccn_charbuf *temp = NULL;
struct ccn_charbuf *name = NULL;
struct ccn_charbuf *resultbuf = NULL;
struct ccn_parsed_ContentObject pcobuf = {0};
struct ccn_face_instance *new_face_instance = NULL;
const unsigned char *ptr = NULL;
size_t length = 0;
int res = 0;
/* Encode the given face instance */
newface = ccn_charbuf_create();
ccnb_append_face_instance(newface, face_instance);
temp = ccn_charbuf_create();
res = ccn_sign_content(h, temp, no_name, NULL, newface->buf, newface->length);
resultbuf = ccn_charbuf_create();
/* Construct the Interest name that will create the face */
name = ccn_charbuf_create();
ccn_name_init(name);
ccn_name_append_str(name, "ccnx");
ccn_name_append(name, face_instance->ccnd_id, face_instance->ccnd_id_size);
ccn_name_append_str(name, face_instance->action);
ccn_name_append(name, temp->buf, temp->length);
/* send Interest to retrieve Data that contains the newly created face */
res = ccn_get(h, name, local_scope_template, 1000, resultbuf, &pcobuf, NULL, 0);
ON_ERROR_CLEANUP(res);
/* decode Data to get the actual face instance */
res = ccn_content_get_value(resultbuf->buf, resultbuf->length, &pcobuf, &ptr, &length);
ON_ERROR_CLEANUP(res);
new_face_instance = ccn_face_instance_parse(ptr, length);
ccn_charbuf_destroy(&newface);
ccn_charbuf_destroy(&signed_info);
ccn_charbuf_destroy(&temp);
ccn_charbuf_destroy(&resultbuf);
ccn_charbuf_destroy(&name);
return new_face_instance;
cleanup:
ccn_charbuf_destroy(&newface);
ccn_charbuf_destroy(&signed_info);
ccn_charbuf_destroy(&temp);
ccn_charbuf_destroy(&resultbuf);
ccn_charbuf_destroy(&name);
return NULL;
}
开发者ID:akaash-nigam,项目名称:OSPFN2.0,代码行数:64,代码来源:ccn_fib.c
示例8: ccn_dhcp_entry_destroy
void ccn_dhcp_entry_destroy(struct ccn_dhcp_entry **de)
{
if (*de != NULL) {
ccn_charbuf_destroy(&(*de)->name_prefix);
ccn_charbuf_destroy(&(*de)->store);
free(*de);
*de = NULL;
}
}
开发者ID:NDN-Routing,项目名称:ccnx-dhcp,代码行数:9,代码来源:dhcp_helper.c
示例9: r_init_destroy
/**
* 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;
}
开发者ID:GabrielLiz,项目名称:ccnx,代码行数:60,代码来源:ccnr_init.c
示例10: ccn_fetch_close
/**
* Closes the stream and reclaims any resources used by the stream.
* The stream object will be freed, so the client must not access it again.
* @returns NULL in all cases.
*/
extern struct ccn_fetch_stream *
ccn_fetch_close(struct ccn_fetch_stream *fs) {
// destroys a ccn_fetch_stream object
// implicit abort of any outstanding fetches
// always returns NULL
int i;
FILE *debug = fs->parent->debug;
ccn_fetch_flags flags = fs->parent->debugFlags;
// make orphans of all outstanding requests
// CallMe should handle the cleanup
struct localClosure * this = fs->requests;
fs->requests = NULL;
while (this != NULL) {
this->fs = NULL;
this = this->next;
}
// free up the buffers
fs->maxBufs = 0;
PruneSegments(fs);
if (fs->name != NULL)
ccn_charbuf_destroy(&fs->name);
if (fs->interest != NULL)
ccn_charbuf_destroy(&fs->interest);
struct ccn_fetch *f = fs->parent;
if (f != NULL) {
int ns = f->nStreams;
fs->parent = NULL;
for (i = 0; i < ns; i++) {
struct ccn_fetch_stream *tfs = f->streams[i];
if (tfs == fs) {
// found it, so get rid of it
ns--;
f->nStreams = ns;
f->streams[i] = NULL;
f->streams[i] = f->streams[ns];
f->streams[ns] = NULL;
break;
}
}
}
if (debug != NULL && (flags & ccn_fetch_flags_NoteOpenClose)) {
fprintf(debug,
"-- ccn_fetch close, %s, segReq %jd, segsRead %jd, timeouts %jd\n",
fs->id,
fs->segsRequested,
fs->segsRead,
fs->timeoutsSeen);
fflush(debug);
}
// finally, get rid of the stream object
freeString(fs->id);
free(fs);
return NULL;
}
开发者ID:netharis,项目名称:ccnxaueb,代码行数:61,代码来源:ccn_fetch.c
示例11: ccn_strategy_selection_destroy
/**
* Destroy the result of ccn_strategy_selection_parse().
*/
void
ccn_strategy_selection_destroy(struct ccn_strategy_selection **pss)
{
if (*pss == NULL)
return;
ccn_charbuf_destroy(&(*pss)->name_prefix);
ccn_charbuf_destroy(&(*pss)->store);
free(*pss);
*pss = NULL;
}
开发者ID:GabrielLiz,项目名称:ccnx,代码行数:13,代码来源:ccn_strategy_mgmt.c
示例12: get_orig_router_from_lsa_name
char *
get_orig_router_from_lsa_name(struct ccn_charbuf * content_name)
{
int start=0;
size_t comp_size;
const unsigned char *second_last_comp;
char *second_comp_type;
char *sep=".";
char *rem;
struct ccn_indexbuf *components=ccn_indexbuf_create();
struct ccn_charbuf *name=ccn_charbuf_create();
ccn_name_from_uri(name,nlsr->slice_prefix);
ccn_name_split (name, components);
start=components->n-2;
ccn_charbuf_destroy(&name);
ccn_indexbuf_destroy(&components);
struct ccn_indexbuf *comps=ccn_indexbuf_create();
ccn_name_split (content_name, comps);
ccn_name_comp_get( content_name->buf, comps,
comps->n-1-2, &second_last_comp, &comp_size);
second_comp_type=strtok_r((char *)second_last_comp, sep, &rem);
if ( strcmp( second_comp_type, "lsId" ) == 0 ){
ccn_name_chop(content_name,comps,-3);
}
else{
ccn_name_chop(content_name,comps,-2);
}
struct ccn_charbuf *temp=ccn_charbuf_create();
ccn_name_init(temp);
ccn_name_append_components( temp, content_name->buf,
comps->buf[start+1],
comps->buf[comps->n - 1]);
struct ccn_charbuf *temp1=ccn_charbuf_create();
ccn_uri_append(temp1, temp->buf, temp->length, 0);
char *orig_router=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
sizeof(char));
memcpy(orig_router,ccn_charbuf_as_string(temp1),
strlen(ccn_charbuf_as_string(temp1)));
orig_router[strlen(orig_router)]='\0';
ccn_charbuf_destroy(&temp);
ccn_charbuf_destroy(&temp1);
ccn_indexbuf_destroy(&comps);
return orig_router;
}
开发者ID:akaash-nigam,项目名称:NLSR0.0,代码行数:55,代码来源:nlsr_km.c
示例13: verify_signed_interest
/**
* Verify a signed interest
*
* params are as returned in upcall info structure
* key is what should be used to verify
*
* returns:
* -1 for parsing error
* 0 for incorrect signature / unverified
* 1 for proper verification
*
*/
int verify_signed_interest(const unsigned char *ccnb, const struct ccn_indexbuf *comps,
size_t num_comps, size_t start, size_t stop,
struct ccn_pkey* key) {
fprintf(stderr,"verifying signed interest...\n");
// What is info->interest_comps->n ?
//fprintf(stderr, "Interest components %d\n", (int) info->interest_comps->n);
unsigned char* comp;
size_t size;
int res;
// Create a charbuf with the matched interest name incl nonce
struct ccn_charbuf* name = ccn_charbuf_create();
ccn_name_init(name);
res = ccn_name_append_components(name, ccnb, start, stop);
// Last component, should be the signature
res = ccn_name_comp_get(ccnb, comps,
num_comps,
(const unsigned char**)&comp, &size);
if (memcmp(NS_SIGNATURE, comp, NS_SIGNATURE_LEN) != 0) {
fprintf(stderr, "debug: Last component not tagged as a signature.\n");
return(-1);
}
// Parse our nameless, dataless content object that follows the namespace
// and replace the name with the implicit name from the interest, so that
// we can use the standard signature verification calls. Could be made
// more efficient with different library calls.
struct ccn_charbuf* co_with_name = ccn_charbuf_create();
unsigned char* co = &comp[NS_SIGNATURE_LEN];
replace_name(co_with_name, co, size-NS_SIGNATURE_LEN, name);
//fprintf(stderr, "replace_name == %d (%s)\n", res, (res==0)?"ok":"fail");
// For now, use standard routines to verify signature
struct ccn_parsed_ContentObject pco = {0};
fprintf(stderr,"verifying signed interest...2\n");
res = ccn_parse_ContentObject(co_with_name->buf, co_with_name->length, &pco, NULL);
if (!res) {
// Verify the signature against the authorized public key given to us, passed through to the handler
res = ccn_verify_signature(co_with_name->buf, pco.offset[CCN_PCO_E], &pco, key );
} else {
fprintf(stderr, "debug: Constructed content object parse failed (res==%d)\n", res);
}
fprintf(stderr,"verifying signed interest...3\n");
ccn_charbuf_destroy(&co_with_name);
ccn_charbuf_destroy(&name);
return (res);
}
开发者ID:named-data,项目名称:ndn-lighting,代码行数:66,代码来源:ccn_signed_interest.c
示例14: fprintf
void NdnMediaProcess::initPipe(struct ccn_closure *selfp, struct ccn_upcall_info *info, UserDataBuf *userBuf) {
fprintf(stderr, "initializing pipe\n");
// get seq
const unsigned char *ccnb = info->content_ccnb;
size_t ccnb_size = info->pco->offset[CCN_PCO_E];
struct ccn_indexbuf *comps = info->content_comps;
long seq;
const unsigned char *seqptr = NULL;
char *endptr = NULL;
size_t seq_size = 0;
int k = comps->n - 2;
if (userBuf->seq < 0) {
seq = ccn_ref_tagged_BLOB(CCN_DTAG_Component, ccnb,
comps->buf[k], comps->buf[k + 1],
&seqptr, &seq_size);
if (seq >= 0) {
seq = strtol((const char *)seqptr, &endptr, 10);
if (endptr != ((const char *)seqptr) + seq_size)
seq = -1;
}
if (seq >= 0) {
userBuf->seq = seq;
}
else {
return;
}
}
fprintf(stderr, "fetched content with seq %d\n", seq);
// send hint-ahead interests
for (int i = 0; i < hint_ahead; i ++) {
userBuf->seq++;
struct ccn_charbuf *pathbuf = ccn_charbuf_create();
ccn_name_init(pathbuf);
ccn_name_append_components(pathbuf, ccnb, comps->buf[0], comps->buf[k]);
struct ccn_charbuf *temp = ccn_charbuf_create();
ccn_charbuf_putf(temp, "%ld", userBuf->seq);
ccn_name_append(pathbuf, temp->buf, temp->length);
// no need to trylock as we already have the lock
// this should use pipe callback, selfp is normal callback
int res = ccn_express_interest(info->h, pathbuf, userBuf->data_buf.pipe_callback, NULL);
if (res < 0) {
fprintf(stderr, "Sending interest failed at normal processor\n");
std::exit(1);
}
ccn_charbuf_destroy(&pathbuf);
ccn_charbuf_destroy(&temp);
}
}
开发者ID:FreshLeaf8865,项目名称:mumble,代码行数:52,代码来源:media_pro.cpp
示例15: ccnr_internal_client_stop
void
ccnr_internal_client_stop(struct ccnr_handle *ccnr)
{
ccnr->notice = NULL; /* ccn_destroy will free */
if (ccnr->notice_push != NULL)
ccn_schedule_cancel(ccnr->sched, ccnr->notice_push);
ccn_indexbuf_destroy(&ccnr->chface);
ccn_destroy(&ccnr->internal_client);
ccn_charbuf_destroy(&ccnr->service_ccnb);
ccn_charbuf_destroy(&ccnr->neighbor_ccnb);
if (ccnr->internal_client_refresh != NULL)
ccn_schedule_cancel(ccnr->sched, ccnr->internal_client_refresh);
}
开发者ID:GabrielLiz,项目名称:ccnx,代码行数:13,代码来源:ccnr_internal_client.c
示例16: ccndc_destroy_data
void
ccndc_destroy_data(struct ccndc_data **data) {
struct ccndc_data *self = *data;
if (self != NULL) {
ccn_charbuf_destroy(&self->no_name);
ccn_charbuf_destroy(&self->local_scope_template);
ccn_disconnect(self->ccn_handle);
ccn_destroy(&self->ccn_handle);
free(self);
*data = NULL;
}
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:13,代码来源:ccndc.c
示例17: ccn_charbuf_create
int NdnMediaProcess::checkInterest()
{
int res = 0;
QHash<QString,UserDataBuf *>::iterator it;
ruMutex->lock();
for ( it = qhRemoteUser.begin(); it != qhRemoteUser.end(); ++it ) {
if (!it.value()->interested) {
/* Use a template to express our order preference for the first packet. */
struct ccn_charbuf *templ = ccn_charbuf_create();
struct ccn_charbuf *path = ccn_charbuf_create();
ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
ccn_charbuf_append_closer(templ);
ccn_charbuf_append_tt(templ, CCN_DTAG_ChildSelector, CCN_DTAG);
ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
ccn_charbuf_append(templ, "1", 1); /* low bit 1: rightmost */
ccn_charbuf_append_closer(templ); /*<ChildSelector>*/
ccn_charbuf_append_closer(templ);
ccn_name_from_uri(path, it.key().toLocal8Bit().constData());
ccn_name_append_str(path, "audio");
if (res >= 0) {
if (it.value()->data_buf.callback->p == NULL) {fprintf(stderr, "data_buf.callback is NULL!\n"); exit(1); }
/*
int c = 0;
while (pthread_mutex_trylock(&ccn_mutex) != 0) {
c++;
if (c > 10000000) {
fprintf(stderr, "cannot obtain lock! %s:%d\n", __FILE__, __LINE__);
std::exit(1);
}
}
*/
pthread_mutex_lock(&ccn_mutex);
res = ccn_express_interest(ndnState.ccn, path, it.value()->data_buf.callback, templ);
pthread_mutex_unlock(&ccn_mutex);
it.value()->interested = 1;
fprintf(stderr, "short interest sent\n");
}
if (res < 0) {
fprintf(stderr, "sending the first interest failed\n");
exit(1);
}
ccn_charbuf_destroy(&path);
ccn_charbuf_destroy(&templ);
}
}
ruMutex->unlock();
return res;
}
开发者ID:FreshLeaf8865,项目名称:mumble,代码行数:49,代码来源:media_pro.cpp
示例18: r_io_record_fd
/**
* Make a new fdholder corresponding to the fd
*/
PUBLIC struct fdholder *
r_io_record_fd(struct ccnr_handle *h, int fd,
void *who, socklen_t wholen,
int setflags)
{
int res;
struct fdholder *fdholder = NULL;
res = fcntl(fd, F_SETFL, O_NONBLOCK);
if (res == -1)
ccnr_msg(h, "fcntl: %s", strerror(errno));
fdholder = calloc(1, sizeof(*fdholder));
if (fdholder == NULL)
return(fdholder);
fdholder->name = ccn_charbuf_create();
if (fdholder->name == NULL)
abort();
if (who != NULL)
ccn_charbuf_append(fdholder->name, who, wholen);
fdholder->filedesc = fd;
init_face_flags(h, fdholder, setflags);
res = r_io_enroll_face(h, fdholder);
if (res == -1) {
ccn_charbuf_destroy(&fdholder->name);
free(fdholder);
fdholder = NULL;
}
return(fdholder);
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:34,代码来源:ccnr_io.c
示例19: slice_parse
/*
* utility, may need to be exported, to parse the buffer into a given slice
* structure.
*/
static int
slice_parse(struct ccns_slice *s, const unsigned char *p, size_t size) {
int res = 0;
struct ccn_buf_decoder decoder;
struct ccn_buf_decoder *d = ccn_buf_decoder_start(&decoder, p, size);
uintmax_t version;
int op;
int start;
struct ccn_charbuf *clause = NULL;
if (!ccn_buf_match_dtag(d, CCN_DTAG_SyncConfigSlice))
return (-1);
ccn_buf_advance(d);
if (!ccn_buf_match_dtag(d, CCN_DTAG_SyncVersion))
return (-1);
ccn_buf_advance(d);
ccn_parse_uintmax(d, &version);
ccn_buf_check_close(d);
if (version != SLICE_VERSION)
return (-1);
start = d->decoder.token_index;
if (ccn_parse_Name(d, NULL) < 0)
return(-1);
ccn_charbuf_reset(s->topo);
res = ccn_charbuf_append(s->topo, p + start, d->decoder.token_index - start);
if (res < 0)
return(-1);
start = d->decoder.token_index;
if (ccn_parse_Name(d, NULL) < 0)
return(-1);
ccn_charbuf_reset(s->prefix);
res = ccn_charbuf_append(s->prefix, p + start, d->decoder.token_index - start);
if (res < 0)
return(-1);
if (!ccn_buf_match_dtag(d, CCN_DTAG_SyncConfigSliceList))
return(-1);
ccn_buf_advance(d);
clause = ccn_charbuf_create();
if (clause == NULL)
return(-1);
while (ccn_buf_match_dtag(d, CCN_DTAG_SyncConfigSliceOp)) {
ccn_buf_advance(d);
op = ccn_parse_nonNegativeInteger(d); // op is a small integer
ccn_buf_check_close(d);
if (op != 0)
break;
ccn_charbuf_reset(clause);
start = d->decoder.token_index;
if (ccn_parse_Name(d, NULL) < 0)
break;
res = ccn_charbuf_append(clause, p + start, d->decoder.token_index - start);
ccns_slice_add_clause(s, clause);
}
ccn_charbuf_destroy(&clause);
ccn_buf_check_close(d); /* </SyncConfigSliceList> */
ccn_buf_check_close(d); /* </SyncConfigSlice> */
if (d->decoder.index != size || !CCN_FINAL_DSTATE(d->decoder.state))
return(-1);
return(0);
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:64,代码来源:sync_api.c
示例20: main
int main(void)
{
int res;
struct ccn_charbuf *name = NULL;
struct ccn_indexbuf *comps = NULL;
const unsigned char *comp0 = NULL;
size_t comp0size;
gen_test(&name, &comps);
res = ccn_name_comp_get(name->buf, comps, 0, &comp0, &comp0size);
if (res < 0) {
printf("Unable to get comp\n");
return(-__LINE__);
}
intmax_t rec_secs = 0;
int rec_nsecs = 0;
reclaim_ts(comp0, comp0size, &rec_secs, &rec_nsecs);
// printf("seconds = %lu %s\n", rec_secs, (secs == rec_secs)?("YES"):("NO"));
// printf("nano seconds = %d %s\n", rec_nsecs, (nsecs == rec_nsecs)?("YES"):("NO"));
ccn_charbuf_destroy(&name);
ccn_indexbuf_destroy(&comps);
return(0);
}
开发者ID:chris-wood,项目名称:ANDANAv2,代码行数:30,代码来源:reclaim.c
注:本文中的ccn_charbuf_destroy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论