X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ftransfer.c;h=177353cae655a1881ccddede583e96b7c76fc3c5;hb=f63305cce846ed60e079397fa9fc06a35d5ce365;hp=9c50ed102342e0b7c91739f5b4c4b5b8294f9c10;hpb=1ce5968e27a19937a0e54f118d91e1a22438a0eb;p=doldaconnect.git diff --git a/daemon/transfer.c b/daemon/transfer.c index 9c50ed1..177353c 100644 --- a/daemon/transfer.c +++ b/daemon/transfer.c @@ -133,7 +133,14 @@ 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; + CBCHAINDOCB(transfer, trans_p, transfer); } } @@ -144,7 +151,13 @@ 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); } } @@ -168,8 +181,20 @@ static void localerr(struct socket *sk, int errno, struct transfer *transfer) static void dataerr(struct socket *sk, int errno, struct transfer *transfer) { - if(transfer->localend != NULL) - closesock(transfer->localend); + if(transfer->dir == TRNSD_DOWN) { + if(transfer->curpos >= transfer->size) { + transfersetstate(transfer, TRNS_DONE); + if(transfer->localend != NULL) { + closesock(transfer->localend); + quitsock(transfer->localend); + transfer->localend = NULL; + } + } else { + resettransfer(transfer); + } + } else if(transfer->dir == TRNSD_UP) { + transfer->close = 1; + } } void transferattach(struct transfer *transfer, struct socket *dpipe) @@ -185,11 +210,8 @@ void transferattach(struct transfer *transfer, struct socket *dpipe) void transferdetach(struct transfer *transfer) { if(transfer->datapipe != NULL) { - transfer->datapipe->readcb = NULL; - transfer->datapipe->writecb = NULL; - transfer->datapipe->errcb = NULL; closesock(transfer->datapipe); - putsock(transfer->datapipe); + quitsock(transfer->datapipe); } transfer->datapipe = NULL; } @@ -281,59 +303,6 @@ static void transexpire(int cancelled, struct transfer *transfer) transfer->timeout = 0; } -static void transferputdata(struct transfer *transfer, void *buf, size_t size) -{ - time(&transfer->activity); - sockqueue(transfer->localend, buf, size); - transfer->curpos += size; - bytesdownload += size; - CBCHAINDOCB(transfer, trans_p, transfer); -} - -static void transferendofdata(struct transfer *transfer) -{ - if(transfer->curpos >= transfer->size) - { - transfersetstate(transfer, TRNS_DONE); - transfer->localend->readcb = NULL; - transfer->localend->writecb = NULL; - transfer->localend->errcb = NULL; - putsock(transfer->localend); - transfer->localend = NULL; - } else { - resettransfer(transfer); - } -} - -static ssize_t transferdatasize(struct transfer *transfer) -{ - return(sockqueueleft(transfer->localend)); -} - -static void *transfergetdata(struct transfer *transfer, size_t *size) -{ - void *buf; - - if(transfer->localend == NULL) - return(NULL); - time(&transfer->activity); - if((buf = sockgetinbuf(transfer->localend, size)) == NULL) - return(NULL); - if((transfer->endpos >= 0) && (transfer->curpos + *size >= transfer->endpos)) - { - if((*size = transfer->endpos - transfer->curpos) == 0) { - free(buf); - buf = NULL; - } else { - buf = srealloc(buf, *size); - } - } - transfer->curpos += *size; - bytesupload += *size; - CBCHAINDOCB(transfer, trans_p, transfer); - return(buf); -} - void transferprepul(struct transfer *transfer, off_t size, off_t start, off_t end, struct socket *lesk) { transfersetsize(transfer, size);