xref: /freebsd/lib/libc/rpc/rpc_svc_create.3 (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1.\" Copyright 1989 AT&T
2.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved.
3.Dd May 3, 1993
4.Dt RPC_SVC_CREATE 3
5.Os
6.Sh NAME
7.Nm rpc_svc_create ,
8.Nm svc_control ,
9.Nm svc_create ,
10.Nm svc_destroy ,
11.Nm svc_dg_create ,
12.Nm svc_fd_create ,
13.Nm svc_raw_create ,
14.Nm svc_tli_create ,
15.Nm svc_tp_create ,
16.Nm svc_vc_create
17.Nd library routines for the creation of server handles
18.Sh LIBRARY
19.Lb libc
20.Sh SYNOPSIS
21.In rpc/rpc.h
22.Ft bool_t
23.Fn svc_control "SVCXPRT *svc" "const u_int req" "void *info"
24.Ft int
25.Fn svc_create "void (*dispatch)(struct svc_req *, SVCXPRT *)" "const rpcprog_t prognum" "const rpcvers_t versnum" "const char *nettype"
26.Ft SVCXPRT *
27.Fn svc_dg_create "const int fildes" "const u_int sendsz" "const u_int recvsz"
28.Ft void
29.Fn svc_destroy "SVCXPRT *xprt"
30.Ft "SVCXPRT *"
31.Fn svc_fd_create "const int fildes" "const u_int sendsz" "const u_int recvsz"
32.Ft "SVCXPRT *"
33.Fn svc_raw_create "void"
34.Ft "SVCXPRT *"
35.Fn svc_tli_create "const int fildes" "const struct netconfig *netconf" "const struct t_bind *bindaddr" "const u_int sendsz" "const u_int recvsz"
36.Ft "SVCXPRT *"
37.Fn svc_tp_create "void (*dispatch)(struct svc_req *, SVCXPRT *)" "const rpcprog_t prognum" "const rpcvers_t versnum" "const struct netconfig *netconf"
38.Ft "SVCXPRT *"
39.Fn svc_vc_create "const int fildes" "const u_int sendsz" "const u_int recvsz"
40.Sh DESCRIPTION
41These routines are part of the RPC
42library which allows C language programs to make procedure
43calls on servers across the network.
44These routines deal with the creation of service handles.
45Once the handle is created, the server can be invoked by calling
46.Fn svc_run .
47.Sh Routines
48See
49.Xr rpc 3
50for the definition of the
51.Vt SVCXPRT
52data structure.
53.Bl -tag -width XXXXX
54.It Fn svc_control
55A function to change or retrieve various information
56about a service object.
57The
58.Fa req
59argument
60indicates the type of operation and
61.Fa info
62is a pointer to the information.
63The supported values of
64.Fa req ,
65their argument types, and what they do are:
66.Bl -tag -width SVCGET_XID
67.It Dv SVCGET_VERSQUIET
68If a request is received for a program number
69served by this server but the version number
70is outside the range registered with the server,
71an
72.Dv RPC_PROGVERSMISMATCH
73error will normally
74be returned.
75The
76.Fa info
77argument
78should be a pointer to an
79integer.
80Upon successful completion of the
81.Dv SVCGET_VERSQUIET
82request,
83.Fa *info
84contains an
85integer which describes the server's current
86behavior: 0 indicates normal server behavior
87(that is, an
88.Dv RPC_PROGVERSMISMATCH
89error
90will be returned); 1 indicates that the out of
91range request will be silently ignored.
92.It Dv SVCSET_VERSQUIET
93If a request is received for a program number
94served by this server but the version number
95is outside the range registered with the server,
96an
97.Dv RPC_PROGVERSMISMATCH
98error will normally
99be returned.
100It is sometimes desirable to
101change this behavior.
102The
103.Fa info
104argument
105should be a
106pointer to an integer which is either 0
107(indicating normal server behavior - an
108.Dv RPC_PROGVERSMISMATCH
109error will be returned),
110or 1 (indicating that the out of range request
111should be silently ignored).
112.El
113.It Fn svc_create
114The
115.Fn svc_create
116function
117creates server handles for all the transports
118belonging to the class
119.Fa nettype .
120The
121.Fa nettype
122argument
123defines a class of transports which can be used
124for a particular application.
125The transports are tried in left to right order in
126.Ev NETPATH
127variable or in top to bottom order in the netconfig database.
128If
129.Fa nettype
130is
131.Dv NULL ,
132it defaults to
133.Qq netpath .
134.Pp
135The
136.Fn svc_create
137function
138registers itself with the rpcbind
139service (see
140.Xr rpcbind 8 ) .
141The
142.Fa dispatch
143function
144is called when there is a remote procedure call for the given
145.Fa prognum
146and
147.Fa versnum ;
148this requires calling
149.Fn svc_run
150(see
151.Fn svc_run
152in
153.Xr rpc_svc_reg 3 ) .
154If
155.Fn svc_create
156succeeds, it returns the number of server
157handles it created,
158otherwise it returns 0 and an error message is logged.
159.It Fn svc_destroy
160A function macro that destroys the RPC
161service handle
162.Fa xprt .
163Destruction usually involves deallocation
164of private data structures,
165including
166.Fa xprt
167itself.
168Use of
169.Fa xprt
170is undefined after calling this routine.
171.It Fn svc_dg_create
172This routine creates a connectionless RPC
173service handle, and returns a pointer to it.
174This routine returns
175.Dv NULL
176if it fails, and an error message is logged.
177The
178.Fa sendsz
179and
180.Fa recvsz
181arguments
182are arguments used to specify the size of the buffers.
183If they are 0, suitable defaults are chosen.
184The file descriptor
185.Fa fildes
186should be open and bound.
187The server is not registered with
188.Xr rpcbind 8 .
189.Pp
190Warning:
191since connectionless-based RPC
192messages can only hold limited amount of encoded data,
193this transport cannot be used for procedures
194that take large arguments or return huge results.
195.It Fn svc_fd_create
196This routine creates a service on top of an open and bound file descriptor,
197and returns the handle to it.
198Typically, this descriptor is a connected file descriptor for a
199connection-oriented transport.
200The
201.Fa sendsz
202and
203.Fa recvsz
204arguments
205indicate sizes for the send and receive buffers.
206If they are 0, reasonable defaults are chosen.
207This routine returns
208.Dv NULL
209if it fails, and an error message is logged.
210.It Fn svc_raw_create
211This routine creates an RPC
212service handle and returns a pointer to it.
213The transport is really a buffer within the process's
214address space, so the corresponding RPC
215client should live in the same address space;
216(see
217.Fn clnt_raw_create
218in
219.Xr rpc_clnt_create 3 ) .
220This routine allows simulation of RPC and acquisition of
221RPC overheads (such as round trip times),
222without any kernel and networking interference.
223This routine returns
224.Dv NULL
225if it fails, and an error message is logged.
226.Pp
227Note:
228.Fn svc_run
229should not be called when the raw interface is being used.
230.It Fn svc_tli_create
231This routine creates an RPC
232server handle, and returns a pointer to it.
233The
234.Fa fildes
235argument
236is the file descriptor on which the service is listening.
237If
238.Fa fildes
239is
240.Dv RPC_ANYFD ,
241it opens a file descriptor on the transport specified by
242.Fa netconf .
243If the file descriptor is unbound and
244.Fa bindaddr
245is not
246.Dv NULL ,
247.Fa fildes
248is bound to the address specified by
249.Fa bindaddr ,
250otherwise
251.Fa fildes
252is bound to a default address chosen by the transport.
253.Pp
254Note: the
255.Vt t_bind
256structure comes from the TLI/XTI SysV interface, which
257.Nx
258does not use.
259The structure is defined in
260.In rpc/types.h
261for compatibility as:
262.Bd -literal
263struct t_bind {
264    struct netbuf addr;	/* network address, see rpc(3) */
265    unsigned int  qlen;	/* queue length (for listen(2)) */
266};
267.Ed
268.Pp
269In the case where the default address is chosen,
270the number of outstanding connect requests is set to 8
271for connection-oriented transports.
272The user may specify the size of the send and receive buffers
273with the arguments
274.Fa sendsz
275and
276.Fa recvsz ;
277values of 0 choose suitable defaults.
278This routine returns
279.Dv NULL
280if it fails,
281and an error message is logged.
282The server is not registered with the
283.Xr rpcbind 8
284service.
285.It Fn svc_tp_create
286The
287.Fn svc_tp_create
288function
289creates a server handle for the network
290specified by
291.Fa netconf ,
292and registers itself with the rpcbind service.
293The
294.Fa dispatch
295function
296is called when there is a remote procedure call
297for the given
298.Fa prognum
299and
300.Fa versnum ;
301this requires calling
302.Fn svc_run .
303The
304.Fn svc_tp_create
305function
306returns the service handle if it succeeds,
307otherwise a
308.Dv NULL
309is returned and an error message is logged.
310.It Fn svc_vc_create
311This routine creates a connection-oriented RPC
312service and returns a pointer to it.
313This routine returns
314.Dv NULL
315if it fails, and an error message is logged.
316The users may specify the size of the send and receive buffers
317with the arguments
318.Fa sendsz
319and
320.Fa recvsz ;
321values of 0 choose suitable defaults.
322The file descriptor
323.Fa fildes
324should be open and bound.
325The server is not registered with the
326.Xr rpcbind 8
327service.
328.El
329.Sh SEE ALSO
330.Xr rpc 3 ,
331.Xr rpc_svc_calls 3 ,
332.Xr rpc_svc_err 3 ,
333.Xr rpc_svc_reg 3 ,
334.Xr rpcbind 8
335