aboutsummaryrefslogtreecommitdiff
path: root/src/libsunrpc/net.c
blob: 28890d6c2e69f9e473cbcfa24fab66cc1763c950 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <sunrpc.h>

typedef struct Arg Arg;
struct Arg
{
	int fd;
	char adir[40];
	SunSrv *srv;
};

static void
sunnetlisten(void *v)
{
	int fd, lcfd;
	char ldir[40];
	Arg *a = v;

	for(;;){
		lcfd = listen(a->adir, ldir);
		if(lcfd < 0)
			break;
		fd = accept(lcfd, ldir);
		close(lcfd);
		if(fd < 0)
			continue;
		if(!sunsrvfd(a->srv, fd))
			close(fd);
	}
	free(a);
	close(a->fd);
}

int
sunsrvnet(SunSrv *srv, char *addr)
{
	Arg *a;

	a = emalloc(sizeof(Arg));
	if((a->fd = announce(addr, a->adir)) < 0)
		return -1;
	a->srv = srv;

	proccreate(sunnetlisten, a, SunStackSize);
	return 0;
}

int
sunsrvannounce(SunSrv *srv, char *addr)
{
	if(strstr(addr, "udp!"))
		return sunsrvudp(srv, addr);
	else
		return sunsrvnet(srv, addr);
}