blob: 08206d6d5e71f70e49bca2b4c3059102961aa437 (
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
58
59
60
61
62
63
|
/* $NetBSD: svc_fdset.c,v 1.1 2013/03/05 19:55:23 christos Exp $ */
#include <sys/cdefs.h>
__RCSID("$NetBSD: svc_fdset.c,v 1.1 2013/03/05 19:55:23 christos Exp $");
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include "svc_fdset.h"
static pthread_key_t fdsetkey;
static pthread_key_t fdmaxkey;
static fd_set thefdset;
static int thefdmax;
void
init_fdsets(void)
{
pthread_key_create(&fdsetkey, NULL);
pthread_key_create(&fdmaxkey, NULL);
}
void
alloc_fdset(void)
{
fd_set *fdsetti;
int *fdmax;
fdsetti = malloc(sizeof(*fdsetti));
memset(fdsetti, 0, sizeof(*fdsetti));
pthread_setspecific(fdsetkey, fdsetti);
fdmax = malloc(sizeof(*fdmax));
memset(fdmax, 0, sizeof(*fdmax));
pthread_setspecific(fdmaxkey, fdmax);
}
fd_set *
get_fdset(void)
{
fd_set *rv;
rv = pthread_getspecific(fdsetkey);
if (rv)
return rv;
else
return &thefdset;
}
int *
get_fdsetmax(void)
{
int *rv;
rv = pthread_getspecific(fdmaxkey);
if (rv)
return rv;
else
return &thefdmax;
}
|