1.\" Copyright 1989 AT&T 2.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved. 3.\" $NetBSD: rpc_svc_calls.3,v 1.1 2000/06/02 23:11:13 fvdl Exp $ 4.Dd May 3, 1993 5.Dt RPC_SVC_CALLS 3 6.Os 7.Sh NAME 8.Nm svc_dg_enablecache , 9.Nm svc_exit , 10.Nm svc_fdset , 11.Nm svc_freeargs , 12.Nm svc_getargs , 13.Nm svc_getreq_common , 14.Nm svc_getreq_poll , 15.Nm svc_getreqset , 16.Nm svc_getrpccaller , 17.Nm svc_pollset , 18.Nm svc_run , 19.Nm svc_sendreply 20.Nd library routines for RPC servers 21.Sh LIBRARY 22.Lb libc 23.Sh SYNOPSIS 24.In rpc/rpc.h 25.Ft int 26.Fn svc_dg_enablecache "SVCXPRT *xprt" "const unsigned cache_size" 27.Ft void 28.Fn svc_exit "void" 29.Ft bool_t 30.Fn svc_freeargs "const SVCXPRT *xprt" "const xdrproc_t inproc" "caddr_t in" 31.Ft bool_t 32.Fn svc_getargs "const SVCXPRT *xprt" "const xdrproc_t inproc" "caddr_t in" 33.Ft void 34.Fn svc_getreq_common "const int fd" 35.Ft void 36.Fn svc_getreq_poll "struct pollfd *pfdp" "const int pollretval" 37.Ft void 38.Fn svc_getreqset "fd_set * rdfds" 39.Ft "struct netbuf *" 40.Fn svc_getrpccaller "const SVCXPRT *xprt" 41.Ft "struct cmsgcred *" 42.Fn __svc_getcallercreds "const SVCXPRT *xprt" 43.Vt struct pollfd svc_pollset[FD_SETSIZE]; 44.Ft void 45.Fn svc_run "void" 46.Ft bool_t 47.Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "void *out" 48.Sh DESCRIPTION 49These routines are part of the 50RPC 51library which allows C language programs to make procedure 52calls on other machines across the network. 53.Pp 54These routines are associated with the server side of the 55RPC mechanism. 56Some of them are called by the server side dispatch function, 57while others 58(such as 59.Fn svc_run ) 60are called when the server is initiated. 61.\" .Pp 62.\" In the current implementation, the service transport handle, 63.\" .Dv SVCXPRT , 64.\" contains a single data area for decoding arguments and encoding results. 65.\" Therefore, this structure cannot be freely shared between threads that call 66.\" functions that do this. 67.\" Routines on this page that are affected by this 68.\" restriction are marked as unsafe for MT applications. 69.Sh Routines 70See 71.Xr rpc 3 72for the definition of the 73.Vt SVCXPRT 74data structure. 75.Bl -tag -width __svc_getcallercreds() 76.It Fn svc_dg_enablecache 77This function allocates a duplicate request cache for the 78service endpoint 79.Fa xprt , 80large enough to hold 81.Fa cache_size 82entries. 83Once enabled, there is no way to disable caching. 84This routine returns 0 if space necessary for a cache of the given size 85was successfully allocated, and 1 otherwise. 86.It Fn svc_exit 87This function, when called by any of the RPC server procedure or 88otherwise, causes 89.Fn svc_run 90to return. 91.Pp 92As currently implemented, 93.Fn svc_exit 94zeroes the 95.Va svc_fdset 96global variable. 97If RPC server activity is to be resumed, 98services must be reregistered with the RPC library 99either through one of the 100.Xr rpc_svc_create 3 101functions, or using 102.Fn xprt_register . 103The 104.Fn svc_exit 105function 106has global scope and ends all RPC server activity. 107.It Xo 108.Vt fd_set Va svc_fdset 109.Xc 110A global variable reflecting the 111RPC server's read file descriptor bit mask; it is suitable as an argument 112to the 113.Xr select 2 114system call. 115This is only of interest 116if service implementors do not call 117.Fn svc_run , 118but rather do their own asynchronous event processing. 119This variable is read-only (do not pass its address to 120.Xr select 2 ! ) , 121yet it may change after calls to 122.Fn svc_getreqset 123or any creation routines. 124.It Fn svc_freeargs 125A function macro that frees any data allocated by the 126RPC/XDR system when it decoded the arguments to a service procedure 127using 128.Fn svc_getargs . 129This routine returns 130.Dv TRUE 131if the results were successfully 132freed, and 133.Dv FALSE 134otherwise. 135.It Fn svc_getargs 136A function macro that decodes the arguments of an 137RPC request associated with the RPC 138service transport handle 139.Fa xprt . 140The 141.Fa in 142argument 143is the address where the arguments will be placed; 144.Fa inproc 145is the XDR 146routine used to decode the arguments. 147This routine returns 148.Dv TRUE 149if decoding succeeds, and 150.Dv FALSE 151otherwise. 152.It Fn svc_getreq_common 153This routine is called to handle a request on the given 154file descriptor. 155.It Fn svc_getreq_poll 156This routine is only of interest if a service implementor 157does not call 158.Fn svc_run , 159but instead implements custom asynchronous event processing. 160It is called when 161.Xr poll 2 162has determined that an RPC request has arrived on some RPC 163file descriptors; 164.Fa pollretval 165is the return value from 166.Xr poll 2 167and 168.Fa pfdp 169is the array of 170.Vt pollfd 171structures on which the 172.Xr poll 2 173was done. 174It is assumed to be an array large enough to 175contain the maximal number of descriptors allowed. 176.It Fn svc_getreqset 177This routine is only of interest if a service implementor 178does not call 179.Fn svc_run , 180but instead implements custom asynchronous event processing. 181It is called when 182.Xr poll 2 183has determined that an RPC 184request has arrived on some RPC file descriptors; 185.Fa rdfds 186is the resultant read file descriptor bit mask. 187The routine returns when all file descriptors 188associated with the value of 189.Fa rdfds 190have been serviced. 191.It Fn svc_getrpccaller 192The approved way of getting the network address of the caller 193of a procedure associated with the 194RPC service transport handle 195.Fa xprt . 196.It Fn __svc_getcallercreds 197.Em Warning : 198this macro is specific to 199.Fx 200and thus not portable. 201This macro returns a pointer to a 202.Vt cmsgcred 203structure, defined in 204.In sys/socket.h , 205identifying the calling client. 206This only works if the client is 207calling the server over an 208.Dv AF_LOCAL 209socket. 210.It Xo 211.Vt struct pollfd Va svc_pollset[FD_SETSIZE] ; 212.Xc 213.Va svc_pollset 214is an array of 215.Vt pollfd 216structures derived from 217.Va svc_fdset[] . 218It is suitable as an argument to the 219.Xr poll 2 220system call. 221The derivation of 222.Va svc_pollset 223from 224.Va svc_fdset 225is made in the current implementation in 226.Fn svc_run . 227Service implementors who do not call 228.Fn svc_run 229and who wish to use this array must perform this derivation themselves. 230.It Fn svc_run 231This routine never returns. 232It waits for RPC 233requests to arrive, and calls the appropriate service 234procedure using 235.Fn svc_getreq_poll 236when one arrives. 237This procedure is usually waiting for the 238.Xr poll 2 239system call to return. 240.It Fn svc_sendreply 241Called by an RPC service's dispatch routine to send the results of a 242remote procedure call. 243The 244.Fa xprt 245argument 246is the request's associated transport handle; 247.Fa outproc 248is the XDR 249routine which is used to encode the results; and 250.Fa out 251is the address of the results. 252This routine returns 253.Dv TRUE 254if it succeeds, 255.Dv FALSE 256otherwise. 257.El 258.Sh SEE ALSO 259.Xr poll 2 , 260.Xr select 2 , 261.Xr rpc 3 , 262.Xr rpc_svc_create 3 , 263.Xr rpc_svc_err 3 , 264.Xr rpc_svc_reg 3 265