Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <venti.h>
4
#include "queue.h"
5
 
6
int chattyventi;
7
 
8
VtConn*
9
vtconn(int infd, int outfd)
10
{
11
	VtConn *z;
12
	NetConnInfo *nci;
13
 
14
	z = vtmallocz(sizeof(VtConn));
15
	z->tagrend.l = &z->lk;
16
	z->rpcfork.l = &z->lk;
17
	z->infd = infd;
18
	z->outfd = outfd;
19
	z->part = packetalloc();
20
	nci = getnetconninfo(nil, infd);
21
	if(nci == nil)
22
		snprint(z->addr, sizeof z->addr, "/dev/fd/%d", infd);
23
	else{
24
		strecpy(z->addr, z->addr+sizeof z->addr, nci->raddr);
25
		freenetconninfo(nci);
26
	}
27
	return z;
28
}
29
 
30
void
31
vtfreeconn(VtConn *z)
32
{
33
	vthangup(z);
34
	qlock(&z->lk);
35
	/*
36
	 * Wait for send and recv procs to notice
37
	 * the hangup and clear out the queues.
38
	 */
39
	while(z->readq || z->writeq){
40
		if(z->readq)
41
			_vtqhangup(z->readq);
42
		if(z->writeq)
43
			_vtqhangup(z->writeq);
44
		rsleep(&z->rpcfork);
45
	}
46
	packetfree(z->part);
47
	vtfree(z->version);
48
	vtfree(z->sid);
49
	qunlock(&z->lk);
50
	vtfree(z);
51
}