static int add_data_to_store(struct cntr *cntr, struct slist *slist, struct iobuf *rbuf, struct dpth *dpth) { static struct blk *blk=NULL; // Find the first one in the list that was requested. // FIX THIS: Going up the list here, and then later // when writing to the manifest is not efficient. for(blk=slist->blist->head; blk && (!blk->requested || blk->got==BLK_GOT); blk=blk->next) { // logp("try: %d %d\n", blk->index, blk->got); } if(!blk) { logp("Received data but could not find next requested block.\n"); if(!slist->blist->head) logp("and slist->blist->head is null\n"); else logp("head index: %" PRIu64 "\n", slist->blist->head->index); return -1; } // Add it to the data store straight away. if(dpth_protocol2_fwrite(dpth, rbuf, blk)) return -1; cntr_add(cntr, CMD_DATA, 0); cntr_add_recvbytes(cntr, blk->length); blk->got=BLK_GOT; blk=blk->next; return 0; }
static int deal_with_receive_append(struct asfd *asfd, struct sbuf *rb, struct conf **cconfs) { int app=0; static struct iobuf *rbuf; rbuf=asfd->rbuf; //logp("rbuf->len: %d\n", rbuf->len); cntr_add_recvbytes(get_cntr(cconfs[OPT_CNTR]), rbuf->len); if(rb->protocol1->fzp) app=fzp_write(rb->protocol1->fzp, rbuf->buf, rbuf->len); if(app>0) return 0; logp("error when appending: %d\n", app); asfd->write_str(asfd, CMD_ERROR, "write failed"); return -1; }
static int deal_with_receive_append(struct asfd *asfd, struct sbuf *rb, struct conf *cconf) { int app=0; static struct iobuf *rbuf; rbuf=asfd->rbuf; //logp("rbuf->len: %d\n", rbuf->len); cntr_add_recvbytes(cconf->cntr, rbuf->len); if(rb->burp1->zp) app=gzwrite(rb->burp1->zp, rbuf->buf, rbuf->len); else if(rb->burp1->fp) app=fwrite(rbuf->buf, 1, rbuf->len, rb->burp1->fp); if(app>0) return 0; logp("error when appending: %d\n", app); asfd->write_str(asfd, CMD_ERROR, "write failed"); return -1; }