1/* $NetBSD: svc.c,v 1.21 2000/07/06 03:10:35 christos Exp $ */ 2 3/* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or --- 20 unchanged lines hidden (view full) --- 29 * Mountain View, California 94043 30 */ 31 32#if defined(LIBC_SCCS) && !defined(lint) 33static char *sccsid = "@(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro"; 34static char *sccsid = "@(#)svc.c 2.4 88/08/11 4.0 RPCSRC"; 35#endif 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/lib/libc/rpc/svc.c 109359 2003-01-16 07:13:51Z mbr $"); |
38 39/* 40 * svc.c, Server-side remote procedure call interface. 41 * 42 * There are two sets of procedures here. The xprt routines are 43 * for handling transport handles. The svc routines handle the 44 * list of service routines. 45 * --- 12 unchanged lines hidden (view full) --- 58#include <rpc/rpc.h> 59#ifdef PORTMAP 60#include <rpc/pmap_clnt.h> 61#endif /* PORTMAP */ 62#include "un-namespace.h" 63 64#include "rpc_com.h" 65 |
66#define RQCRED_SIZE 400 /* this size is excessive */ 67 68#define SVC_VERSQUIET 0x0001 /* keep quiet about vers mismatch */ 69#define version_keepquiet(xp) ((u_long)(xp)->xp_p3 & SVC_VERSQUIET) 70 71#define max(a, b) (a > b ? a : b) 72 73/* --- 10 unchanged lines hidden (view full) --- 84 void (*sc_dispatch)(struct svc_req *, SVCXPRT *); 85} *svc_head; 86 87extern rwlock_t svc_lock; 88extern rwlock_t svc_fd_lock; 89 90static struct svc_callout *svc_find(rpcprog_t, rpcvers_t, 91 struct svc_callout **, char *); |
92static void __xprt_do_unregister (SVCXPRT *xprt, bool_t dolock); |
93 94/* *************** SVCXPRT related stuff **************** */ 95 96/* 97 * Activate a transport handle. 98 */ 99void 100xprt_register(xprt) 101 SVCXPRT *xprt; 102{ 103 int sock; 104 105 assert(xprt != NULL); 106 107 sock = xprt->xp_fd; 108 109 rwlock_wrlock(&svc_fd_lock); |
110 if (__svc_xports == NULL) { 111 __svc_xports = (SVCXPRT **) |
112 mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *)); |
113 if (__svc_xports == NULL) |
114 return; |
115 memset(__svc_xports, '\0', FD_SETSIZE * sizeof(SVCXPRT *)); |
116 } 117 if (sock < FD_SETSIZE) { |
118 __svc_xports[sock] = xprt; |
119 FD_SET(sock, &svc_fdset); 120 svc_maxfd = max(svc_maxfd, sock); 121 } 122 rwlock_unlock(&svc_fd_lock); 123} 124 |
125void 126xprt_unregister(SVCXPRT *xprt) 127{ 128 __xprt_do_unregister(xprt, TRUE); 129} 130 131void 132__xprt_unregister_unlocked(SVCXPRT *xprt) 133{ 134 __xprt_do_unregister(xprt, FALSE); 135} 136 |
137/* 138 * De-activate a transport handle. 139 */ |
140static void 141__xprt_do_unregister(xprt, dolock) |
142 SVCXPRT *xprt; |
143 bool_t dolock; |
144{ 145 int sock; 146 147 assert(xprt != NULL); 148 149 sock = xprt->xp_fd; 150 |
151 if (dolock) 152 rwlock_wrlock(&svc_fd_lock); 153 if ((sock < FD_SETSIZE) && (__svc_xports[sock] == xprt)) { 154 __svc_xports[sock] = NULL; |
155 FD_CLR(sock, &svc_fdset); 156 if (sock >= svc_maxfd) { 157 for (svc_maxfd--; svc_maxfd>=0; svc_maxfd--) |
158 if (__svc_xports[svc_maxfd]) |
159 break; 160 } 161 } |
162 if (dolock) 163 rwlock_unlock(&svc_fd_lock); |
164} 165 166/* 167 * Add a service program to the callout list. 168 * The dispatch routine will be called when a rpc request for this 169 * program number comes in. 170 */ 171bool_t --- 448 unchanged lines hidden (view full) --- 620 enum xprt_stat stat; 621 char cred_area[2*MAX_AUTH_BYTES + RQCRED_SIZE]; 622 623 msg.rm_call.cb_cred.oa_base = cred_area; 624 msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]); 625 r.rq_clntcred = &(cred_area[2*MAX_AUTH_BYTES]); 626 627 rwlock_rdlock(&svc_fd_lock); |
628 xprt = __svc_xports[fd]; |
629 rwlock_unlock(&svc_fd_lock); 630 if (xprt == NULL) 631 /* But do we control sock? */ 632 return; 633 /* now receive msgs from xprtprt (support batch calls) */ 634 do { 635 if (SVC_RECV(xprt, &msg)) { 636 --- 39 unchanged lines hidden (view full) --- 676 /* Fall through to ... */ 677 } 678 /* 679 * Check if the xprt has been disconnected in a 680 * recursive call in the service dispatch routine. 681 * If so, then break. 682 */ 683 rwlock_rdlock(&svc_fd_lock); |
684 if (xprt != __svc_xports[fd]) { |
685 rwlock_unlock(&svc_fd_lock); 686 break; 687 } 688 rwlock_unlock(&svc_fd_lock); 689call_done: 690 if ((stat = SVC_STAT(xprt)) == XPRT_DIED){ 691 SVC_DESTROY(xprt); 692 break; --- 31 unchanged lines hidden (view full) --- 724 rwlock_wrlock(&svc_fd_lock); 725 FD_CLR(p->fd, &svc_fdset); 726 rwlock_unlock(&svc_fd_lock); 727 } else 728 svc_getreq_common(p->fd); 729 } 730 } 731} |
732 733bool_t 734rpc_control(int what, void *arg) 735{ 736 int val; 737 738 switch (what) { 739 case RPC_SVC_CONNMAXREC_SET: 740 val = *(int *)arg; 741 if (val <= 0) 742 return FALSE; 743 __svc_maxrec = val; 744 return TRUE; 745 case RPC_SVC_CONNMAXREC_GET: 746 *(int *)arg = __svc_maxrec; 747 return TRUE; 748 default: 749 break; 750 } 751 return FALSE; 752} |