X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ftransfer.c;h=b713f52e571c889190c93db79afe95057fb0d0e9;hb=bd5d862e9745b6fb3c67ccb215c0e6aaa65bacf9;hp=f23a3ed50f6b05c496a1536e7f0439f36d13b746;hpb=1ff9e8ea002024dee061378ae5871619d6b979dd;p=doldaconnect.git diff --git a/daemon/transfer.c b/daemon/transfer.c index f23a3ed..b713f52 100644 --- a/daemon/transfer.c +++ b/daemon/transfer.c @@ -133,7 +133,10 @@ static void localread(struct socket *sk, struct transfer *transfer) if((transfer->datapipe != NULL) && (sockqueueleft(transfer->datapipe) > 0)) { buf = sockgetinbuf(sk, &blen); + if((transfer->endpos >= 0) && (transfer->curpos + blen > transfer->endpos)) + blen = transfer->endpos - transfer->curpos; sockqueue(transfer->datapipe, buf, blen); + free(buf); time(&transfer->activity); transfer->curpos += blen; bytesupload += blen; @@ -148,7 +151,10 @@ static void dataread(struct socket *sk, struct transfer *transfer) if((transfer->localend != NULL) && (sockqueueleft(transfer->localend) > 0)) { buf = sockgetinbuf(sk, &blen); + if((transfer->endpos >= 0) && (transfer->curpos + blen > transfer->endpos)) + blen = transfer->endpos - transfer->curpos; sockqueue(transfer->localend, buf, blen); + free(buf); transfer->curpos += blen; bytesdownload += blen; CBCHAINDOCB(transfer, trans_p, transfer); @@ -177,9 +183,11 @@ static void dataerr(struct socket *sk, int errno, struct transfer *transfer) { if(transfer->curpos >= transfer->size) { transfersetstate(transfer, TRNS_DONE); - closesock(transfer->localend); - quitsock(transfer->localend); - transfer->localend = NULL; + if(transfer->localend != NULL) { + closesock(transfer->localend); + quitsock(transfer->localend); + transfer->localend = NULL; + } } else { resettransfer(transfer); } @@ -317,6 +325,7 @@ void transfersetlocalend(struct transfer *transfer, struct socket *sk) { if(transfer->localend != NULL) putsock(transfer->localend); + socksetdebug(sk, 2, "localend"); getsock(transfer->localend = sk); sk->data = transfer; sk->readcb = (void (*)(struct socket *, void *))localread;