response to M_GET only with already opened (and so sent) file

master
Sergey Dorofeev 13 years ago
parent 185cff17a5
commit e3a691481e

@ -921,7 +921,7 @@ case BPMSG_GET: /* Get a file from offset */
if (bstate->extracmd[0] != -1) return 0; 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"); log("M_GET for currently transmitted file");
if (getfi.offs==bstate->pi->send->bytes_sent) { if (getfi.offs==bstate->pi->send->bytes_sent) {
log("M_GET offset match current (seems NR mode)"); 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"); log("ignore differing M_GET for netspool");
return 1; 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 ) { if( p_tx_rewind(bstate->pi, getfi.offs) != 0 ) {
log("failed to rewind"); log("failed to rewind");
p_tx_fclose(bstate->pi); p_tx_fclose(bstate->pi);
return -1; 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_skipped = getfi.offs;
bstate->pi->send->bytes_sent = getfi.offs; bstate->pi->send->bytes_sent = getfi.offs;
bstate->extracmd[0] = BPMSG_FILE; bstate->extracmd[0] = BPMSG_FILE;
@ -967,7 +967,7 @@ case BPMSG_GET: /* Get a file from offset */
s_filehint hint; s_filehint hint;
hint.fn = getfi.fn; hint.fn = getfi.fn;
hint.sz = getfi.sz; hint.sz = getfi.sz;
hint.tm = getfi.tm;; hint.tm = getfi.tm;
if( p_tx_fopen(bstate->pi, &hint) != 0 ) { if( p_tx_fopen(bstate->pi, &hint) != 0 ) {
log("could not satisfy M_GET"); log("could not satisfy M_GET");
return -1; return -1;

@ -43,7 +43,7 @@ const char *Protocols[] =
static int prot_get_next_file(s_filelist **dest, s_protinfo *pi, s_filehint *hint) 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 *ptrl = NULL;
s_filelist *best = NULL; s_filelist *best = NULL;
s_fsqueue *q = &state.queue; 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 *host = conf_string(cf_netspool_host);
char *port = conf_string(cf_netspool_port); char *port = conf_string(cf_netspool_port);
if(host==NULL) { if(host==NULL) {
log("netspool is not configured"); //log("netspool is not configured");
state.netspool.state = NS_UNCONF; state.netspool.state = NS_UNCONF;
} else { } else {
snprintf(address, 299, state.node.addr.point? "%d:%d/%d.%d": "%d:%d/%d", 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) { if(state.netspool.state == NS_RECEIVING) {
log("netspool begin receive"); //log("netspool begin receive");
netspool_receive(&state.netspool); netspool_receive(&state.netspool);
} else { } else {
log("netspool could not start receive"); //log("netspool could not start receive");
return 1; 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) { if(state.netspool.state == NS_READY) {
log("netspool queue empty"); //log("netspool queue empty");
netspool_end(&state.netspool); netspool_end(&state.netspool);
} }
if(state.netspool.state==NS_ERROR) { if(state.netspool.state==NS_ERROR) {
log("no next file: netspool error %s", state.netspool.error); log("netspool error %s", state.netspool.error);
} }
#endif #endif
@ -228,6 +228,31 @@ int p_tx_fopen(s_protinfo *pi, s_filehint *hint)
if( state.sopts.holdall ) if( state.sopts.holdall )
return 1; return 1;
if (hint) {
log("trying to reopen file");
int i;
for (i=0; i++; i<pi->n_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: get_next_file:
if( prot_get_next_file(&ptrl, pi, hint) ) { if( prot_get_next_file(&ptrl, pi, hint) ) {
log("no next file"); log("no next file");

Loading…
Cancel
Save