svc_fdset.c revision 1.1
1/*	$NetBSD: svc_fdset.c,v 1.1 2013/03/05 19:55:23 christos Exp $	*/
2
3#include <sys/cdefs.h>
4__RCSID("$NetBSD: svc_fdset.c,v 1.1 2013/03/05 19:55:23 christos Exp $");
5
6#include <pthread.h>
7#include <stdlib.h>
8#include <string.h>
9#include <sys/select.h>
10
11#include "svc_fdset.h"
12
13static pthread_key_t fdsetkey;
14static pthread_key_t fdmaxkey;
15static fd_set thefdset;
16static int thefdmax;
17
18void
19init_fdsets(void)
20{
21
22	pthread_key_create(&fdsetkey, NULL);
23	pthread_key_create(&fdmaxkey, NULL);
24}
25
26void
27alloc_fdset(void)
28{
29	fd_set *fdsetti;
30	int *fdmax;
31
32	fdsetti = malloc(sizeof(*fdsetti));
33	memset(fdsetti, 0, sizeof(*fdsetti));
34	pthread_setspecific(fdsetkey, fdsetti);
35
36	fdmax = malloc(sizeof(*fdmax));
37	memset(fdmax, 0, sizeof(*fdmax));
38	pthread_setspecific(fdmaxkey, fdmax);
39}
40
41fd_set *
42get_fdset(void)
43{
44	fd_set *rv;
45
46	rv = pthread_getspecific(fdsetkey);
47	if (rv)
48		return rv;
49	else
50		return &thefdset;
51}
52
53int *
54get_fdsetmax(void)
55{
56	int *rv;
57
58	rv = pthread_getspecific(fdmaxkey);
59	if (rv)
60		return rv;
61	else
62		return &thefdmax;
63}
64