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