xref: /netbsd-src/lib/libc/rpc/rpc_svc_calls.3 (revision 7cc2f76925f078d01ddc9e640a98f4ccfc9f8c3b)
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.1 2000/06/02 23:11:13 fvdl 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_pollset,
20.Nm svc_run,
21.Nm svc_sendreply
22.Nd library routines for RPC servers
23.Sh LIBRARY
24.Lb libc
25.Sh SYNOPSIS
26.Fd #include <rpc/rpc.h>
27.Ft int
28.Fn svc_dg_enablecache "SVCXPRT *xprt" "const unsigned cache_size"
29.Ft void
30.Fn svc_exit "void"
31.Ft bool_t
32.Fn svc_freeargs "const SVCXPRT *xprt" "const xdrproc_t inproc" "caddr_t in"
33.Ft bool_t
34.Fn svc_getargs "const SVCXPRT *xprt" "const xdrproc_t inproc" "caddr_t in"
35.Ft void
36.Fn svc_getreq_common "const int fd"
37.Ft void
38.Fn svc_getreq_poll "struct pollfd *pfdp" "const int pollretval"
39.Ft void
40.Fn svc_getreqset "fd_set * rdfds"
41.Ft "struct netbuf *"
42.Fn svc_getrpccaller "const SVCXPRT *xprt"
43.Ft "struct sockcred *"
44.Fn __svc_getcallercreds "const SVCXPRT *xprt"
45.Vt struct pollfd svc_pollset[FD_SETSIZE];
46.Ft void
47.Fn svc_run "void"
48.Ft bool_t
49.Fn svc_sendreply "const SVCXPRT *xprt" "const xdrproc_t outproc" "const caddr_t *out"
50
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.Pp
78.Bl -tag -width __svc_getcallercreds()
79.It Fn svc_dg_enablecache
80This function allocates a duplicate request cache for the
81service endpoint
82.Fa xprt ,
83large enough to hold
84.Fa cache_size
85entries.
86Once enabled, there is no way to disable caching.
87This routine returns 0 if space necessary for a cache of the given size
88was successfully allocated, and 1 otherwise.
89.It Fn svc_exit
90This function when called by any of the RPC server procedure or
91otherwise, causes
92.Fn svc_run
93to return.
94.Pp
95As currently implemented,
96.Fn svc_exit
97zeroes the
98.Dv svc_fdset
99global variable. If 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.Pp
123.It Fn svc_freeargs
124A function macro that frees any data allocated by the
125RPC/XDR system when it decoded the arguments to a service procedure
126using
127.Fn svc_getargs .
128This routine returns
129.Dv TRUE
130if the results were successfully
131freed, and
132.Dv FALSE
133otherwise.
134.Pp
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 parameter
141.Fa in
142is the address where the arguments will be placed;
143.Fa inproc
144is the XDR
145routine used to decode the arguments.
146This routine returns
147.Dv TRUE
148if decoding succeeds, and
149.Dv FALSE
150otherwise.
151.It Fn svc_getreq_common
152This routine is called to handle a request on the given
153file descriptor.
154.Pp
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.Fn pollretval
165is the return value from
166.Xr poll 2
167and
168.Fa pfdp
169is the array of
170.Fa 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.Pp
177.Fn svc_getreqset
178This routine is only of interest if a service implementor
179does not call
180.Fn svc_run ,
181but instead implements custom asynchronous event processing.
182It is called when
183.Xr poll 2
184has determined that an RPC
185request has arrived on some RPC file descriptors;
186.Fa rdfds
187is the resultant read file descriptor bit mask.
188The routine returns when all file descriptors
189associated with the value of
190.Fa rdfds
191have been serviced.
192.Pp
193.It Fn svc_getrpccaller
194The approved way of getting the network address of the caller
195of a procedure associated with the
196RPC service transport handle
197.Fa xprt .
198.Pp
199.It Fn __svc_getcallercreds
200.Bf Warning: this macro is specific to NetBSD and thus not portable.
201This macro returns a pointer to a sockcred structure, defined in
202.Fd <sys/socket.h> ,
203identifying the calling client. This only works if the client is
204calling the server over an
205.Dv AF_LOCAL
206socket.
207.It Fa struct pollfd svc_pollset[FD_SETSIZE];
208.Va svc_pollset
209is an array of
210.Vt pollfd
211structures derived from
212.Va svc_fdset[] .
213It is suitable as a parameter to the
214.Xr  poll 2
215system call.
216The derivation of
217.Va svc_pollset
218from
219.Va svc_fdset
220is made in the current implementation in
221.Fn svc_run .
222Service implementors who do not call
223.Fn svc_run
224and who wish to use this array must perform this derivation themselves.
225.Pp
226.It Fn svc_run
227.IP
228This routine never returns.
229It waits for RPC
230requests to arrive, and calls the appropriate service
231procedure using
232.Fn svc_getreq_poll
233when one arrives.
234This procedure is usually waiting for the
235.Xr poll 2
236system call to return.
237.Pp
238.It Fn svc_sendreply
239Called by an RPC service's dispatch routine to send the results of a
240remote procedure call. The parameter
241.Fa xprt
242is the request's associated transport handle;
243.Fa outproc
244is the XDR
245routine which is used to encode the results; and
246.Fa out
247is the address of the results.
248This routine returns
249.Dv TRUE
250if it succeeds,
251.Dv FALSE
252otherwise.
253.El
254.Sh SEE ALSO
255.Xr poll 2 ,
256.Xr rpc 3 ,
257.Xr rpc_svc_create 3 ,
258.Xr rpc_svc_err 3 ,
259.Xr rpc_svc_reg 3 ,
260