From: Fredrik Tolf Date: Sat, 18 Oct 2008 12:33:02 +0000 (+0200) Subject: A number of transfer-related bugfixes. X-Git-Tag: 1.3~5 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=c3d01fa95daeee35607cdf7ddc8e688c4a49ea50;p=doldaconnect.git A number of transfer-related bugfixes. --- diff --git a/daemon/fnet-dc.c b/daemon/fnet-dc.c index f8b7606..afd13b3 100644 --- a/daemon/fnet-dc.c +++ b/daemon/fnet-dc.c @@ -161,6 +161,7 @@ static void updatexmllist(void); static void updatexmlbz2list(void); static void requestfile(struct dcpeer *peer); static void updatelists(int now); +static int trdestroycb(struct transfer *transfer, struct dcpeer *peer); static int reservedchar(unsigned char c) { @@ -1585,6 +1586,13 @@ static void cmd_mynick(struct socket *sk, struct dcpeer *peer, char *cmd, char * } } +static void peerattach(struct dcpeer *peer, struct transfer *transfer) +{ + peer->transfer = transfer; + CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer); + CBREG(peer->transfer, trans_destroy, (int (*)(struct transfer *, void *))trdestroycb, NULL, peer); +} + static void cmd_direction(struct socket *sk, struct dcpeer *peer, char *cmd, char *args) { char *p; @@ -1632,8 +1640,7 @@ static void cmd_direction(struct socket *sk, struct dcpeer *peer, char *cmd, cha transfersetstate(transfer, TRNS_HS); } transfersetnick(transfer, peer->wcsname); - peer->transfer = transfer; - CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer); + peerattach(peer, transfer); if(peer->extended) sendsupports(peer); qstrf(sk, "$Direction %s %i|", (peer->direction == TRNSD_UP)?"Upload":"Download", rand() % 10000); @@ -1681,8 +1688,7 @@ static void cmd_peerlock(struct socket *sk, struct dcpeer *peer, char *cmd, char transfersetstate(transfer, TRNS_HS); } transfersetnick(transfer, peer->wcsname); - peer->transfer = transfer; - CBREG(peer->transfer, trans_filterout, (int (*)(struct transfer *, wchar_t *, wchar_t *, void *))trresumecb, NULL, peer); + peerattach(peer, transfer); qstrf(sk, "$Direction %s %i|", (peer->direction == TRNSD_UP)?"Upload":"Download", rand() % 10000); qstrf(sk, "$Key %s|", key); free(key); @@ -2755,17 +2761,29 @@ static void dctransgotdata(struct transfer *transfer, struct dcpeer *peer) static void peerdetach(struct dcpeer *peer) { CBUNREG(peer->transfer, trans_filterout, peer); + CBUNREG(peer->transfer, trans_destroy, peer); closesock(peer->trpipe); quitsock(peer->trpipe); peer->trpipe = NULL; peer->transfer = NULL; } +static int trdestroycb(struct transfer *transfer, struct dcpeer *peer) +{ + peerdetach(peer); + peer->close = 1; + return(0); +} + static void transread(struct socket *sk, struct dcpeer *peer) { void *buf; size_t bufsize; + if(peer->transfer == NULL) { + freedcpeer(peer); + return; + } if(sockqueueleft(peer->trpipe) < 0) return; if((buf = sockgetinbuf(sk, &bufsize)) != NULL) diff --git a/daemon/transfer.c b/daemon/transfer.c index 32f3e28..16e3571 100644 --- a/daemon/transfer.c +++ b/daemon/transfer.c @@ -181,17 +181,18 @@ static void localerr(struct socket *sk, int errno, struct transfer *transfer) static void dataerr(struct socket *sk, int errno, struct transfer *transfer) { - if(transfer->curpos >= transfer->size) { - transfersetstate(transfer, TRNS_DONE); - if(transfer->localend != NULL) { - closesock(transfer->localend); - quitsock(transfer->localend); - transfer->localend = NULL; - } - } else { - if(transfer->dir == TRNSD_DOWN) + 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) + } + } else if(transfer->dir == TRNSD_UP) { transfer->close = 1; } }