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 13 static pthread_key_t fdsetkey; 14 static pthread_key_t fdmaxkey; 15 static fd_set thefdset; 16 static int thefdmax; 17 18 void 19 init_fdsets(void) 20 { 21 22 pthread_key_create(&fdsetkey, NULL); 23 pthread_key_create(&fdmaxkey, NULL); 24 } 25 26 void 27 alloc_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 41 fd_set * 42 get_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 53 int * 54 get_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