aboutsummaryrefslogtreecommitdiff
path: root/src/libventi/conn.c
blob: 3f4197905c7771b0336f583749ca0ada7c88ee74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <u.h>
#include <libc.h>
#include <venti.h>
#include "queue.h"

int chattyventi;

VtConn*
vtconn(int infd, int outfd)
{
	VtConn *z;

	z = vtmallocz(sizeof(VtConn));
	z->tagrend.l = &z->lk;
	z->rpcfork.l = &z->lk;
	z->infd = infd;
	z->outfd = outfd;
	z->part = packetalloc();
	return z;
}

void
vtfreeconn(VtConn *z)
{
	vthangup(z);
	qlock(&z->lk);
	for(;;){
		if(z->readq)
			_vtqhangup(z->readq);
		else if(z->writeq)
			_vtqhangup(z->writeq);
		else
			break;
		rsleep(&z->rpcfork);
	}
	packetfree(z->part);
	vtfree(z);
}