diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libventi/conn.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libventi/conn.c')
-rwxr-xr-x | sys/src/libventi/conn.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sys/src/libventi/conn.c b/sys/src/libventi/conn.c new file mode 100755 index 000000000..e488c6db6 --- /dev/null +++ b/sys/src/libventi/conn.c @@ -0,0 +1,51 @@ +#include <u.h> +#include <libc.h> +#include <venti.h> +#include "queue.h" + +int chattyventi; + +VtConn* +vtconn(int infd, int outfd) +{ + VtConn *z; + NetConnInfo *nci; + + z = vtmallocz(sizeof(VtConn)); + z->tagrend.l = &z->lk; + z->rpcfork.l = &z->lk; + z->infd = infd; + z->outfd = outfd; + z->part = packetalloc(); + nci = getnetconninfo(nil, infd); + if(nci == nil) + snprint(z->addr, sizeof z->addr, "/dev/fd/%d", infd); + else{ + strecpy(z->addr, z->addr+sizeof z->addr, nci->raddr); + freenetconninfo(nci); + } + return z; +} + +void +vtfreeconn(VtConn *z) +{ + vthangup(z); + qlock(&z->lk); + /* + * Wait for send and recv procs to notice + * the hangup and clear out the queues. + */ + while(z->readq || z->writeq){ + if(z->readq) + _vtqhangup(z->readq); + if(z->writeq) + _vtqhangup(z->writeq); + rsleep(&z->rpcfork); + } + packetfree(z->part); + vtfree(z->version); + vtfree(z->sid); + qunlock(&z->lk); + vtfree(z); +} |