4306 rpc_svc_calls(3nsl): Messed svc_sendreply/svc_max_pollfd
[unleashed.git] / usr / src / man / man3nsl / rpc_svc_calls.3nsl
blob105c9d16d4e3cf74d29bcc68a51df0231e733b68
1 '\" te
2 .\" Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
3 .\"  Copyright 1989 AT&T
4 .\" Copyright (C) 2004 Sun Microsystems, Inc. All Rights Reserved
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH RPC_SVC_CALLS 3NSL "Nov 24, 2014"
9 .SH NAME
10 rpc_svc_calls, svc_dg_enablecache, svc_done, svc_exit, svc_fdset, svc_freeargs,
11 svc_getargs, svc_getreq_common, svc_getreq_poll, svc_getreqset,
12 svc_getrpccaller, svc_max_pollfd, svc_pollfd, svc_run, svc_sendreply,
13 svc_getcallerucred, svc_fd_negotiate_ucred \- library routines for RPC servers
14 .SH SYNOPSIS
15 .LP
16 .nf
17 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lnsl\fR [ \fIlibrary\fR...]
18 #include <rpc/rpc.h>
20 \fBint\fR \fBsvc_dg_enablecache\fR(\fBSVCXPRT *\fR\fIxprt\fR, \fBconst uint_t\fR \fIcache_size\fR);
21 .fi
23 .LP
24 .nf
25 \fBint\fR \fBsvc_done\fR(\fBSVCXPRT *\fR\fIxprt\fR);
26 .fi
28 .LP
29 .nf
30 \fBvoid\fR \fBsvc_exit\fR(\fBvoid\fR);
31 .fi
33 .LP
34 .nf
35 \fBvoid\fR \fBsvc_fd_negotiate_ucred\fR(\fBint\fR \fIfd\fR);
36 .fi
38 .LP
39 .nf
40 \fBbool_t\fR \fBsvc_freeargs\fR(\fBconst SVCXPRT *\fR\fIxprt\fR, \fBconst txdrproc_t\fR \fIinproc\fR,
41      \fBcaddr_t\fR \fIin\fR);
42 .fi
44 .LP
45 .nf
46 \fBbool_t\fR \fBsvc_getargs\fR(\fBconst SVCXPRT *\fR\fIxprt\fR, \fBconst xdrproc_t\fR \fIinproc\fR,
47      \fBcaddr_t\fR \fIin\fR);
48 .fi
50 .LP
51 .nf
52 \fBint\fR \fBsvc_getcallerucred\fR(\fBconst SVCXPRT *\fR\fIxprt\fR, \fBucred_t **\fR\fIucred\fR);
53 .fi
55 .LP
56 .nf
57 \fBvoid\fR \fBsvc_getreq_common\fR(\fBconst int\fR \fIfd\fR);
58 .fi
60 .LP
61 .nf
62 \fBvoid\fR \fBsvc_getreqset\fR(\fBfd_set *\fR\fIrdfds\fR);
63 .fi
65 .LP
66 .nf
67 \fBvoid\fR \fBsvc_getreq_poll\fR(\fBstruct pollfd *\fR\fIpfdp\fR, \fBconst int\fR \fIpollretval\fR);
68 .fi
70 .LP
71 .nf
72 \fBstruct netbuf *\fR\fBsvc_getrpccaller\fR(\fBconst SVCXPRT *\fR\fIxprt\fR);
73 .fi
75 .LP
76 .nf
77 \fBvoid\fR \fBsvc_run\fR(\fBvoid\fR);
78 .fi
80 .LP
81 .nf
82 \fBbool_t\fR \fBsvc_sendreply\fR(\fBconst SVCXPRT *\fR\fIxprt\fR, \fBconst xdrproc_t\fR \fIoutproc\fR,
83      \fBcaddr_t\fR \fIout\fR);
84 .fi
86 .LP
87 .nf
88 int svc_max_pollfd;
89 fd_set svc_fdset;
90 pollfd_t *svc_pollfd;
91 .fi
93 .SH DESCRIPTION
94 .LP
95 These routines are part of the \fBRPC\fR library which allows C language
96 programs to make procedure calls on other machines across the network.
97 .sp
98 .LP
99 These routines are associated with the server side of the \fBRPC\fR mechanism.
100 Some of them are called by the server side dispatch function. Others, such as
101 \fBsvc_run()\fR, are called when the server is initiated.
104 Because the service transport handle \fBSVCXPRT\fR contains a single data area
105 for decoding arguments and encoding results, the structure cannot freely be
106 shared between threads that call functions to decode arguments and encode
107 results. When a server is operating in the Automatic or User MT modes, however,
108 a copy of this structure is passed to the service dispatch procedure in order
109 to enable concurrent request processing. Under these circumstances, some
110 routines which would otherwise be Unsafe, become Safe. These are marked as
111 such. Also marked are routines that are Unsafe for multithreaded applications,
112 and are not to be used by such applications. See \fBrpc\fR(3NSL) for the
113 definition of the \fBSVCXPRT\fR data structure.
116 The \fBsvc_dg_enablecache()\fR function allocates a duplicate request cache for
117 the service endpoint \fIxprt\fR, large enough to hold \fIcache_size\fR entries.
118 Once enabled, there is no way to disable caching. The function returns \fB1\fR
119 if space necessary for a cache of the given size was successfully allocated,
120 and \fB0\fR otherwise. This function is Safe in multithreaded applications.
123 The \fBsvc_done()\fR function frees resources allocated to service a client
124 request directed to the service endpoint \fIxprt\fR. This call pertains only to
125 servers executing in the User MT mode. In the User MT mode, service procedures
126 must invoke this call before returning, either after a client request has been
127 serviced, or after an error or abnormal condition that prevents a reply from
128 being sent. After \fBsvc_done\fR() is invoked, the service endpoint \fIxprt\fR
129 should not be referenced by the service procedure. Server multithreading modes
130 and parameters can be set using the \fBrpc_control\fR() call. This function is
131 Safe in multithreaded applications. It will have no effect if invoked in modes
132 other than the User MT mode.
135 The \fBsvc_exit()\fR function when called by any of the RPC server procedures
136 or otherwise, destroys all services registered by the server and causes
137 \fBsvc_run()\fR to return. If RPC server activity is to be resumed, services
138 must be reregistered with the RPC library either through one of the
139 \fBrpc_svc_create\fR(3NSL) functions, or using \fBxprt_register\fR(3NSL). The
140 \fBsvc_exit()\fR function has global scope and ends all RPC server activity.
143 The \fBsvc_freeargs()\fR function macro frees any data allocated by the
144 \fBRPC/XDR\fR system when it decoded the arguments to a service procedure using
145 \fBsvc_getargs()\fR. This routine returns \fBTRUE\fR if the results were
146 successfully freed, and \fBFALSE\fR otherwise. This function macro is Safe in
147 multithreaded applications utilizing the Automatic or User MT modes.
150 The \fBsvc_getargs()\fR function macro decodes the arguments of an \fBRPC\fR
151 request associated with the \fBRPC\fR service transport handle \fIxprt\fR. The
152 parameter \fIin\fR is the address where the arguments will be placed;
153 \fIinproc\fR is the \fBXDR\fR routine used to decode the arguments. This
154 routine returns \fBTRUE\fR if decoding succeeds, and \fBFALSE\fR otherwise.
155 This function macro is Safe in multithreaded applications utilizing the
156 Automatic or User MT modes.
159 The \fBsvc_getreq_common()\fR function is called to handle a request on a file
160 descriptor.
163 The \fBsvc_getreq_poll()\fR function is only of interest if a service
164 implementor does not call \fBsvc_run()\fR, but instead implements custom
165 asynchronous event processing. It is called when \fBpoll\fR(2) has determined
166 that an RPC request has arrived on some RPC file descriptors; \fIpollretval\fR
167 is the return value from \fBpoll\fR(2) and \fIpfdp\fR is the array of
168 \fIpollfd\fR structures on which the \fBpoll\fR(2) was done. It is assumed to
169 be an array large enough to contain the maximal number of descriptors allowed.
170 The \fBsvc_getreq_poll()\fR function macro is Unsafe in multithreaded
171 applications.
174 The \fBsvc_getreqset()\fR function is only of interest if a service implementor
175 does not call \fBsvc_run()\fR, but instead implements custom asynchronous event
176 processing. It is called when \fBselect\fR(3C) has determined that an \fBRPC\fR
177 request has arrived on some \fBRPC\fR file descriptors; \fIrdfds\fR is the
178 resultant read file descriptor bit mask. The routine returns when all file
179 descriptors associated with the value of \fIrdfds\fR have been serviced. This
180 function macro is Unsafe in multithreaded applications.
183 The \fBsvc_getrpccaller()\fR function is the approved way of getting the
184 network address of the caller of a procedure associated with the \fBRPC\fR
185 service transport handle \fIxprt\fR. This function macro is Safe in
186 multithreaded applications.
189 The \fBsvc_run()\fR function never returns. In single-threaded mode, the
190 function waits for \fBRPC\fR requests to arrive. When an RPC request arrives,
191 the \fBsvc_run()\fR function calls the appropriate service procedure. This
192 procedure is usually waiting for the \fBpoll\fR(2) library call to return.
195 Applications that execute in the Automatic or the User MT mode should invoke
196 the \fBsvc_run()\fR function exactly once. In the Automatic MT mode, the
197 \fBsvc_run()\fR function creates threads to service client requests. In the
198 User MT mode, the function provides a framework for service developers to
199 create and manage their own threads for servicing client requests.
202 The \fBsvc_fdset\fR global variable reflects the \fBRPC\fR server's read file
203 descriptor bit mask. This is only of interest if service implementors do not
204 call \fBsvc_run()\fR, but rather do their own asynchronous event processing.
205 This variable is read-only may change after calls to \fBsvc_getreqset()\fR or
206 after any creation routine. Do not pass its address to \fBselect\fR(3C).
207 Instead, pass the address of a copy. Multithreaded applications executing in
208 either the Automatic MT mode or the User MT mode should never read this
209 variable. They should use auxiliary threads to do asynchronous event
210 processing. The \fBsvc_fdset\fR variable is limited to 1024 file descriptors
211 and is considered obsolete. Use of \fBsvc_pollfd\fR is recommended instead.
214 The \fBsvc_pollfd\fR global variable points to an array of \fBpollfd_t\fR
215 structures that reflect the \fBRPC\fR server's read file descriptor array. This
216 is only of interest if service implementors do not call \fBsvc_run()\fR
217 but rather do their own asynchronous event processing. This variable is
218 read-only, and it may change after calls to \fBsvc_getreg_poll()\fR or any
219 creation routines. Do no pass its address to \fBpoll\fR(2). Instead, pass the
220 address of a copy. By default, \fBsvc_pollfd\fR is limited to 1024 entries. Use
221 \fBrpc_control\fR(3NSL) to remove this limitation. Multithreaded applications
222 executing in either the Automatic MT mode or the User MT mode should never be
223 read this variable. They should use auxiliary threads to do asynchronous event
224 processing.
227 The \fBsvc_max_pollfd\fR global variable contains the maximum length of the
228 \fBsvc_pollfd\fR array. This variable is read-only, and it may change after
229 calls to \fBsvc_getreg_poll()\fR or any creation routines.
232 The \fBsvc_sendreply()\fR function is called by an \fBRPC\fR service dispatch
233 routine to send the results of a remote procedure call. The \fIxprt\fR
234 parameter is the transport handle of the request. The \fIoutproc\fR parameter
235 is the \fBXDR\fR routine used to encode the results. The \fIout\fR parameter is
236 the address of the results. This routine returns \fBTRUE\fR if it succeeds,
237 \fBFALSE\fR otherwise. The \fBsvc_sendreply()\fR function macro is Safe in
238 multithreaded applications that use the Automatic or the User MT mode.
241 The \fBsvc_fd_negotiate_ucred()\fR function is called by an RPC server to
242 inform the underlying transport that the function wishes to receive
243 \fBucreds\fR for local calls, including those over IP transports.
246 The \fBsvc_getcallerucred()\fR function attempts to retrieve the \fBucred_t\fR
247 associated with the caller. The function returns \fB\fR0 when successful and
248 \fB-1\fR when not.
251 When successful, the \fBsvc_getcallerucred()\fR function stores the pointer to
252 a freshly allocated \fBucred_t\fR in the memory location pointed to by the
253 \fIucred\fR argument if that memory location contains the null pointer. If the
254 memory location is non-null, the function reuses the existing \fBucred_t\fR.
255 When \fIucred\fR is no longer needed, a credential allocated by
256 \fBsvc_getcallerucred()\fR should be freed with \fBucred_free\fR(3C).
257 .SH ATTRIBUTES
259 See \fBattributes\fR(5) for descriptions of attribute types and values.
264 box;
265 c | c
266 l | l .
267 ATTRIBUTE TYPE  ATTRIBUTE VALUE
269 MT-Level        See below.
274 The \fBsvc_fd_negotiate_ucred()\fR, \fBsvc_dg_enablecache()\fR,
275 \fBsvc_getrpccaller()\fR, and \fBsvc_getcallerucred()\fR functions are Safe in
276 multithreaded applications. The \fBsvc_freeargs()\fR, \fBsvc_getargs()\fR, and
277 \fBsvc_sendreply()\fR functions are Safe in multithreaded applications that use
278 the Automatic or the User MT mode. The \fBsvc_getreq_common()\fR,
279 \fBsvc_getreqset()\fR, and \fBsvc_getreq_poll()\fR functions are Unsafe in
280 multithreaded applications and should be called only from the main thread.
281 .SH SEE ALSO
283 \fBrpcgen\fR(1), \fBpoll\fR(2), \fBgetpeerucred\fR(3C), \fBrpc\fR(3NSL),
284 \fBrpc_control\fR(3NSL), \fBrpc_svc_create\fR(3NSL), \fBrpc_svc_err\fR(3NSL),
285 \fBrpc_svc_reg\fR(3NSL), \fBselect\fR(3C), \fBucred_free\fR(3C),
286 \fBxprt_register\fR(3NSL), \fBattributes\fR(5)