aboutsummaryrefslogtreecommitdiff
path: root/src/libventi/hangup.c
blob: 230758649c2d3a91d902cc1fa203e868aaaa0248 (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
#include <u.h>
#include <sys/socket.h>
#include <libc.h>
#include <venti.h>
#include "queue.h"

void
vthangup(VtConn *z)
{
	qlock(&z->lk);
	z->state = VtStateClosed;
	/* try to make the read in vtsendproc fail */
	shutdown(SHUT_WR, z->infd);
	shutdown(SHUT_WR, z->outfd);
	if(z->infd >= 0)
		close(z->infd);
	if(z->outfd >= 0 && z->outfd != z->infd)
		close(z->outfd);
	z->infd = -1;
	z->outfd = -1;
	if(z->writeq)
		_vtqhangup(z->writeq);
	if(z->readq)
		_vtqhangup(z->readq);
	qunlock(&z->lk);
}