1 | #ifndef RPCIO_H |
---|
2 | #define RPCIO_H |
---|
3 | /* $Id$ */ |
---|
4 | |
---|
5 | /* A multihreaded RPC/UDP multiplexor */ |
---|
6 | |
---|
7 | /* Author: Till Straumann, <strauman@slac.stanford.edu>, 2002 */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Authorship |
---|
11 | * ---------- |
---|
12 | * This software (NFS-2 client implementation for RTEMS) was created by |
---|
13 | * Till Straumann <strauman@slac.stanford.edu>, 2002-2007, |
---|
14 | * Stanford Linear Accelerator Center, Stanford University. |
---|
15 | * |
---|
16 | * Acknowledgement of sponsorship |
---|
17 | * ------------------------------ |
---|
18 | * The NFS-2 client implementation for RTEMS was produced by |
---|
19 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
20 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
21 | * |
---|
22 | * Government disclaimer of liability |
---|
23 | * ---------------------------------- |
---|
24 | * Neither the United States nor the United States Department of Energy, |
---|
25 | * nor any of their employees, makes any warranty, express or implied, or |
---|
26 | * assumes any legal liability or responsibility for the accuracy, |
---|
27 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
28 | * disclosed, or represents that its use would not infringe privately owned |
---|
29 | * rights. |
---|
30 | * |
---|
31 | * Stanford disclaimer of liability |
---|
32 | * -------------------------------- |
---|
33 | * Stanford University makes no representations or warranties, express or |
---|
34 | * implied, nor assumes any liability for the use of this software. |
---|
35 | * |
---|
36 | * Stanford disclaimer of copyright |
---|
37 | * -------------------------------- |
---|
38 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
39 | * copyright and all other rights in this software. Hence, anyone may |
---|
40 | * freely use it for any purpose without restriction. |
---|
41 | * |
---|
42 | * Maintenance of notices |
---|
43 | * ---------------------- |
---|
44 | * In the interest of clarity regarding the origin and status of this |
---|
45 | * SLAC software, this and all the preceding Stanford University notices |
---|
46 | * are to remain affixed to any copy or derivative of this software made |
---|
47 | * or distributed by the recipient and are to be affixed to any copy of |
---|
48 | * software made or distributed by the recipient that contains a copy or |
---|
49 | * derivative of this software. |
---|
50 | * |
---|
51 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
52 | */ |
---|
53 | |
---|
54 | #ifdef __rtems |
---|
55 | #include <rtems.h> |
---|
56 | #endif |
---|
57 | |
---|
58 | #include <rpc/rpc.h> |
---|
59 | #include <errno.h> |
---|
60 | #include <sys/ioctl.h> |
---|
61 | #include <sys/param.h> |
---|
62 | #include <stdarg.h> |
---|
63 | |
---|
64 | typedef struct RpcUdpServerRec_ *RpcUdpServer; |
---|
65 | typedef struct RpcUdpXactRec_ *RpcUdpXact; |
---|
66 | |
---|
67 | typedef RpcUdpXact RpcUdpClnt; |
---|
68 | |
---|
69 | #define RPCIOD_DEFAULT_ID 0xdef10000 |
---|
70 | |
---|
71 | int |
---|
72 | rpcUdpInit(void); |
---|
73 | |
---|
74 | enum clnt_stat |
---|
75 | rpcUdpServerCreate( |
---|
76 | struct sockaddr_in *paddr, |
---|
77 | int prog, |
---|
78 | int vers, |
---|
79 | u_long uid, /* RPCIO_DEFAULT_ID picks default */ |
---|
80 | u_long gid, /* RPCIO_DEFAULT_ID picks default */ |
---|
81 | RpcUdpServer *pclnt /* new server is returned here */ |
---|
82 | ); |
---|
83 | |
---|
84 | |
---|
85 | void |
---|
86 | rpcUdpServerDestroy(RpcUdpServer s); |
---|
87 | |
---|
88 | /* Dump statistics to a file (stdout if NULL); |
---|
89 | * returns 0 for convenience |
---|
90 | */ |
---|
91 | int |
---|
92 | rpcUdpStats(FILE *f); |
---|
93 | |
---|
94 | enum clnt_stat |
---|
95 | rpcUdpClntCreate( |
---|
96 | struct sockaddr_in *psaddr, |
---|
97 | int prog, |
---|
98 | int vers, |
---|
99 | u_long uid, /* RPCIO_DEFAULT_ID picks default */ |
---|
100 | u_long gid, /* RPCIO_DEFAULT_ID picks default */ |
---|
101 | RpcUdpClnt *pclnt /* new client is returned here */ |
---|
102 | ); |
---|
103 | |
---|
104 | void |
---|
105 | RpcUdpClntDestroy(RpcUdpClnt clnt); |
---|
106 | |
---|
107 | /* mute compiler warnings */ |
---|
108 | typedef void *XdrProcT; |
---|
109 | typedef void *CaddrT; |
---|
110 | |
---|
111 | enum clnt_stat |
---|
112 | rpcUdpClntCall( |
---|
113 | RpcUdpClnt clnt, |
---|
114 | u_long proc, |
---|
115 | XdrProcT xargs, |
---|
116 | CaddrT pargs, |
---|
117 | XdrProcT xres, |
---|
118 | CaddrT pres, |
---|
119 | struct timeval *timeout /* optional timeout; maybe NULL to pick default */ |
---|
120 | ); |
---|
121 | |
---|
122 | RpcUdpXact |
---|
123 | rpcUdpXactCreate( |
---|
124 | u_long program, |
---|
125 | u_long version, |
---|
126 | u_long size |
---|
127 | ); |
---|
128 | |
---|
129 | void |
---|
130 | rpcUdpXactDestroy( |
---|
131 | RpcUdpXact xact |
---|
132 | ); |
---|
133 | |
---|
134 | /* send a transaction */ |
---|
135 | enum clnt_stat |
---|
136 | rpcUdpSend( |
---|
137 | RpcUdpXact xact, |
---|
138 | RpcUdpServer srvr, |
---|
139 | struct timeval *timeout, /* maybe NULL to pick default */ |
---|
140 | u_long proc, |
---|
141 | xdrproc_t xres, |
---|
142 | caddr_t pres, |
---|
143 | xdrproc_t xargs, |
---|
144 | caddr_t pargs, |
---|
145 | ... /* 0 terminated xdrproc/pobj additional argument list */ |
---|
146 | ); |
---|
147 | |
---|
148 | /* wait for a transaction to complete */ |
---|
149 | enum clnt_stat |
---|
150 | rpcUdpRcv(RpcUdpXact xact); |
---|
151 | |
---|
152 | /* a yet simpler interface */ |
---|
153 | enum clnt_stat |
---|
154 | rpcUdpCallRp( |
---|
155 | struct sockaddr_in *pserver_addr, |
---|
156 | u_long prog, |
---|
157 | u_long vers, |
---|
158 | u_long proc, |
---|
159 | XdrProcT xargs, |
---|
160 | CaddrT pargs, |
---|
161 | XdrProcT xres, |
---|
162 | CaddrT pres, |
---|
163 | u_long uid, /* RPCIO_DEFAULT_ID picks default */ |
---|
164 | u_long gid, /* RPCIO_DEFAULT_ID picks default */ |
---|
165 | struct timeval *timeout /* NULL picks default */ |
---|
166 | ); |
---|
167 | |
---|
168 | |
---|
169 | /* manage pools of transactions */ |
---|
170 | |
---|
171 | /* A pool of transactions. The idea is not to malloc/free them |
---|
172 | * all the time but keep a limited number around in a 'pool'. |
---|
173 | * Users who need a XACT may get it from the pool and put it back |
---|
174 | * when done. |
---|
175 | * The pool is implemented by RTEMS message queues who manage |
---|
176 | * the required task synchronization. |
---|
177 | * A requestor has different options if the pool is empty: |
---|
178 | * - it can wait (block) for a XACT to become available |
---|
179 | * - it can get an error status |
---|
180 | * - or it can malloc an extra XACT from the heap which |
---|
181 | * will eventually be released. |
---|
182 | */ |
---|
183 | |
---|
184 | typedef struct RpcUdpXactPoolRec_ *RpcUdpXactPool; |
---|
185 | |
---|
186 | /* NOTE: the pool is empty initially, must get messages (in |
---|
187 | * GetCreate mode |
---|
188 | */ |
---|
189 | RpcUdpXactPool |
---|
190 | rpcUdpXactPoolCreate( |
---|
191 | int prog, int version, |
---|
192 | int xactsize, int poolsize); |
---|
193 | |
---|
194 | void |
---|
195 | rpcUdpXactPoolDestroy(RpcUdpXactPool pool); |
---|
196 | |
---|
197 | typedef enum { |
---|
198 | XactGetFail, /* call fails if no transaction available */ |
---|
199 | XactGetWait, /* call blocks until transaction available */ |
---|
200 | XactGetCreate /* a new transaction is allocated (and freed when put back to the pool */ |
---|
201 | } XactPoolGetMode; |
---|
202 | |
---|
203 | RpcUdpXact |
---|
204 | rpcUdpXactPoolGet(RpcUdpXactPool pool, XactPoolGetMode mode); |
---|
205 | |
---|
206 | void |
---|
207 | rpcUdpXactPoolPut(RpcUdpXact xact); |
---|
208 | |
---|
209 | #endif |
---|