svc_run.c revision 109904
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 109904 2003-01-26 23:01:49Z mbr $"); 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> 5416270Sjraynard 551901Swollmanvoid 561901Swollmansvc_run() 571901Swollman{ 58109359Smbr fd_set readfds, cleanfds; 59109359Smbr struct timeval timeout; 6074462Salfred extern rwlock_t svc_fd_lock; 611901Swollman 62109359Smbr timeout.tv_sec = 30; 63109359Smbr timeout.tv_usec = 0; 64109359Smbr 651901Swollman for (;;) { 6674462Salfred rwlock_rdlock(&svc_fd_lock); 6774462Salfred readfds = svc_fdset; 68109359Smbr cleanfds = svc_fdset; 6974462Salfred rwlock_unlock(&svc_fd_lock); 70109904Smbr switch (_select(svc_maxfd+1, &readfds, NULL, NULL, &timeout)) { 711901Swollman case -1: 7274462Salfred FD_ZERO(&readfds); 731901Swollman if (errno == EINTR) { 741901Swollman continue; 751901Swollman } 7682496Sbde _warn("svc_run: - select failed"); 771901Swollman return; 781901Swollman case 0: 79109359Smbr __svc_clean_idle(&cleanfds, 30, FALSE); 801901Swollman continue; 811901Swollman default: 8274462Salfred svc_getreqset(&readfds); 831901Swollman } 841901Swollman } 851901Swollman} 8674462Salfred 8774462Salfred/* 8874462Salfred * This function causes svc_run() to exit by telling it that it has no 8974462Salfred * more work to do. 9074462Salfred */ 9174462Salfredvoid 9274462Salfredsvc_exit() 9374462Salfred{ 9474462Salfred extern rwlock_t svc_fd_lock; 9574462Salfred 9674462Salfred rwlock_wrlock(&svc_fd_lock); 9774462Salfred FD_ZERO(&svc_fdset); 9874462Salfred rwlock_unlock(&svc_fd_lock); 9974462Salfred} 100