这篇教程C++ warnp函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中warnp函数的典型用法代码示例。如果您正苦于以下问题:C++ warnp函数的具体用法?C++ warnp怎么用?C++ warnp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了warnp函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: multitape_metadata_recrypt/** * multitape_metadata_recrypt(obuf, obuflen, nbuf, nbuflen): * Decrypt and re-encrypt the provided metadata file. */intmultitape_metadata_recrypt(uint8_t * obuf, size_t obuflen, uint8_t ** nbuf, size_t * nbuflen){ struct tapemetadata mdat; /* Parse the metadata file. */ switch (multitape_metadata_dec(&mdat, obuf, obuflen)) { case 1: warn0("Metadata file is corrupt"); goto err0; case -1: warnp("Error parsing metadata file"); goto err0; } /* Construct a new metadata file. */ if (multitape_metadata_enc(&mdat, nbuf, nbuflen)) { warnp("Error constructing metadata file"); goto err1; } /* Free the metadata we parsed. */ multitape_metadata_free(&mdat); /* Success! */ return (0);err1: multitape_metadata_free(&mdat);err0: /* Failure! */ return (-1);}
开发者ID:zeha,项目名称:tarsnap-deb,代码行数:38,
示例2: bulkupdatestatic intbulkupdate(struct wire_requestqueue * Q, FILE * f){ struct bulkupdate_state C; struct timeval tv_now; uint8_t buf[40]; /* dummy */ /* Initialize. */ C.Q = Q; C.f = f; C.Nip = 0; C.generation = 0; C.failed = 0; C.done = 0; C.N = 0; /* Allocate key and value structures. */ if ((C.key = kvldskey_create(buf, 40)) == NULL) goto err0; if ((C.val = kvldskey_create(buf, 40)) == NULL) goto err1; /* Get current time and store T+60s and T+50s. */ if (monoclock_get(&tv_now)) { warnp("Error reading clock"); goto err2; } C.tv_60.tv_sec = tv_now.tv_sec + 60; C.tv_60.tv_usec = tv_now.tv_usec; C.tv_50.tv_sec = tv_now.tv_sec + 50; C.tv_50.tv_usec = tv_now.tv_usec; /* Send an initial batch of 4096 requests. */ if (sendbatch(&C)) goto err2; /* Wait until we've finished. */ if (events_spin(&C.done) || C.failed) { warnp("SET request failed"); goto err2; } /* Print number of updates performed in a single second. */ printf("%" PRIu64 "/n", C.N / 10); /* Free the key and value structures. */ kvldskey_free(C.val); kvldskey_free(C.key); /* Success! */ return (0);err2: kvldskey_free(C.val);err1: kvldskey_free(C.key);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:60,
示例3: callback_donestatic intcallback_done(void * cookie, int failed){ struct bulkinsert_state * C = cookie; struct timeval tv; /* This request is no longer in progress. */ C->Nip -= 1; /* This request is done. */ C->Ndone += 1; /* Did we fail? */ if (failed) { C->done = 1; C->failed = 1; } /* Store new power-of-two timestamp? */ if ((C->Ndone & (C->Ndone - 1)) == 0) { /* If we have a saved timestamp, print results. */ if (C->Ndone_saved) printperf(C); /* Store new timestamp. */ C->Ndone_saved = C->Ndone; if (monoclock_get(&C->tv_saved)) { warnp("Error reading clock"); goto err0; } } /* Has it been 1s since the stored timestamp? */ if (C->Ndone_saved) { if (monoclock_get(&tv)) { warnp("Error reading clock"); goto err0; } if ((tv.tv_sec >= C->tv_saved.tv_sec + 10) && ((tv.tv_sec > C->tv_saved.tv_sec + 10) || (tv.tv_usec > C->tv_saved.tv_usec))) printperf(C); } /* Send more requests if possible. */ if (sendbatch(C)) goto err0; /* Are we done? */ if (C->Nip == 0) C->done = 1; /* Success! */ return (0);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:59,
示例4: proto_crypt_secret/** * proto_crypt_secret(filename): * Read the key file ${filename} and return a protocol secret structure. */struct proto_secret *proto_crypt_secret(const char * filename){ SHA256_CTX ctx; FILE * f; struct proto_secret * K; uint8_t buf[BUFSIZ]; size_t lenread; /* Allocate a protocol secret structure. */ if ((K = malloc(sizeof(struct proto_secret))) == NULL) goto err0; /* Open the file, or use stdin if requested. */ if (strcmp(filename, STDIN_FILENAME) == 0) { f = stdin; } else if ((f = fopen(filename, "r")) == NULL) { warnp("Cannot open file: %s", filename); goto err1; } /* Initialize the SHA256 hash context. */ SHA256_Init(&ctx); /* Read the file until we hit EOF. */ while ((lenread = fread(buf, 1, BUFSIZ, f)) > 0) SHA256_Update(&ctx, buf, lenread); /* Did we hit EOF? */ if (!feof(f)) { if (f == stdin) { warnp("Error reading from stdin"); } else { warnp("Error reading file: %s", filename); } goto err2; } /* Close the file if it isn't stdin. */ if (f != stdin) fclose(f); /* Compute the final hash. */ SHA256_Final(K->K, &ctx); /* Success! */ return (K);err2: if (f != stdin) fclose(f);err1: free(K);err0: /* Failure! */ return (NULL);}
开发者ID:c0decafe,项目名称:spiped,代码行数:62,
示例5: callback_accept/* A connection has arrived. */static intcallback_accept(void * cookie, int s){ struct dispatch_state * D = cookie; /* We have a socket. */ if ((D->sconn = s) == -1) { warnp("Error accepting connection"); goto err0; } /* Make the accepted connection non-blocking. */ if (fcntl(D->sconn, F_SETFL, O_NONBLOCK) == -1) { warnp("Cannot make connection non-blocking"); goto err1; } /* Create a buffered writer for the connection. */ if ((D->writeq = netbuf_write_init(D->sconn, dropconnection, D)) == NULL) { warnp("Cannot create packet write queue"); goto err1; } /* Create a buffered reader for the connection. */ if ((D->readq = netbuf_read_init(D->sconn)) == NULL) { warnp("Cannot create packet read queue"); goto err2; } /* Wait for a request to arrive. */ if ((D->read_cookie = wire_readpacket_wait(D->readq, gotrequest, D)) == NULL) { warnp("Error reading request from connection"); goto err3; } /* We are no longer waiting for a connection. */ D->accepting = 0; /* No requests are pending yet. */ D->npending = 0; D->appendip = 0; /* Success! */ return (0);err3: netbuf_read_free(D->readq);err2: netbuf_write_free(D->writeq);err1: close(D->sconn);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:58,
示例6: mainintmain(int argc, char * argv[]){ struct sock_addr ** sas; uintmax_t N; int s; struct wire_requestqueue * Q; WARNP_INIT; /* Check number of arguments. */ if (argc != 3) { fprintf(stderr, "usage: hotspot_read %s N/n", "<socketname>"); exit(1); } /* Parse N. */ if ((N = strtoumax(argv[2], NULL, 0)) == 0) { warnp("Invalid value for N: %s", argv[2]); exit(1); } /* Resolve the socket address and connect. */ if ((sas = sock_resolve(argv[1])) == NULL) { warnp("Error resolving socket address: %s", argv[1]); exit(1); } if (sas[0] == NULL) { warn0("No addresses found for %s", argv[1]); exit(1); } if ((s = sock_connect(sas)) == -1) exit(1); /* Create a request queue. */ if ((Q = wire_requestqueue_init(s)) == NULL) { warnp("Cannot create packet write queue"); exit(1); } /* Start issuing hotspot read requests. */ if (hotspotread(Q, N)) exit(1); /* Free the request queue. */ wire_requestqueue_destroy(Q); wire_requestqueue_free(Q); /* Free socket addresses. */ sock_addr_freelist(sas); /* Shut down the event subsystem. */ events_shutdown(); /* Success! */ exit(0);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:57,
示例7: entropy_read/** * entropy_read(buf, buflen): * Fill the given buffer with random bytes provided by the operating system. */intentropy_read(uint8_t * buf, size_t buflen){ int fd; ssize_t lenread; /* Sanity-check the buffer size. */ if (buflen > SSIZE_MAX) { warn0("Programmer error: " "Trying to read insane amount of random data: %zu", buflen); goto err0; } /* Open /dev/urandom. */ if ((fd = open("/dev/urandom", O_RDONLY)) == -1) { warnp("open(/dev/urandom)"); goto err0; } /* Read bytes until we have filled the buffer. */ while (buflen > 0) { if ((lenread = read(fd, buf, buflen)) == -1) { warnp("read(/dev/urandom)"); goto err1; } /* The random device should never EOF. */ if (lenread == 0) { warn0("EOF on /dev/urandom?"); goto err1; } /* We've filled a portion of the buffer. */ buf += (size_t)lenread; buflen -= (size_t)lenread; } /* Close the device. */ while (close(fd) == -1) { if (errno != EINTR) { warnp("close(/dev/urandom)"); goto err0; } } /* Success! */ return (0);err1: close(fd);err0: /* Failure! */ return (-1);}
开发者ID:FauxFaux,项目名称:spiped,代码行数:59,
示例8: tokyostatic inttokyo(struct wire_requestqueue * Q, char ** keys){ struct tokyo_state C; uint8_t buf[8]; /* dummy */ struct timeval tv_start, tv_end; /* Initialize. */ C.Q = Q; C.keys = keys; C.N = 0; C.Nip = 0; C.failed = 0; C.done = 0; /* Allocate key structure. */ if ((C.key = kvldskey_create(buf, 8)) == NULL) return (-1); /* Get start time. */ if (monoclock_get(&tv_start)) { warnp("Error reading clock"); return (-1); } /* Send an initial batch of 4096 requests. */ if (sendbatch(&C)) return (-1); /* Wait until we've finished. */ if (events_spin(&C.done) || C.failed) { warnp("SET request failed"); return (-1); } /* Get start time. */ if (monoclock_get(&tv_end)) { warnp("Error reading clock"); return (-1); } /* Free the key structure. */ kvldskey_free(C.key); /* Print time. */ printf("%.3f/n", (tv_end.tv_sec - tv_start.tv_sec) + (tv_end.tv_usec - tv_start.tv_usec) * 0.000001); /* Success! */ return (0);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:51,
示例9: mainintmain(int argc, char * argv[]){ struct sock_addr ** sas; int s; struct wire_requestqueue * Q; WARNP_INIT; /* Check number of arguments. */ if (argc != 2) { fprintf(stderr, "usage: bulk_insert %s/n", "<socketname>"); exit(1); } /* Resolve the socket address and connect. */ if ((sas = sock_resolve(argv[1])) == NULL) { warnp("Error resolving socket address: %s", argv[1]); exit(1); } if (sas[0] == NULL) { warn0("No addresses found for %s", argv[1]); exit(1); } if ((s = sock_connect(sas)) == -1) exit(1); /* Create a request queue. */ if ((Q = wire_requestqueue_init(s)) == NULL) { warnp("Cannot create packet write queue"); exit(1); } /* Start bulk inserting. */ if (bulkinsert(Q, stdin)) exit(1); /* Free the request queue. */ wire_requestqueue_destroy(Q); wire_requestqueue_free(Q); /* Free socket addresses. */ sock_addr_freelist(sas); /* Shut down the event subsystem. */ events_shutdown(); /* Success! */ exit(0);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:50,
示例10: dispatch_done/** * dispatch_done(D): * Clean up the dispatch state ${D}. The function dispatch_alive(${D}) must * have previously returned zero. */intdispatch_done(struct dispatch_state * D){ /* Sanity check. */ assert(D->accepting == 0); assert(D->read_cookie == NULL); assert(D->npending == 0); /* Free the buffered reader for the connection. */ netbuf_read_free(D->readq); /* Free the buffered writer for the connection. */ netbuf_write_free(D->writeq); /* Close the connection. */ while (close(D->sconn)) { if (errno == EINTR) continue; warnp("close"); goto err0; } /* Free allocated memory. */ free(D); /* Success! */ return (0);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:38,
示例11: store_chunk/** * store_chunk(buf, buflen, ch, C): * Write the chunk ${buf} of length ${buflen} using the chunk layer cookie * ${C}, and populate the chunkheader structure ${ch}. */static intstore_chunk(uint8_t * buf, size_t buflen, struct chunkheader * ch, CHUNKS_W * C){ ssize_t zlen; /* Hash of chunk. */ if (crypto_hash_data(CRYPTO_KEY_HMAC_CHUNK, buf, buflen, ch->hash)) goto err0; /* Length of chunk. */ le32enc(ch->len, (uint32_t)(buflen)); /* Ask chunk layer to store the chunk. */ zlen = chunks_write_chunk(C, ch->hash, buf, buflen); if (zlen == -1) { warnp("Error in chunk storage layer"); goto err0; } /* Compressed length of chunk. */ le32enc(ch->zlen, (uint32_t)(zlen)); /* Success! */ return (0);err0: /* Failure! */ return (-1);}
开发者ID:zg,项目名称:tarsnap,代码行数:35,
示例12: sock_connect_nb/** * sock_connect_nb(sa): * Create a socket, mark it as non-blocking, and attempt to connect to the * address ${sa}. Return the socket (connected or in the process of * connecting) or -1 on error. */intsock_connect_nb(const struct sock_addr * sa){ int s; /* Create a socket. */ if ((s = socket(sa->ai_family, sa->ai_socktype, 0)) == -1) goto err0; /* Mark the socket as non-blocking. */ if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) { warnp("Cannot make socket non-blocking"); goto err1; } /* Attempt to connect. */ if ((connect(s, sa->name, sa->namelen) == -1) && (errno != EINPROGRESS) && (errno == EINTR)) goto err1; /* We have a connect(ed|ing) socket. */ return (s);err1: close(s);err0: /* We failed to connect to this address. */ return (-1);}
开发者ID:brainwater,项目名称:spiped,代码行数:36,
示例13: ccache_free/** * ccache_free(cache): * Free the cache and all of its entries. */voidccache_free(CCACHE * cache){ struct ccache_internal * C = cache; if (cache == NULL) return; /* Free all of the records in the patricia tree. */ patricia_foreach(C->tree, callback_free, NULL); /* Free the patricia tree itself. */ patricia_free(C->tree); /* Unmap memory. */#ifdef HAVE_MMAP if (C->datalen > 0 && munmap(C->data, C->datalen)) warnp("munmap failed on cache data");#else free(C->data);#endif /* Free the cache. */ free(C);}
开发者ID:codarrenvelvindron,项目名称:tarsnap,代码行数:29,
示例14: callback_write/** * callback_write(rec, cookie): * Convert chunkdata record ${rec} into a struct chunkdata_external and * write it to the FILE * ${cookie}; but don't write entries with nrefs == 0. */static intcallback_write(void * rec, void * cookie){ struct chunkdata_external che; struct chunkdata * ch = rec; FILE * f = cookie; /* If nrefs == 0, return without writing anything. */ if (ch->nrefs == 0) return (0); /* Convert to on-disk format. */ memcpy(che.hash, ch->hash, 32); le32enc(che.len, ch->len); le32enc(che.zlen, ch->zlen_flags & CHDATA_ZLEN); le32enc(che.nrefs, ch->nrefs); le32enc(che.ncopies, ch->ncopies); /* Write. */ if (fwrite(&che, sizeof(che), 1, f) != 1) { warnp("Error writing to chunk directory"); return (-1); } /* Success! */ return (0);}
开发者ID:carriercomm,项目名称:tarsnap-1,代码行数:32,
示例15: netproto_close/** * netproto_close(C): * Cancel all pending writes and any in-progress read, and free memory. */intnetproto_close(NETPROTO_CONNECTION * C){ int rc, rc2; /* If we were connecting, cancel that. */ if (C->cancel != NULL) rc = (C->cancel)(C->cookie); else rc = 0; /* Cancel pending writes. */ if (C->Q != NULL) { rc2 = network_writeq_cancel(C->Q); rc = rc ? rc : rc2; } /* Free the write queue. */ if (C->Q != NULL) network_writeq_free(C->Q); /* Cancel any in-progress read. */ if (C->fd != -1) { rc2 = network_deregister(C->fd, NETWORK_OP_READ); rc = rc ? rc : rc2; } /* Free cryptographic keys, if any exist. */ crypto_session_free(C->keys); /* Close the socket. */ while (C->fd != -1 && close(C->fd)) { if (errno == ECONNRESET) { /* * You can't dump me! I'm dumping you! We don't * care about the connection dying since we we're * done with it anyway. */ break; } if (errno != EINTR) { warnp("close()"); goto err1; } } /* Free the network protocol cookie. */ free(C); /* Return success or the first nonzero callback value. */ return (rc);err1: free(C); /* Failure! */ return (-1);}
开发者ID:carriercomm,项目名称:tarsnap-1,代码行数:63,
示例16: sock_listener/** * sock_listener(sa): * Create a socket, set SO_REUSEADDR, bind it to the socket address ${sa}, * mark it for listening, and mark it as non-blocking. */intsock_listener(const struct sock_addr * sa){ int s; int val = 1; /* Create a socket. */ if ((s = socket(sa->ai_family, sa->ai_socktype, 0)) == -1) { warnp("socket(%d, %d)", sa->ai_family, sa->ai_socktype); goto err0; } /* Set SO_REUSEADDR. */ if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))) { warnp("setsockopt(SO_REUSEADDR)"); goto err1; } /* Bind the socket. */ if (bind(s, sa->name, sa->namelen)) { warnp("error binding socket"); goto err1; } /* Mark the socket as listening. */ if (listen(s, 10)) { warnp("error marking socket as listening"); goto err1; } /* Make the socket as non-blocking. */ if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) { warnp("error marking socket as non-blocking"); goto err1; } /* Success! */ return (s);err1: close(s);err0: /* Failure! */ return (-1);}
开发者ID:brainwater,项目名称:spiped,代码行数:50,
示例17: xmalloc_q_static q_vdb_ctx *q_vdb_open(/*const char *sroot, const char *svdb*/void){ q_vdb_ctx *ctx = xmalloc(sizeof(*ctx)); const char *sroot = NULL; const char *svdb = NULL; if (!sroot) sroot = portroot; ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC|O_PATH); if (ctx->portroot_fd == -1) { warnp("could not open root: %s", sroot); goto f_error; } if (!svdb) svdb = portvdb; /* Skip the leading slash */ svdb++; if (*svdb == '/0') svdb = "."; /* Cannot use O_PATH as we want to use fdopendir() */ ctx->vdb_fd = openat(ctx->portroot_fd, svdb, O_RDONLY|O_CLOEXEC); if (ctx->vdb_fd == -1) { warnp("could not open vdb: %s (in root %s)", svdb, sroot); goto cp_error; } ctx->dir = fdopendir(ctx->vdb_fd); if (ctx->dir == NULL) goto cv_error; return ctx; cv_error: close(ctx->vdb_fd); cp_error: close(ctx->portroot_fd); f_error: free(ctx); return NULL;}
开发者ID:den4ix,项目名称:portage-utils,代码行数:41,
示例18: btree_sync/** * btree_sync(T, callback, cookie): * Serialize and write dirty nodes from the B+Tree ${T}; mark said nodes as * clean; free the shadow tree; and invoke the provided callback. */intbtree_sync(struct btree * T, int (* callback)(void *), void * cookie){ struct write_cookie * WC; size_t npages; const uint8_t ** bufv; uint64_t pn = 0; /* Bake a cookie. */ if ((WC = malloc(sizeof(struct write_cookie))) == NULL) goto err0; WC->T = T; WC->callback = callback; WC->cookie = cookie; /* Figure out how many pages we need to write. */ npages = ndirty(T->root_dirty); /* Allocate a vector to hold pointers to pages. */ if (IMALLOC(bufv, npages, const uint8_t *)) goto err1; /* Serialize pages and record pointers into the vector. */ if (serializetree(T, T->root_dirty, T->pagelen, T->nextblk, bufv, &pn)) goto err2; /* Sanity check the number of pages serialized. */ assert(pn == npages); /* Write pages out. */ if (proto_lbs_request_append_blks(T->LBS, npages, T->nextblk, T->pagelen, bufv, callback_append, WC)) { warnp("Error writing pages"); goto err2; } /* Free the page pointers vector. */ free(bufv); /* Success! */ return (0);err2: free(bufv);err1: free(WC);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:56,
示例19: monoclock_get/** * monoclock_get(tv): * Store the current time in ${tv}. If CLOCK_MONOTONIC is available, use * that clock; if CLOCK_MONOTONIC is unavailable, use CLOCK_REALTIME (if * available) or gettimeofday(2). */intmonoclock_get(struct timeval * tv){#if defined(CLOCK_MONOTONIC) || !defined(POSIXFAIL_CLOCK_REALTIME) struct timespec tp;#endif#ifdef CLOCK_MONOTONIC if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) { tv->tv_sec = tp.tv_sec; tv->tv_usec = tp.tv_nsec / 1000; } else if ((errno != ENOSYS) && (errno != EINVAL)) { warnp("clock_gettime(CLOCK_MONOTONIC)"); goto err0; } else#endif#ifndef POSIXFAIL_CLOCK_REALTIME if (clock_gettime(CLOCK_REALTIME, &tp) == 0) { tv->tv_sec = tp.tv_sec; tv->tv_usec = tp.tv_nsec / 1000; } else { warnp("clock_gettime(CLOCK_REALTIME)"); goto err0; }#else if (gettimeofday(tv, NULL)) { warnp("gettimeofday"); goto err0; }#endif /* Success! */ return (0);err0: /* Failure! */ return (-1);}
开发者ID:c0decafe,项目名称:spiped,代码行数:44,
示例20: events_network_select/** * events_network_select(tv): * Check for socket readiness events, waiting up to ${tv} time if there are * no sockets immediately ready, or indefinitely if ${tv} is NULL. The value * stored in ${tv} may be modified. */intevents_network_select(struct timeval * tv){ size_t i; /* Initialize if necessary. */ if (initsocketlist()) goto err0; /* Zero the fd sets... */ FD_ZERO(&readfds); FD_ZERO(&writefds); /* ... and add the ones we care about. */ for (i = 0; i < socketlist_getsize(S); i++) { if (socketlist_get(S, i)->reader) FD_SET(i, &readfds); if (socketlist_get(S, i)->writer) FD_SET(i, &writefds); } /* We're about to call select! */ events_network_selectstats_select(); /* Select. */ while (select(socketlist_getsize(S), &readfds, &writefds, NULL, tv) == -1) { /* EINTR is harmless. */ if (errno == EINTR) continue; /* Anything else is an error. */ warnp("select()"); goto err0; } /* If we have any events registered, start the clock again. */ if (nev > 0) events_network_selectstats_startclock(); /* We should start scanning for events at the beginning. */ fdscanpos = 0; /* Success! */ return (0);err0: /* Failure! */ return (-1);}
开发者ID:c0decafe,项目名称:spiped,代码行数:56,
示例21: callback_getstatic intcallback_get(void * cookie, int failed, struct kvldskey * value){ struct hotspotread_state * C = cookie; struct timeval tv; /* This request is no longer in progress. */ C->Nip -= 1; /* Did we fail? */ if (failed) { C->done = 1; C->failed = 1; } /* If we have a value, free it. */ if (failed == 0) kvldskey_free(value); /* Read the current time. */ if (monoclock_get(&tv)) { warnp("Error reading clock"); goto err0; } /* Are we finished? Are we within the 50-60 second range? */ if ((tv.tv_sec > C->tv_60.tv_sec) || ((tv.tv_sec == C->tv_60.tv_sec) && (tv.tv_usec > C->tv_60.tv_usec))) { C->done = 1; } else if ((tv.tv_sec > C->tv_50.tv_sec) || ((tv.tv_sec == C->tv_50.tv_sec) && (tv.tv_usec > C->tv_50.tv_usec))) { C->N += 1; } /* Send more requests if possible. */ if (sendbatch(C)) goto err0; /* Success! */ return (0);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:47,
示例22: print_idstatic voidprint_id(const char *keyfilename){ uint64_t machinenum = (uint64_t)(-1); /* Read keyfile and machine name. */ if (keyfile_read(keyfilename, &machinenum, ~0)) { warnp("Cannot read key file: %s", keyfilename); exit(1); } /* Print key ID. */ fprintf(stdout, "%" PRIu64 "/n", machinenum); exit(0); /* NOTREACHED */}
开发者ID:carriercomm,项目名称:tarsnap,代码行数:17,
示例23: bulkinsertstatic intbulkinsert(struct wire_requestqueue * Q, FILE * f){ struct bulkinsert_state C; uint8_t buf[40]; /* dummy */ /* Initialize. */ C.Q = Q; C.f = f; C.Nip = 0; C.failed = 0; C.done = 0; C.Ndone = 0; C.Ndone_saved = 0; /* Allocate key and value structures. */ if ((C.key = kvldskey_create(buf, 40)) == NULL) goto err0; if ((C.val = kvldskey_create(buf, 40)) == NULL) goto err1; /* Send an initial batch of 4096 requests. */ if (sendbatch(&C)) goto err2; /* Wait until we've finished. */ if (events_spin(&C.done) || C.failed) { warnp("SET request failed"); goto err2; } /* Free the key and value structures. */ kvldskey_free(C.val); kvldskey_free(C.key); /* Success! */ return (0);err2: kvldskey_free(C.val);err1: kvldskey_free(C.key);err0: /* Failure! */ return (-1);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:46,
示例24: humansize/** * humansize(size): * Given a size in bytes, allocate and return a string of the form "<N> B" * for 0 <= N <= 999 or "<X> <prefix>B" where either 10 <= X <= 999 or * 1.0 <= X <= 9.9 and <prefix> is "k", "M", "G", "T", "P", or "E"; and where * the value returned is the largest valid value <= the provided size. */char *humansize(uint64_t size){ char * s; char prefix; int shiftcnt; int rc; /* Special-case for size < 1000. */ if (size < 1000) { rc = asprintf(&s, "%d B", (int)size); } else { /* Keep 10 * size / 1000^(3n) in size. */ for (size /= 100, shiftcnt = 1; size >= 10000; shiftcnt++) size /= 1000; /* * Figure out what prefix to use. Since 1 EB = 10^18 B and * the maximum value of a uint64_t is 2^64 which is roughly * 18.4 * 10^18, this cannot reference beyond the end of the * string. */ prefix = " kMGTPE"[shiftcnt]; /* Construct the string. */ if (size < 100) rc = asprintf(&s, "%d.%d %cB", (int)size / 10, (int)size % 10, prefix); else rc = asprintf(&s, "%d %cB", (int)size / 10, prefix); } if (rc == -1) { warnp("asprintf"); goto err0; } /* Success! */ return (s);err0: /* Failure! */ return (NULL);}
开发者ID:barak,项目名称:scrypt,代码行数:51,
示例25: storage_util_mkpath/** * storage_util_mkpath(S, fileno): * Return the malloc-allocated NUL-terminated string "${dir}/blks_${fileno}" * where ${dir} is ${S}->storagedir and ${fileno} is a 0-padding hex value. */char *storage_util_mkpath(struct storage_state * S, uint64_t fileno){ char * s; /* Construct path. */ if (asprintf(&s, "%s/blks_%016" PRIx64, S->storagedir, fileno) == -1) { warnp("asprintf"); goto err0; } /* Success! */ return (s);err0: /* Failure! */ return (NULL);}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:24,
示例26: sock_connect/** * sock_connect(sas): * Iterate through the addresses in ${sas}, attempting to create a socket and * connect (blockingly). Once connected, stop iterating, mark the socket as * non-blocking, and return it. */intsock_connect(struct sock_addr * const * sas){ int s = -1; /* Iterate through the addresses provided. */ for (; sas[0] != NULL; sas++) { /* Create a socket. */ if ((s = socket(sas[0]->ai_family, sas[0]->ai_socktype, 0)) == -1) continue; /* Attempt to connect. */ if (connect(s, sas[0]->name, sas[0]->namelen) == 0) break; /* Close the socket; this address didn't work. */ close(s); } /* Did we manage to connect? */ if (sas[0] == NULL) { warn0("Could not connect"); goto err0; } /* Mark the socket as non-blocking. */ if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) { warnp("Cannot make connection non-blocking"); goto err1; } /* Success! */ return (s);err1: close(s);err0: /* Failure! */ return (-1);}
开发者ID:brainwater,项目名称:spiped,代码行数:47,
示例27: printperfstatic voidprintperf(struct bulkinsert_state * C){ struct timeval tv; double T; uint64_t N; /* Get current time. */ if (monoclock_get(&tv)) { warnp("Error reading clock"); return; } /* Compute time difference. */ T = (tv.tv_sec - C->tv_saved.tv_sec) + (tv.tv_usec - C->tv_saved.tv_usec) * 0.000001; /* Compute number of requests between then and now. */ N = C->Ndone - C->Ndone_saved; /* Everything completed before now was before 10 s. */ if (T > 10.0) { T = 10.0; N -= 1; } /* Avoid microsecond precision rounding resulting in divide-by-0. */ if (T < 0.000001) T = 0.000001; /* * Print requests per second. Skip this if we handled less than 4096 * requests, since that could be a burst of responses from a single * bundle. */ if (N >= 4096) printf("%zu %.0f/n", C->Ndone_saved, N / T); /* We've printed this performance point. */ C->Ndone_saved = 0;}
开发者ID:Tarsnap,项目名称:kivaloo,代码行数:41,
示例28: print_permissionsstatic voidprint_permissions(const char *keyfilename){ uint64_t machinenum = (uint64_t)(-1); int has_read; int has_write; int has_delete; /* Read keyfile and machine name. */ if (keyfile_read(keyfilename, &machinenum, ~0)) { warnp("Cannot read key file: %s", keyfilename); exit(1); } /* Determine permissions. */ has_read = (crypto_keys_missing(CRYPTO_KEYMASK_READ) == NULL); has_write = (crypto_keys_missing(CRYPTO_KEYMASK_WRITE) == NULL); has_delete = (crypto_keys_missing(CRYPTO_KEYMASK_AUTH_DELETE) == NULL); /* Print key permissions. */ fprintf(stdout, "This key has permissions for: "); if (has_read && has_write && has_delete) fprintf(stdout, "reading, writing, and deleting./n"); if (has_read && has_write && !has_delete) fprintf(stdout, "reading and writing./n"); if (has_read && !has_write && has_delete) fprintf(stdout, "reading and deleting./n"); if (has_read && !has_write && !has_delete) fprintf(stdout, "reading./n"); if (!has_read && has_write && has_delete) fprintf(stdout, "writing and nuking./n"); if (!has_read && has_write && !has_delete) fprintf(stdout, "writing./n"); if (!has_read && !has_write && has_delete) fprintf(stdout, "nuking./n"); if (!has_read && !has_write && !has_delete) fprintf(stdout, "nothing./n"); exit(0); /* NOTREACHED */}
开发者ID:carriercomm,项目名称:tarsnap,代码行数:41,
示例29: crypto_keys_subr_generate_HMAC/** * crypto_keys_subr_generate_HMAC(key): * Generate an HMAC key. */intcrypto_keys_subr_generate_HMAC(struct crypto_hmac_key ** key){ /* Free any existing key. */ if (*key != NULL) { free((*key)->key); free(*key); } /* Allocate memory. */ if ((*key = malloc(sizeof(struct crypto_hmac_key))) == NULL) goto err0; if (((*key)->key = malloc(32)) == NULL) goto err1; /* Store key length. */ (*key)->len = 32; /* Generate key. */ if (crypto_entropy_read((*key)->key, 32)) { warnp("Could not obtain sufficient entropy"); goto err2; } /* Success! */ return (0);err2: free((*key)->key);err1: free(*key);err0: /* Failure! */ return (-1);}
开发者ID:codarrenvelvindron,项目名称:tarsnap,代码行数:40,
示例30: debug_tlv/* Prints out some information about TLV */void debug_tlv(struct tlv * t){ warnp("TLV type %.4X, Length %d, Message ID %.8X/n", ntohs(t->type), ntohs(t->length), ntohs(t->messageid));}
开发者ID:ryo,项目名称:netbsd-src,代码行数:7,
注:本文中的warnp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ warnx函数代码示例 C++ warningf函数代码示例 |