/** * Shutdown all open fds. */ PUBLIC void r_io_shutdown_all(struct ccnr_handle *h) { int i; for (i = 1; i < h->face_limit; i++) { if (r_io_fdholder_from_fd(h, i) != NULL) r_io_shutdown_client_fd(h, i); } ccnr_internal_client_stop(h); r_io_shutdown_client_fd(h, 0); }
/** * Destroys the fdholder identified by filedesc. * @returns 0 for success, -1 for failure. */ PUBLIC int r_io_destroy_face(struct ccnr_handle *h, unsigned filedesc) { r_io_shutdown_client_fd(h, filedesc); return(0); }
int r_init_map_and_process_file(struct ndnr_handle *h, struct ndn_charbuf *filename, int add_content) { int res = 0; int dres; struct stat statbuf; unsigned char *mapped_file = MAP_FAILED; unsigned char *msg; size_t size; int fd = -1; struct content_entry *content; struct ndn_skeleton_decoder *d; struct fdholder *fdholder; fd = r_io_open_repo_data_file(h, ndn_charbuf_as_string(filename), 0); if (fd == -1) // Normal exit return(1); res = fstat(fd, &statbuf); if (res != 0) { ndnr_msg(h, "stat failed for %s (fd=%d), %s (errno=%d)", ndn_charbuf_as_string(filename), fd, strerror(errno), errno); res = -errno; goto Bail; } if (statbuf.st_size == 0) goto Bail; mapped_file = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); if (mapped_file == MAP_FAILED) { ndnr_msg(h, "mmap failed for %s (fd=%d), %s (errno=%d)", ndn_charbuf_as_string(filename), fd, strerror(errno), errno); res = -errno; goto Bail; } fdholder = r_io_fdholder_from_fd(h, fd); d = &fdholder->decoder; msg = mapped_file; size = statbuf.st_size; while (d->index < size) { dres = ndn_skeleton_decode(d, msg + d->index, size - d->index); if (!NDN_FINAL_DSTATE(d->state)) break; if (add_content) { content = process_incoming_content(h, fdholder, msg + d->index - dres, dres, NULL); if (content != NULL) r_store_commit_content(h, content); } } if (d->index != size || !NDN_FINAL_DSTATE(d->state)) { ndnr_msg(h, "protocol error on fdholder %u (state %d), discarding %d bytes", fdholder->filedesc, d->state, (int)(size - d->index)); res = -1; goto Bail; } Bail: if (mapped_file != MAP_FAILED) munmap(mapped_file, statbuf.st_size); r_io_shutdown_client_fd(h, fd); return (res); }