Home | History | Annotate | Line # | Download | only in rpc
svc_run.c revision 1.19.58.1
      1  1.19.58.1       riz /*	$NetBSD: svc_run.c,v 1.19.58.1 2013/03/14 22:03:08 riz Exp $	*/
      2        1.6       cgd 
      3        1.1       cgd /*
      4  1.19.58.1       riz  * Copyright (c) 2010, Oracle America, Inc.
      5  1.19.58.1       riz  *
      6  1.19.58.1       riz  * Redistribution and use in source and binary forms, with or without
      7  1.19.58.1       riz  * modification, are permitted provided that the following conditions are
      8  1.19.58.1       riz  * met:
      9  1.19.58.1       riz  *
     10  1.19.58.1       riz  *     * Redistributions of source code must retain the above copyright
     11  1.19.58.1       riz  *       notice, this list of conditions and the following disclaimer.
     12  1.19.58.1       riz  *     * Redistributions in binary form must reproduce the above
     13  1.19.58.1       riz  *       copyright notice, this list of conditions and the following
     14  1.19.58.1       riz  *       disclaimer in the documentation and/or other materials
     15  1.19.58.1       riz  *       provided with the distribution.
     16  1.19.58.1       riz  *     * Neither the name of the "Oracle America, Inc." nor the names of its
     17  1.19.58.1       riz  *       contributors may be used to endorse or promote products derived
     18  1.19.58.1       riz  *       from this software without specific prior written permission.
     19  1.19.58.1       riz  *
     20  1.19.58.1       riz  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  1.19.58.1       riz  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  1.19.58.1       riz  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     23  1.19.58.1       riz  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     24  1.19.58.1       riz  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     25  1.19.58.1       riz  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.19.58.1       riz  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     27  1.19.58.1       riz  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  1.19.58.1       riz  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  1.19.58.1       riz  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30  1.19.58.1       riz  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     31  1.19.58.1       riz  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32        1.1       cgd  */
     33        1.1       cgd 
     34        1.8  christos #include <sys/cdefs.h>
     35        1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     36        1.8  christos #if 0
     37        1.8  christos static char *sccsid = "@(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";
     38        1.8  christos static char *sccsid = "@(#)svc_run.c	2.1 88/07/29 4.0 RPCSRC";
     39        1.8  christos #else
     40  1.19.58.1       riz __RCSID("$NetBSD: svc_run.c,v 1.19.58.1 2013/03/14 22:03:08 riz Exp $");
     41        1.8  christos #endif
     42        1.1       cgd #endif
     43        1.1       cgd 
     44        1.1       cgd /*
     45        1.1       cgd  * This is the rpc server side idle loop
     46        1.1       cgd  * Wait for input, call server program.
     47        1.1       cgd  */
     48        1.9       jtc #include "namespace.h"
     49       1.15      fvdl #include "reentrant.h"
     50       1.12     lukem #include <err.h>
     51       1.12     lukem #include <errno.h>
     52        1.8  christos #include <stdio.h>
     53       1.16   thorpej #include <string.h>
     54       1.12     lukem #include <unistd.h>
     55       1.12     lukem 
     56       1.11     lukem #include <rpc/rpc.h>
     57        1.9       jtc 
     58       1.18      fvdl #include "rpc_internal.h"
     59       1.18      fvdl 
     60        1.9       jtc #ifdef __weak_alias
     61       1.14   mycroft __weak_alias(svc_run,_svc_run)
     62       1.15      fvdl __weak_alias(svc_exit,_svc_exit)
     63        1.9       jtc #endif
     64        1.3   deraadt 
     65        1.1       cgd void
     66        1.1       cgd svc_run()
     67        1.1       cgd {
     68       1.18      fvdl 	fd_set readfds, cleanfds;
     69       1.18      fvdl 	struct timeval timeout;
     70       1.19   thorpej #ifdef _REENTRANT
     71       1.15      fvdl 	extern rwlock_t svc_fd_lock;
     72       1.15      fvdl #endif
     73        1.1       cgd 
     74       1.18      fvdl 	timeout.tv_sec = 30;
     75       1.18      fvdl 	timeout.tv_usec = 0;
     76       1.18      fvdl 
     77        1.1       cgd 	for (;;) {
     78       1.15      fvdl 		rwlock_rdlock(&svc_fd_lock);
     79        1.1       cgd 		readfds = svc_fdset;
     80       1.18      fvdl 		cleanfds = svc_fdset;
     81       1.15      fvdl 		rwlock_unlock(&svc_fd_lock);
     82       1.18      fvdl 		switch (select(svc_maxfd+1, &readfds, NULL, NULL, &timeout)) {
     83        1.1       cgd 		case -1:
     84        1.1       cgd 			if (errno == EINTR) {
     85        1.1       cgd 				continue;
     86        1.1       cgd 			}
     87       1.13     lukem 			warn("svc_run: - select failed");
     88        1.1       cgd 			return;
     89        1.1       cgd 		case 0:
     90       1.18      fvdl 			__svc_clean_idle(&cleanfds, 30, FALSE);
     91        1.1       cgd 			continue;
     92        1.1       cgd 		default:
     93        1.1       cgd 			svc_getreqset(&readfds);
     94        1.1       cgd 		}
     95        1.1       cgd 	}
     96       1.15      fvdl }
     97       1.15      fvdl 
     98       1.15      fvdl /*
     99       1.15      fvdl  *      This function causes svc_run() to exit by telling it that it has no
    100       1.15      fvdl  *      more work to do.
    101       1.15      fvdl  */
    102       1.15      fvdl void
    103       1.15      fvdl svc_exit()
    104       1.15      fvdl {
    105       1.19   thorpej #ifdef _REENTRANT
    106       1.15      fvdl 	extern rwlock_t svc_fd_lock;
    107       1.15      fvdl #endif
    108       1.15      fvdl 
    109       1.15      fvdl 	rwlock_wrlock(&svc_fd_lock);
    110       1.15      fvdl 	FD_ZERO(&svc_fdset);
    111       1.15      fvdl 	rwlock_unlock(&svc_fd_lock);
    112        1.1       cgd }
    113