1 /* $NetBSD: clnt_dg.c,v 1.22 2008/04/25 17:44:44 christos Exp $ */
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
35 /* #ident "@(#)clnt_dg.c 1.23 94/04/22 SMI" */
37 #include <sys/cdefs.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
40 static char sccsid
[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro";
42 __RCSID("$NetBSD: clnt_dg.c,v 1.22 2008/04/25 17:44:44 christos Exp $");
47 * Implements a connectionless client side RPC.
50 #include "namespace.h"
51 #include "reentrant.h"
53 #include <sys/types.h>
55 #include <sys/socket.h>
56 #include <sys/ioctl.h>
65 #include "rpc_internal.h"
68 __weak_alias(clnt_dg_create
,_clnt_dg_create
)
71 #define RPC_MAX_BACKOFF 30 /* seconds */
74 static struct clnt_ops
*clnt_dg_ops
__P((void));
75 static bool_t time_not_ok
__P((struct timeval
*));
76 static enum clnt_stat clnt_dg_call
__P((CLIENT
*, rpcproc_t
, xdrproc_t
,
77 const char *, xdrproc_t
, caddr_t
, struct timeval
));
78 static void clnt_dg_geterr
__P((CLIENT
*, struct rpc_err
*));
79 static bool_t clnt_dg_freeres
__P((CLIENT
*, xdrproc_t
, caddr_t
));
80 static void clnt_dg_abort
__P((CLIENT
*));
81 static bool_t clnt_dg_control
__P((CLIENT
*, u_int
, char *));
82 static void clnt_dg_destroy
__P((CLIENT
*));
88 * This machinery implements per-fd locks for MT-safety. It is not
89 * sufficient to do per-CLIENT handle locks for MT-safety because a
90 * user may create more than one CLIENT handle with the same fd behind
91 * it. Therfore, we allocate an array of flags (dg_fd_locks), protected
92 * by the clnt_fd_lock mutex, and an array (dg_cv) of condition variables
93 * similarly protected. Dg_fd_lock[fd] == 1 => a call is activte on some
94 * CLIENT handle created for that fd.
95 * The current implementation holds locks across the entire RPC and reply,
96 * including retransmissions. Yes, this is silly, and as soon as this
97 * code is proven to work, this should be the first thing fixed. One step
100 static int *dg_fd_locks
;
102 extern int __isthreaded
;
103 #define __rpc_lock_value __isthreaded;
104 extern mutex_t clnt_fd_lock
;
105 static cond_t
*dg_cv
;
106 #define release_fd_lock(fd, mask) { \
107 mutex_lock(&clnt_fd_lock); \
108 dg_fd_locks[fd] = 0; \
109 mutex_unlock(&clnt_fd_lock); \
110 thr_sigsetmask(SIG_SETMASK, &(mask), NULL); \
111 cond_signal(&dg_cv[fd]); \
114 #define release_fd_lock(fd,mask)
115 #define __rpc_lock_value 0
118 static const char mem_err_clnt_dg
[] = "clnt_dg_create: out of memory";
120 /* VARIABLES PROTECTED BY clnt_fd_lock: dg_fd_locks, dg_cv */
123 * Private data kept per client handle
126 int cu_fd
; /* connections fd */
127 bool_t cu_closeit
; /* opened by library */
128 struct sockaddr_storage cu_raddr
; /* remote address */
130 struct timeval cu_wait
; /* retransmit interval */
131 struct timeval cu_total
; /* total time for the call */
132 struct rpc_err cu_error
;
135 u_int cu_sendsz
; /* send size */
137 u_int cu_recvsz
; /* recv size */
138 struct pollfd cu_pfdp
;
143 * Connection less client creation returns with client handle parameters.
144 * Default options are set, which the user can change using clnt_control().
145 * fd should be open and bound.
146 * NB: The rpch->cl_auth is initialized to null authentication.
147 * Caller may wish to set this something more useful.
149 * sendsz and recvsz are the maximum allowable packet sizes that can be
150 * sent and received. Normally they are the same, but they can be
151 * changed to improve the program efficiency and buffer allocation.
152 * If they are 0, use the transport default.
154 * If svcaddr is NULL, returns NULL.
157 clnt_dg_create(fd
, svcaddr
, program
, version
, sendsz
, recvsz
)
158 int fd
; /* open file descriptor */
159 const struct netbuf
*svcaddr
; /* servers address */
160 rpcprog_t program
; /* program number */
161 rpcvers_t version
; /* version number */
162 u_int sendsz
; /* buffer recv size */
163 u_int recvsz
; /* buffer send size */
165 CLIENT
*cl
= NULL
; /* client handle */
166 struct cu_data
*cu
= NULL
; /* private data */
167 struct rpc_msg call_msg
;
172 struct __rpc_sockinfo si
;
175 sigfillset(&newmask
);
176 thr_sigsetmask(SIG_SETMASK
, &newmask
, &mask
);
177 mutex_lock(&clnt_fd_lock
);
178 if (dg_fd_locks
== NULL
) {
183 int dtbsize
= __rpc_dtbsize();
185 fd_allocsz
= dtbsize
* sizeof (int);
186 dg_fd_locks
= mem_alloc(fd_allocsz
);
187 if (dg_fd_locks
== NULL
) {
188 mutex_unlock(&clnt_fd_lock
);
189 thr_sigsetmask(SIG_SETMASK
, &(mask
), NULL
);
192 memset(dg_fd_locks
, '\0', fd_allocsz
);
195 cv_allocsz
= dtbsize
* sizeof (cond_t
);
196 dg_cv
= mem_alloc(cv_allocsz
);
198 mem_free(dg_fd_locks
, fd_allocsz
);
200 mutex_unlock(&clnt_fd_lock
);
201 thr_sigsetmask(SIG_SETMASK
, &(mask
), NULL
);
206 for (i
= 0; i
< dtbsize
; i
++)
207 cond_init(&dg_cv
[i
], 0, (void *) 0);
212 mutex_unlock(&clnt_fd_lock
);
213 thr_sigsetmask(SIG_SETMASK
, &(mask
), NULL
);
215 if (svcaddr
== NULL
) {
216 rpc_createerr
.cf_stat
= RPC_UNKNOWNADDR
;
220 if (!__rpc_fd2sockinfo(fd
, &si
)) {
221 rpc_createerr
.cf_stat
= RPC_TLIERROR
;
222 rpc_createerr
.cf_error
.re_errno
= 0;
226 * Find the receive and the send size
228 sendsz
= __rpc_get_t_size(si
.si_af
, si
.si_proto
, (int)sendsz
);
229 recvsz
= __rpc_get_t_size(si
.si_af
, si
.si_proto
, (int)recvsz
);
230 if ((sendsz
== 0) || (recvsz
== 0)) {
231 rpc_createerr
.cf_stat
= RPC_TLIERROR
; /* XXX */
232 rpc_createerr
.cf_error
.re_errno
= 0;
236 if ((cl
= mem_alloc(sizeof (CLIENT
))) == NULL
)
239 * Should be multiple of 4 for XDR.
241 sendsz
= ((sendsz
+ 3) / 4) * 4;
242 recvsz
= ((recvsz
+ 3) / 4) * 4;
243 cu
= malloc(sizeof (*cu
) + sendsz
+ recvsz
);
246 memset(cu
, 0, sizeof(*cu
));
247 (void) memcpy(&cu
->cu_raddr
, svcaddr
->buf
, (size_t)svcaddr
->len
);
248 cu
->cu_rlen
= svcaddr
->len
;
249 cu
->cu_outbuf
= &cu
->cu_inbuf
[recvsz
];
250 /* Other values can also be set through clnt_control() */
251 cu
->cu_wait
.tv_sec
= 15; /* heuristically chosen */
252 cu
->cu_wait
.tv_usec
= 0;
253 cu
->cu_total
.tv_sec
= -1;
254 cu
->cu_total
.tv_usec
= -1;
255 cu
->cu_sendsz
= sendsz
;
256 cu
->cu_recvsz
= recvsz
;
257 call_msg
.rm_xid
= __RPC_GETXID();
258 call_msg
.rm_call
.cb_prog
= program
;
259 call_msg
.rm_call
.cb_vers
= version
;
260 xdrmem_create(&(cu
->cu_outxdrs
), cu
->cu_outbuf
, sendsz
, XDR_ENCODE
);
261 if (! xdr_callhdr(&(cu
->cu_outxdrs
), &call_msg
)) {
262 rpc_createerr
.cf_stat
= RPC_CANTENCODEARGS
; /* XXX */
263 rpc_createerr
.cf_error
.re_errno
= 0;
266 cu
->cu_xdrpos
= XDR_GETPOS(&(cu
->cu_outxdrs
));
268 /* XXX fvdl - do we still want this? */
270 (void)bindresvport_sa(fd
, (struct sockaddr
*)svcaddr
->buf
);
272 ioctl(fd
, FIONBIO
, (char *)(void *)&one
);
275 * By default, closeit is always FALSE. It is users responsibility
276 * to do a close on it, else the user may use clnt_control
277 * to let clnt_destroy do it for him/her.
279 cu
->cu_closeit
= FALSE
;
281 cu
->cu_pfdp
.fd
= cu
->cu_fd
;
282 cu
->cu_pfdp
.events
= POLLIN
| POLLPRI
| POLLRDNORM
| POLLRDBAND
;
283 cl
->cl_ops
= clnt_dg_ops();
284 cl
->cl_private
= (caddr_t
)(void *)cu
;
285 cl
->cl_auth
= authnone_create();
290 warnx(mem_err_clnt_dg
);
291 rpc_createerr
.cf_stat
= RPC_SYSTEMERROR
;
292 rpc_createerr
.cf_error
.re_errno
= errno
;
295 mem_free(cl
, sizeof (CLIENT
));
297 mem_free(cu
, sizeof (*cu
) + sendsz
+ recvsz
);
302 static enum clnt_stat
303 clnt_dg_call(cl
, proc
, xargs
, argsp
, xresults
, resultsp
, utimeout
)
304 CLIENT
*cl
; /* client handle */
305 rpcproc_t proc
; /* procedure number */
306 xdrproc_t xargs
; /* xdr routine for args */
307 const char * argsp
; /* pointer to args */
308 xdrproc_t xresults
; /* xdr routine for results */
309 caddr_t resultsp
; /* pointer to results */
310 struct timeval utimeout
; /* seconds to wait before giving up */
315 struct rpc_msg reply_msg
;
318 int nrefreshes
= 2; /* number of times to refresh cred */
319 struct timeval timeout
;
320 struct timeval retransmit_time
;
321 struct timeval next_sendtime
, starttime
, time_waited
, tv
;
323 sigset_t mask
, *maskp
= &mask
;
325 sigset_t
*maskp
= NULL
;
332 _DIAGASSERT(cl
!= NULL
);
334 cu
= (struct cu_data
*)cl
->cl_private
;
336 sigfillset(&newmask
);
337 thr_sigsetmask(SIG_SETMASK
, &newmask
, &mask
);
338 mutex_lock(&clnt_fd_lock
);
339 while (dg_fd_locks
[cu
->cu_fd
])
340 cond_wait(&dg_cv
[cu
->cu_fd
], &clnt_fd_lock
);
341 dg_fd_locks
[cu
->cu_fd
] = __rpc_lock_value
;
342 mutex_unlock(&clnt_fd_lock
);
343 if (cu
->cu_total
.tv_usec
== -1) {
344 timeout
= utimeout
; /* use supplied timeout */
346 timeout
= cu
->cu_total
; /* use default timeout */
349 time_waited
.tv_sec
= 0;
350 time_waited
.tv_usec
= 0;
351 retransmit_time
= next_sendtime
= cu
->cu_wait
;
352 gettimeofday(&starttime
, NULL
);
355 xdrs
= &(cu
->cu_outxdrs
);
356 xdrs
->x_op
= XDR_ENCODE
;
357 XDR_SETPOS(xdrs
, cu
->cu_xdrpos
);
359 * the transaction is the first thing in the out buffer
361 (*(u_int32_t
*)(void *)(cu
->cu_outbuf
))++;
362 if ((! XDR_PUTINT32(xdrs
, (int32_t *)&proc
)) ||
363 (! AUTH_MARSHALL(cl
->cl_auth
, xdrs
)) ||
364 (! (*xargs
)(xdrs
, __UNCONST(argsp
)))) {
365 cu
->cu_error
.re_status
= RPC_CANTENCODEARGS
;
368 outlen
= (size_t)XDR_GETPOS(xdrs
);
371 if ((size_t)sendto(cu
->cu_fd
, cu
->cu_outbuf
, outlen
, 0,
372 (struct sockaddr
*)(void *)&cu
->cu_raddr
, (socklen_t
)cu
->cu_rlen
)
374 cu
->cu_error
.re_errno
= errno
;
375 cu
->cu_error
.re_status
= RPC_CANTSEND
;
380 * Hack to provide rpc-based message passing
382 if (timeout
.tv_sec
== 0 && timeout
.tv_usec
== 0) {
383 cu
->cu_error
.re_status
= RPC_TIMEDOUT
;
387 * sub-optimal code appears here because we have
388 * some clock time to spare while the packets are in flight.
389 * (We assume that this is actually only executed once.)
391 reply_msg
.acpted_rply
.ar_verf
= _null_auth
;
392 reply_msg
.acpted_rply
.ar_results
.where
= resultsp
;
393 reply_msg
.acpted_rply
.ar_results
.proc
= xresults
;
397 /* Decide how long to wait. */
398 if (timercmp(&next_sendtime
, &timeout
, <))
399 timersub(&next_sendtime
, &time_waited
, &tv
);
401 timersub(&timeout
, &time_waited
, &tv
);
402 if (tv
.tv_sec
< 0 || tv
.tv_usec
< 0)
403 tv
.tv_sec
= tv
.tv_usec
= 0;
404 TIMEVAL_TO_TIMESPEC(&tv
, &ts
);
406 n
= pollts(&cu
->cu_pfdp
, 1, &ts
, maskp
);
408 /* We have some data now */
410 recvlen
= recvfrom(cu
->cu_fd
, cu
->cu_inbuf
,
411 cu
->cu_recvsz
, 0, NULL
, NULL
);
412 } while (recvlen
< 0 && errno
== EINTR
);
414 if (recvlen
< 0 && errno
!= EWOULDBLOCK
) {
415 cu
->cu_error
.re_errno
= errno
;
416 cu
->cu_error
.re_status
= RPC_CANTRECV
;
419 if (recvlen
>= (ssize_t
)sizeof(uint32_t) &&
420 (*((uint32_t *)(void *)(cu
->cu_inbuf
)) ==
421 *((uint32_t *)(void *)(cu
->cu_outbuf
)))) {
422 /* We now assume we have the proper reply. */
427 cu
->cu_error
.re_errno
= errno
;
428 cu
->cu_error
.re_status
= RPC_CANTRECV
;
432 gettimeofday(&tv
, NULL
);
433 timersub(&tv
, &starttime
, &time_waited
);
435 /* Check for timeout. */
436 if (timercmp(&time_waited
, &timeout
, >)) {
437 cu
->cu_error
.re_status
= RPC_TIMEDOUT
;
441 /* Retransmit if necessary. */
442 if (timercmp(&time_waited
, &next_sendtime
, >)) {
443 /* update retransmit_time */
444 if (retransmit_time
.tv_sec
< RPC_MAX_BACKOFF
)
445 timeradd(&retransmit_time
, &retransmit_time
,
447 timeradd(&next_sendtime
, &retransmit_time
,
454 * now decode and validate the response
457 xdrmem_create(&reply_xdrs
, cu
->cu_inbuf
, (u_int
)recvlen
, XDR_DECODE
);
458 ok
= xdr_replymsg(&reply_xdrs
, &reply_msg
);
459 /* XDR_DESTROY(&reply_xdrs); save a few cycles on noop destroy */
461 if ((reply_msg
.rm_reply
.rp_stat
== MSG_ACCEPTED
) &&
462 (reply_msg
.acpted_rply
.ar_stat
== SUCCESS
))
463 cu
->cu_error
.re_status
= RPC_SUCCESS
;
465 _seterr_reply(&reply_msg
, &(cu
->cu_error
));
467 if (cu
->cu_error
.re_status
== RPC_SUCCESS
) {
468 if (! AUTH_VALIDATE(cl
->cl_auth
,
469 &reply_msg
.acpted_rply
.ar_verf
)) {
470 cu
->cu_error
.re_status
= RPC_AUTHERROR
;
471 cu
->cu_error
.re_why
= AUTH_INVALIDRESP
;
473 if (reply_msg
.acpted_rply
.ar_verf
.oa_base
!= NULL
) {
474 xdrs
->x_op
= XDR_FREE
;
475 (void) xdr_opaque_auth(xdrs
,
476 &(reply_msg
.acpted_rply
.ar_verf
));
478 } /* end successful completion */
480 * If unsuccesful AND error is an authentication error
481 * then refresh credentials and try again, else break
483 else if (cu
->cu_error
.re_status
== RPC_AUTHERROR
)
484 /* maybe our credentials need to be refreshed ... */
485 if (nrefreshes
> 0 && AUTH_REFRESH(cl
->cl_auth
)) {
489 /* end of unsuccessful completion */
490 } /* end of valid reply message */
492 cu
->cu_error
.re_status
= RPC_CANTDECODERES
;
496 release_fd_lock(cu
->cu_fd
, mask
);
497 return (cu
->cu_error
.re_status
);
501 clnt_dg_geterr(cl
, errp
)
503 struct rpc_err
*errp
;
507 _DIAGASSERT(cl
!= NULL
);
508 _DIAGASSERT(errp
!= NULL
);
510 cu
= (struct cu_data
*)cl
->cl_private
;
511 *errp
= cu
->cu_error
;
515 clnt_dg_freeres(cl
, xdr_res
, res_ptr
)
528 _DIAGASSERT(cl
!= NULL
);
529 cu
= (struct cu_data
*)cl
->cl_private
;
530 xdrs
= &(cu
->cu_outxdrs
);
532 sigfillset(&newmask
);
533 thr_sigsetmask(SIG_SETMASK
, &newmask
, &mask
);
534 mutex_lock(&clnt_fd_lock
);
535 while (dg_fd_locks
[cu
->cu_fd
])
536 cond_wait(&dg_cv
[cu
->cu_fd
], &clnt_fd_lock
);
537 xdrs
->x_op
= XDR_FREE
;
538 dummy
= (*xdr_res
)(xdrs
, res_ptr
);
539 mutex_unlock(&clnt_fd_lock
);
540 thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
541 cond_signal(&dg_cv
[cu
->cu_fd
]);
553 clnt_dg_control(cl
, request
, info
)
565 _DIAGASSERT(cl
!= NULL
);
566 /* info is handled below */
568 cu
= (struct cu_data
*)cl
->cl_private
;
570 sigfillset(&newmask
);
571 thr_sigsetmask(SIG_SETMASK
, &newmask
, &mask
);
572 mutex_lock(&clnt_fd_lock
);
573 while (dg_fd_locks
[cu
->cu_fd
])
574 cond_wait(&dg_cv
[cu
->cu_fd
], &clnt_fd_lock
);
575 dg_fd_locks
[cu
->cu_fd
] = __rpc_lock_value
;
576 mutex_unlock(&clnt_fd_lock
);
579 cu
->cu_closeit
= TRUE
;
580 release_fd_lock(cu
->cu_fd
, mask
);
582 case CLSET_FD_NCLOSE
:
583 cu
->cu_closeit
= FALSE
;
584 release_fd_lock(cu
->cu_fd
, mask
);
588 /* for other requests which use info */
590 release_fd_lock(cu
->cu_fd
, mask
);
595 if (time_not_ok((struct timeval
*)(void *)info
)) {
596 release_fd_lock(cu
->cu_fd
, mask
);
599 cu
->cu_total
= *(struct timeval
*)(void *)info
;
602 *(struct timeval
*)(void *)info
= cu
->cu_total
;
604 case CLGET_SERVER_ADDR
: /* Give him the fd address */
605 /* Now obsolete. Only for backward compatibility */
606 (void) memcpy(info
, &cu
->cu_raddr
, (size_t)cu
->cu_rlen
);
608 case CLSET_RETRY_TIMEOUT
:
609 if (time_not_ok((struct timeval
*)(void *)info
)) {
610 release_fd_lock(cu
->cu_fd
, mask
);
613 cu
->cu_wait
= *(struct timeval
*)(void *)info
;
615 case CLGET_RETRY_TIMEOUT
:
616 *(struct timeval
*)(void *)info
= cu
->cu_wait
;
619 *(int *)(void *)info
= cu
->cu_fd
;
622 addr
= (struct netbuf
*)(void *)info
;
623 addr
->buf
= &cu
->cu_raddr
;
624 addr
->len
= cu
->cu_rlen
;
625 addr
->maxlen
= sizeof cu
->cu_raddr
;
627 case CLSET_SVC_ADDR
: /* set to new address */
628 addr
= (struct netbuf
*)(void *)info
;
629 if (addr
->len
< sizeof cu
->cu_raddr
) {
630 release_fd_lock(cu
->cu_fd
, mask
);
633 (void) memcpy(&cu
->cu_raddr
, addr
->buf
, (size_t)addr
->len
);
634 cu
->cu_rlen
= addr
->len
;
638 * use the knowledge that xid is the
639 * first element in the call structure *.
640 * This will get the xid of the PREVIOUS call
642 *(u_int32_t
*)(void *)info
=
643 ntohl(*(u_int32_t
*)(void *)cu
->cu_outbuf
);
647 /* This will set the xid of the NEXT call */
648 *(u_int32_t
*)(void *)cu
->cu_outbuf
=
649 htonl(*(u_int32_t
*)(void *)info
- 1);
650 /* decrement by 1 as clnt_dg_call() increments once */
655 * This RELIES on the information that, in the call body,
656 * the version number field is the fifth field from the
657 * begining of the RPC header. MUST be changed if the
658 * call_struct is changed
660 *(u_int32_t
*)(void *)info
=
661 ntohl(*(u_int32_t
*)(void *)(cu
->cu_outbuf
+
662 4 * BYTES_PER_XDR_UNIT
));
666 *(u_int32_t
*)(void *)(cu
->cu_outbuf
+ 4 * BYTES_PER_XDR_UNIT
)
667 = htonl(*(u_int32_t
*)(void *)info
);
672 * This RELIES on the information that, in the call body,
673 * the program number field is the fourth field from the
674 * begining of the RPC header. MUST be changed if the
675 * call_struct is changed
677 *(u_int32_t
*)(void *)info
=
678 ntohl(*(u_int32_t
*)(void *)(cu
->cu_outbuf
+
679 3 * BYTES_PER_XDR_UNIT
));
683 *(u_int32_t
*)(void *)(cu
->cu_outbuf
+ 3 * BYTES_PER_XDR_UNIT
)
684 = htonl(*(u_int32_t
*)(void *)info
);
688 release_fd_lock(cu
->cu_fd
, mask
);
691 release_fd_lock(cu
->cu_fd
, mask
);
706 _DIAGASSERT(cl
!= NULL
);
708 cu
= (struct cu_data
*)cl
->cl_private
;
711 sigfillset(&newmask
);
712 thr_sigsetmask(SIG_SETMASK
, &newmask
, &mask
);
713 mutex_lock(&clnt_fd_lock
);
714 while (dg_fd_locks
[cu_fd
])
715 cond_wait(&dg_cv
[cu_fd
], &clnt_fd_lock
);
718 XDR_DESTROY(&(cu
->cu_outxdrs
));
719 mem_free(cu
, (sizeof (*cu
) + cu
->cu_sendsz
+ cu
->cu_recvsz
));
720 if (cl
->cl_netid
&& cl
->cl_netid
[0])
721 mem_free(cl
->cl_netid
, strlen(cl
->cl_netid
) +1);
722 if (cl
->cl_tp
&& cl
->cl_tp
[0])
723 mem_free(cl
->cl_tp
, strlen(cl
->cl_tp
) +1);
724 mem_free(cl
, sizeof (CLIENT
));
725 mutex_unlock(&clnt_fd_lock
);
726 thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
727 cond_signal(&dg_cv
[cu_fd
]);
730 static struct clnt_ops
*
733 static struct clnt_ops ops
;
735 extern mutex_t ops_lock
;
740 /* VARIABLES PROTECTED BY ops_lock: ops */
742 sigfillset(&newmask
);
743 thr_sigsetmask(SIG_SETMASK
, &newmask
, &mask
);
744 mutex_lock(&ops_lock
);
745 if (ops
.cl_call
== NULL
) {
746 ops
.cl_call
= clnt_dg_call
;
747 ops
.cl_abort
= clnt_dg_abort
;
748 ops
.cl_geterr
= clnt_dg_geterr
;
749 ops
.cl_freeres
= clnt_dg_freeres
;
750 ops
.cl_destroy
= clnt_dg_destroy
;
751 ops
.cl_control
= clnt_dg_control
;
753 mutex_unlock(&ops_lock
);
754 thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
759 * Make sure that the time is not garbage. -1 value is allowed.
766 _DIAGASSERT(t
!= NULL
);
768 return (t
->tv_sec
< -1 || t
->tv_sec
> 100000000 ||
769 t
->tv_usec
< -1 || t
->tv_usec
> 1000000);