svc_run.c revision 111618
174462Salfred/*	$NetBSD: svc_run.c,v 1.17 2000/07/06 03:10:35 christos Exp $	*/
274462Salfred
31901Swollman/*
41901Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
51901Swollman * unrestricted use provided that this legend is included on all tape
61901Swollman * media and as a part of the software program in whole or part.  Users
71901Swollman * may copy or modify Sun RPC without charge, but are not authorized
81901Swollman * to license or distribute it to anyone else except as part of a product or
91901Swollman * program developed by the user.
108870Srgrimes *
111901Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
121901Swollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
131901Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
148870Srgrimes *
151901Swollman * Sun RPC is provided with no support and without any obligation on the
161901Swollman * part of Sun Microsystems, Inc. to assist in its use, correction,
171901Swollman * modification or enhancement.
188870Srgrimes *
191901Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
201901Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
211901Swollman * OR ANY PART THEREOF.
228870Srgrimes *
231901Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue
241901Swollman * or profits or other special, indirect and consequential damages, even if
251901Swollman * Sun has been advised of the possibility of such damages.
268870Srgrimes *
271901Swollman * Sun Microsystems, Inc.
281901Swollman * 2550 Garcia Avenue
291901Swollman * Mountain View, California  94043
301901Swollman */
311901Swollman
321901Swollman#if defined(LIBC_SCCS) && !defined(lint)
3392990Sobrienstatic char *sccsid = "from: @(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";
3492990Sobrienstatic char *sccsid = "from: @(#)svc_run.c	2.1 88/07/29 4.0 RPCSRC";
351901Swollman#endif
3692990Sobrien#include <sys/cdefs.h>
3792990Sobrien__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_run.c 111618 2003-02-27 13:40:01Z nectar $");
381901Swollman
391901Swollman/*
401901Swollman * This is the rpc server side idle loop
411901Swollman * Wait for input, call server program.
421901Swollman */
4375094Siedowse#include "namespace.h"
4474462Salfred#include "reentrant.h"
4574462Salfred#include <err.h>
4674462Salfred#include <errno.h>
471901Swollman#include <rpc/rpc.h>
4816270Sjraynard#include <stdio.h>
4974462Salfred#include <string.h>
5016270Sjraynard#include <unistd.h>
5171579Sdeischen#include "un-namespace.h"
521901Swollman
5374462Salfred#include <rpc/rpc.h>
54111618Snectar#include "rpc_com.h"
5516270Sjraynard
561901Swollmanvoid
571901Swollmansvc_run()
581901Swollman{
59109359Smbr	fd_set readfds, cleanfds;
60109359Smbr	struct timeval timeout;
6174462Salfred	extern rwlock_t svc_fd_lock;
621901Swollman
63109359Smbr	timeout.tv_sec = 30;
64109359Smbr	timeout.tv_usec = 0;
65109359Smbr
661901Swollman	for (;;) {
6774462Salfred		rwlock_rdlock(&svc_fd_lock);
6874462Salfred		readfds = svc_fdset;
69109359Smbr		cleanfds = svc_fdset;
7074462Salfred		rwlock_unlock(&svc_fd_lock);
71109904Smbr		switch (_select(svc_maxfd+1, &readfds, NULL, NULL, &timeout)) {
721901Swollman		case -1:
7374462Salfred			FD_ZERO(&readfds);
741901Swollman			if (errno == EINTR) {
751901Swollman				continue;
761901Swollman			}
7782496Sbde			_warn("svc_run: - select failed");
781901Swollman			return;
791901Swollman		case 0:
80109359Smbr			__svc_clean_idle(&cleanfds, 30, FALSE);
811901Swollman			continue;
821901Swollman		default:
8374462Salfred			svc_getreqset(&readfds);
841901Swollman		}
851901Swollman	}
861901Swollman}
8774462Salfred
8874462Salfred/*
8974462Salfred *      This function causes svc_run() to exit by telling it that it has no
9074462Salfred *      more work to do.
9174462Salfred */
9274462Salfredvoid
9374462Salfredsvc_exit()
9474462Salfred{
9574462Salfred	extern rwlock_t svc_fd_lock;
9674462Salfred
9774462Salfred	rwlock_wrlock(&svc_fd_lock);
9874462Salfred	FD_ZERO(&svc_fdset);
9974462Salfred	rwlock_unlock(&svc_fd_lock);
10074462Salfred}
101