return(new);
}
-void transferattach(struct transfer *transfer, struct transferiface *iface, void *data)
+void transferattach(struct transfer *transfer, struct socket *dpipe)
{
- if(transfer->iface != NULL)
- transferdetach(transfer);
- transfer->iface = iface;
- transfer->ifacedata = data;
+ transferdetach(transfer);
+ getsock(transfer->datapipe = dpipe);
}
void transferdetach(struct transfer *transfer)
{
- if(transfer->iface != NULL)
- {
- transfer->iface->detach(transfer, transfer->ifacedata);
- transfer->iface = NULL;
- transfer->ifacedata = NULL;
+ if(transfer->datapipe != NULL) {
+ closesock(transfer->datapipe);
+ putsock(transfer->datapipe);
}
+ transfer->datapipe = NULL;
}
struct transfer *finddownload(wchar_t *peerid)
for(transfer = transfers; transfer != NULL; transfer = transfer->next)
{
- if((transfer->dir == TRNSD_DOWN) && (transfer->iface == NULL) && !wcscmp(peerid, transfer->peerid))
+ if((transfer->dir == TRNSD_DOWN) && (transfer->datapipe == NULL) && !wcscmp(peerid, transfer->peerid))
break;
}
return(transfer);
return(transfer);
}
-struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data)
+struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct socket *dpipe)
{
struct transfer *transfer;
transfer->dir = TRNSD_UP;
if(fn != NULL)
getfnetnode(transfer->fn = fn);
- transferattach(transfer, iface, data);
+ transferattach(transfer, dpipe);
linktransfer(transfer);
bumptransfer(transfer);
return(transfer);
{
if(transfer->dir == TRNSD_DOWN)
{
- if(transfer->iface != NULL)
- transferdetach(transfer);
+ transferdetach(transfer);
killfilter(transfer);
transfersetstate(transfer, TRNS_WAITING);
transfersetactivity(transfer, L"reset");
transfer->timeout = 0;
}
-static void transferread(struct socket *sk, struct transfer *transfer)
+static void localread(struct socket *sk, struct transfer *transfer)
{
- if(sockgetdatalen(sk) >= 65536)
- sockblock(sk, 1);
- if((transfer->iface != NULL) && (transfer->iface->gotdata != NULL))
- transfer->iface->gotdata(transfer, transfer->ifacedata);
+ void *buf;
+ size_t blen;
+
+ if(transfer->datapipe != NULL) {
+ buf = sockgetinbuf(sk, &blen);
+ sockqueue(transfer->datapipe, buf, blen);
+ if(sockqueuesize(transfer->datapipe) >= 65536)
+ sockblock(sk, 1);
+ else
+ sockblock(sk, 0);
+ } else {
+ if(sockgetdatalen(sk) >= 65536)
+ sockblock(sk, 1);
+ }
}
-static void transferwrite(struct socket *sk, struct transfer *transfer)
+static void localwrite(struct socket *sk, struct transfer *transfer)
{
- if((transfer->iface != NULL) && (transfer->iface->wantdata != NULL))
- transfer->iface->wantdata(transfer, transfer->ifacedata);
+ void *buf;
+ size_t blen;
+
+
}
-static void transfererr(struct socket *sk, int errno, struct transfer *transfer)
+static void localerr(struct socket *sk, int errno, struct transfer *transfer)
{
if((transfer->iface != NULL) && (transfer->iface->endofdata != NULL))
transfer->iface->endofdata(transfer, transfer->ifacedata);
putsock(transfer->localend);
getsock(transfer->localend = sk);
sk->data = transfer;
- sk->readcb = (void (*)(struct socket *, void *))transferread;
- sk->writecb = (void (*)(struct socket *, void *))transferwrite;
- sk->errcb = (void (*)(struct socket *, int, void *))transfererr;
+ sk->readcb = (void (*)(struct socket *, void *))localread;
+ sk->writecb = (void (*)(struct socket *, void *))localwrite;
+ sk->errcb = (void (*)(struct socket *, int, void *))localerr;
}
static int tryreq(struct transfer *transfer)
#define TRNSE_NOTFOUND 1
#define TRNSE_NOSLOTS 2
-struct transfer;
-
-struct transferiface
-{
- void (*detach)(struct transfer *transfer, void *data);
- void (*gotdata)(struct transfer *transfer, void *data);
- void (*endofdata)(struct transfer *transfer, void *data);
- void (*wantdata)(struct transfer *transfer, void *data);
-};
-
struct transfer
{
struct transfer *next, *prev;
time_t timeout, activity, lastreq;
wchar_t *actdesc;
struct fnet *fnet;
- struct transferiface *iface;
wchar_t *peerid, *peernick;
wchar_t *path;
uid_t owner;
int state, dir, error;
off_t size, curpos, endpos;
struct fnetnode *fn;
- void *ifacedata;
- struct socket *localend;
+ struct socket *localend, *datapipe;
struct wcspair *args;
pid_t filter;
struct authhandle *auth;
void bumptransfer(struct transfer *transfer);
struct transfer *findtransfer(int id);
struct transfer *hasupload(struct fnet *fnet, wchar_t *peerid);
-struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data);
+struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct socket *dpipe);
void transfersetnick(struct transfer *transfer, wchar_t *newnick);
void transfersetpath(struct transfer *transfer, wchar_t *newpath);
void transfersetstate(struct transfer *transfer, int newstate);
void transfersetsize(struct transfer *transfer, off_t newsize);
void transferseterror(struct transfer *transfer, int error);
void transfersetactivity(struct transfer *transfer, wchar_t *desc);
-void transferattach(struct transfer *transfer, struct transferiface *iface, void *data);
+void transferattach(struct transfer *transfer, struct socket *dpipe);
void transferdetach(struct transfer *transfer);
void resettransfer(struct transfer *transfer);
void transfersetlocalend(struct transfer *transfer, struct socket *sk);
-void *transfergetdata(struct transfer *transfer, size_t *size);
int forkfilter(struct transfer *transfer);
-void transferputdata(struct transfer *transfer, void *buf, size_t size);
-size_t transferdatasize(struct transfer *transfer);
-void transferendofdata(struct transfer *transfer);
void transferprepul(struct transfer *transfer, off_t size, off_t start, off_t end, struct socket *lesk);
void transferstartul(struct transfer *transfer, struct socket *sk);
void transfersethash(struct transfer *transfer, struct hash *hash);