From e3a691481ec1c8b24a350ade835bd0f585b8719b Mon Sep 17 00:00:00 2001 From: Sergey Dorofeev Date: Tue, 21 Feb 2012 22:27:22 +0400 Subject: [PATCH] response to M_GET only with already opened (and so sent) file --- source/bforce/prot_binkp.c | 10 +++++----- source/bforce/prot_common.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/source/bforce/prot_binkp.c b/source/bforce/prot_binkp.c index 6d83be4..5c70332 100644 --- a/source/bforce/prot_binkp.c +++ b/source/bforce/prot_binkp.c @@ -921,7 +921,7 @@ case BPMSG_GET: /* Get a file from offset */ if (bstate->extracmd[0] != -1) return 0; - if (p_compfinfo(bstate->pi->send, getfi.fn, getfi.sz, getfi.tm)==0) { + if (bstate->pi->send) if (p_compfinfo(bstate->pi->send, getfi.fn, getfi.sz, getfi.tm)==0) { log("M_GET for currently transmitted file"); if (getfi.offs==bstate->pi->send->bytes_sent) { log("M_GET offset match current (seems NR mode)"); @@ -937,18 +937,18 @@ case BPMSG_GET: /* Get a file from offset */ } } - if (bstate->pi->send->netspool) { + if (bstate->pi->send) if (bstate->pi->send->netspool) { log("ignore differing M_GET for netspool"); return 1; } - if (bstate->pi->send && p_compfinfo(bstate->pi->send, getfi.fn, getfi.sz, getfi.tm)==0) { + if (bstate->pi->send) if (p_compfinfo(bstate->pi->send, getfi.fn, getfi.sz, getfi.tm)==0) { + log("resending \"%s\" from %ld offset", bstate->pi->send->fname, (long)getfi.offs); if( p_tx_rewind(bstate->pi, getfi.offs) != 0 ) { log("failed to rewind"); p_tx_fclose(bstate->pi); return -1; } - log("sending \"%s\" from %ld offset", bstate->pi->send->fname, (long)getfi.offs); bstate->pi->send->bytes_skipped = getfi.offs; bstate->pi->send->bytes_sent = getfi.offs; bstate->extracmd[0] = BPMSG_FILE; @@ -967,7 +967,7 @@ case BPMSG_GET: /* Get a file from offset */ s_filehint hint; hint.fn = getfi.fn; hint.sz = getfi.sz; - hint.tm = getfi.tm;; + hint.tm = getfi.tm; if( p_tx_fopen(bstate->pi, &hint) != 0 ) { log("could not satisfy M_GET"); return -1; diff --git a/source/bforce/prot_common.c b/source/bforce/prot_common.c index 252a13e..70f1df9 100644 --- a/source/bforce/prot_common.c +++ b/source/bforce/prot_common.c @@ -43,7 +43,7 @@ const char *Protocols[] = static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_filehint *hint) { - log("prot_get_next_file %d", hint); + log("prot_get_next_file"); // %s %d", hint->fn, hint->sz); s_filelist *ptrl = NULL; s_filelist *best = NULL; s_fsqueue *q = &state.queue; @@ -121,7 +121,7 @@ static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_filehint *hin char *host = conf_string(cf_netspool_host); char *port = conf_string(cf_netspool_port); if(host==NULL) { - log("netspool is not configured"); + //log("netspool is not configured"); state.netspool.state = NS_UNCONF; } else { snprintf(address, 299, state.node.addr.point? "%d:%d/%d.%d": "%d:%d/%d", @@ -143,10 +143,10 @@ static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_filehint *hin } if(state.netspool.state == NS_RECEIVING) { - log("netspool begin receive"); + //log("netspool begin receive"); netspool_receive(&state.netspool); } else { - log("netspool could not start receive"); + //log("netspool could not start receive"); return 1; } @@ -157,12 +157,12 @@ static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_filehint *hin } if(state.netspool.state == NS_READY) { - log("netspool queue empty"); + //log("netspool queue empty"); netspool_end(&state.netspool); } if(state.netspool.state==NS_ERROR) { - log("no next file: netspool error %s", state.netspool.error); + log("netspool error %s", state.netspool.error); } #endif @@ -227,6 +227,31 @@ int p_tx_fopen(s_protinfo *pi, s_filehint *hint) if( state.sopts.holdall ) return 1; + + if (hint) { + log("trying to reopen file"); + int i; + for (i=0; i++; in_sentfiles) { + if (strcmp(pi->sentfiles[i].net_name, hint->fn)==0) { + log("name match"); + if (pi->sentfiles[i].bytes_total == hint->sz) { + log("size match"); + if (pi->sentfiles[i].mod_time == hint->tm) { + log("time match"); + if (!pi->sentfiles[i].fp) { + log("already closed"); + return -1; + } + pi->send = pi->sentfiles + i; + pi->send->eofseen = FALSE; + pi->send->status = FSTAT_PROCESS; + log("reopened %s", pi->send->fname); + return 0; + } + } + } + } + } get_next_file: if( prot_get_next_file(&ptrl, pi, hint) ) {