rx-flag-all-packets-20080925
[openafs.git] / src / rx / rx_rdwr.c
1  /*
2   * Copyright 2000, International Business Machines Corporation and others.
3   * All Rights Reserved.
4   * 
5   * This software has been released under the terms of the IBM Public
6   * License.  For details, see the LICENSE file in the top-level source
7   * directory or online at http://www.openafs.org/dl/license10.html
8   */
9
10 #include <afsconfig.h>
11 #ifdef KERNEL
12 #include "afs/param.h"
13 #else
14 #include <afs/param.h>
15 #endif
16
17 RCSID
18     ("$Header$");
19
20 #ifdef KERNEL
21 #ifndef UKERNEL
22 #ifdef RX_KERNEL_TRACE
23 #include "rx_kcommon.h"
24 #endif
25 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
26 #include "afs/sysincludes.h"
27 #else
28 #include "h/types.h"
29 #include "h/time.h"
30 #include "h/stat.h"
31 #if defined(AFS_AIX_ENV) || defined(AFS_AUX_ENV) || defined(AFS_SUN5_ENV) 
32 #include "h/systm.h"
33 #endif
34 #ifdef  AFS_OSF_ENV
35 #include <net/net_globals.h>
36 #endif /* AFS_OSF_ENV */
37 #ifdef AFS_LINUX20_ENV
38 #include "h/socket.h"
39 #endif
40 #include "netinet/in.h"
41 #if defined(AFS_SGI_ENV)
42 #include "afs/sysincludes.h"
43 #endif
44 #endif
45 #include "afs/afs_args.h"
46 #include "afs/afs_osi.h"
47 #if     (defined(AFS_AUX_ENV) || defined(AFS_AIX_ENV))
48 #include "h/systm.h"
49 #endif
50 #else /* !UKERNEL */
51 #include "afs/sysincludes.h"
52 #endif /* !UKERNEL */
53 #ifdef RXDEBUG
54 #undef RXDEBUG                  /* turn off debugging */
55 #endif /* RXDEBUG */
56
57 #include "rx_kmutex.h"
58 #include "rx/rx_kernel.h"
59 #include "rx/rx_clock.h"
60 #include "rx/rx_queue.h"
61 #include "rx/rx.h"
62 #include "rx/rx_globals.h"
63 #include "afs/lock.h"
64 #include "afsint.h"
65 #ifdef  AFS_OSF_ENV
66 #undef kmem_alloc
67 #undef kmem_free
68 #undef mem_alloc
69 #undef mem_free
70 #undef register
71 #endif /* AFS_OSF_ENV */
72 #else /* KERNEL */
73 # include <sys/types.h>
74 #ifdef AFS_NT40_ENV
75 # include <winsock2.h>
76 #else /* !AFS_NT40_ENV */
77 # include <sys/socket.h>
78 # include <sys/file.h>
79 # include <netdb.h>
80 # include <netinet/in.h>
81 # include <sys/stat.h>
82 # include <sys/time.h>
83 #endif /* !AFS_NT40_ENV */
84 #include <string.h>
85 #ifdef HAVE_UNISTD_H
86 #include <unistd.h>
87 #endif
88 # include "rx_user.h"
89 # include "rx_clock.h"
90 # include "rx_queue.h"
91 # include "rx.h"
92 # include "rx_globals.h"
93 #endif /* KERNEL */
94
95 #ifdef RX_LOCKS_DB
96 /* rxdb_fileID is used to identify the lock location, along with line#. */
97 static int rxdb_fileID = RXDB_FILE_RX_RDWR;
98 #endif /* RX_LOCKS_DB */
99 /* rxi_ReadProc -- internal version.
100  *
101  * LOCKS USED -- called at netpri with rx global lock and call->lock held.
102  */
103 int
104 rxi_ReadProc(register struct rx_call *call, register char *buf,
105              register int nbytes)
106 {
107     register struct rx_packet *cp = call->currentPacket;
108     register struct rx_packet *rp;
109     register int requestCount;
110     register unsigned int t;
111
112 /* XXXX took out clock_NewTime from here.  Was it needed? */
113     requestCount = nbytes;
114
115     /* Free any packets from the last call to ReadvProc/WritevProc */
116     if (queue_IsNotEmpty(&call->iovq)) {
117         rxi_FreePackets(0, &call->iovq);
118     }
119
120     do {
121         if (call->nLeft == 0) {
122             /* Get next packet */
123             for (;;) {
124                 if (call->error || (call->mode != RX_MODE_RECEIVING)) {
125                     if (call->error) {
126                         return 0;
127                     }
128                     if (call->mode == RX_MODE_SENDING) {
129                         rxi_FlushWrite(call);
130                         continue;
131                     }
132                 }
133                 if (queue_IsNotEmpty(&call->rq)) {
134                     /* Check that next packet available is next in sequence */
135                     rp = queue_First(&call->rq, rx_packet);
136                     if (rp->header.seq == call->rnext) {
137                         afs_int32 error;
138                         register struct rx_connection *conn = call->conn;
139                         queue_Remove(rp);
140                         rp->flags &= ~RX_PKTFLAG_RQ;
141
142                         /* RXS_CheckPacket called to undo RXS_PreparePacket's
143                          * work.  It may reduce the length of the packet by up
144                          * to conn->maxTrailerSize, to reflect the length of the
145                          * data + the header. */
146                         if ((error =
147                              RXS_CheckPacket(conn->securityObject, call,
148                                              rp))) {
149                             /* Used to merely shut down the call, but now we 
150                              * shut down the whole connection since this may 
151                              * indicate an attempt to hijack it */
152
153                             MUTEX_EXIT(&call->lock);
154                             rxi_ConnectionError(conn, error);
155                             MUTEX_ENTER(&conn->conn_data_lock);
156                             rp = rxi_SendConnectionAbort(conn, rp, 0, 0);
157                             MUTEX_EXIT(&conn->conn_data_lock);
158                             rxi_FreePacket(rp);
159                             MUTEX_ENTER(&call->lock);
160
161                             return 0;
162                         }
163                         call->rnext++;
164                         cp = call->currentPacket = rp;
165                         call->currentPacket->flags |= RX_PKTFLAG_CP;
166                         call->curvec = 1;       /* 0th vec is always header */
167                         /* begin at the beginning [ more or less ], continue 
168                          * on until the end, then stop. */
169                         call->curpos =
170                             (char *)cp->wirevec[1].iov_base +
171                             call->conn->securityHeaderSize;
172                         call->curlen =
173                             cp->wirevec[1].iov_len -
174                             call->conn->securityHeaderSize;
175
176                         /* Notice that this code works correctly if the data
177                          * size is 0 (which it may be--no reply arguments from
178                          * server, for example).  This relies heavily on the
179                          * fact that the code below immediately frees the packet
180                          * (no yields, etc.).  If it didn't, this would be a
181                          * problem because a value of zero for call->nLeft
182                          * normally means that there is no read packet */
183                         call->nLeft = cp->length;
184                         hadd32(call->bytesRcvd, cp->length);
185
186                         /* Send a hard ack for every rxi_HardAckRate+1 packets
187                          * consumed. Otherwise schedule an event to send
188                          * the hard ack later on.
189                          */
190                         call->nHardAcks++;
191                         if (!(call->flags & RX_CALL_RECEIVE_DONE)) {
192                             if (call->nHardAcks > (u_short) rxi_HardAckRate) {
193                                 rxevent_Cancel(call->delayedAckEvent, call,
194                                                RX_CALL_REFCOUNT_DELAY);
195                                 rxi_SendAck(call, 0, 0, RX_ACK_DELAY, 0);
196                             } else {
197                                 struct clock when, now;
198                                 clock_GetTime(&now);
199                                 when = now;
200                                 /* Delay to consolidate ack packets */
201                                 clock_Add(&when, &rx_hardAckDelay);
202                                 if (!call->delayedAckEvent
203                                     || clock_Gt(&call->delayedAckEvent->
204                                                 eventTime, &when)) {
205                                     rxevent_Cancel(call->delayedAckEvent,
206                                                    call,
207                                                    RX_CALL_REFCOUNT_DELAY);
208                                     CALL_HOLD(call, RX_CALL_REFCOUNT_DELAY);
209                                     call->delayedAckEvent =
210                                       rxevent_PostNow(&when, &now,
211                                                      rxi_SendDelayedAck, call,
212                                                      0);
213                                 }
214                             }
215                         }
216                         break;
217                     }
218                 }
219
220 /*
221 MTUXXX  doesn't there need to be an "else" here ??? 
222 */
223                 /* Are there ever going to be any more packets? */
224                 if (call->flags & RX_CALL_RECEIVE_DONE) {
225                     return requestCount - nbytes;
226                 }
227                 /* Wait for in-sequence packet */
228                 call->flags |= RX_CALL_READER_WAIT;
229                 clock_NewTime();
230                 call->startWait = clock_Sec();
231                 while (call->flags & RX_CALL_READER_WAIT) {
232 #ifdef  RX_ENABLE_LOCKS
233                     CV_WAIT(&call->cv_rq, &call->lock);
234 #else
235                     osi_rxSleep(&call->rq);
236 #endif
237                 }
238
239                 call->startWait = 0;
240 #ifdef RX_ENABLE_LOCKS
241                 if (call->error) {
242                     return 0;
243                 }
244 #endif /* RX_ENABLE_LOCKS */
245             }
246         } else
247             /* assert(cp); */
248             /* MTUXXX  this should be replaced by some error-recovery code before shipping */
249             /* yes, the following block is allowed to be the ELSE clause (or not) */
250             /* It's possible for call->nLeft to be smaller than any particular
251              * iov_len.  Usually, recvmsg doesn't change the iov_len, since it
252              * reflects the size of the buffer.  We have to keep track of the
253              * number of bytes read in the length field of the packet struct.  On
254              * the final portion of a received packet, it's almost certain that
255              * call->nLeft will be smaller than the final buffer. */
256             while (nbytes && cp) {
257                 t = MIN((int)call->curlen, nbytes);
258                 t = MIN(t, (int)call->nLeft);
259                 memcpy(buf, call->curpos, t);
260                 buf += t;
261                 nbytes -= t;
262                 call->curpos += t;
263                 call->curlen -= t;
264                 call->nLeft -= t;
265
266                 if (!call->nLeft) {
267                     /* out of packet.  Get another one. */
268                     call->currentPacket->flags &= ~RX_PKTFLAG_CP;
269                     rxi_FreePacket(cp);
270                     cp = call->currentPacket = (struct rx_packet *)0;
271                 } else if (!call->curlen) {
272                     /* need to get another struct iov */
273                     if (++call->curvec >= cp->niovecs) {
274                         /* current packet is exhausted, get ready for another */
275                         /* don't worry about curvec and stuff, they get set somewhere else */
276                         call->currentPacket->flags &= ~RX_PKTFLAG_CP;
277                         rxi_FreePacket(cp);
278                         cp = call->currentPacket = (struct rx_packet *)0;
279                         call->nLeft = 0;
280                     } else {
281                         call->curpos =
282                             (char *)cp->wirevec[call->curvec].iov_base;
283                         call->curlen = cp->wirevec[call->curvec].iov_len;
284                     }
285                 }
286             }
287         if (!nbytes) {
288             /* user buffer is full, return */
289             return requestCount;
290         }
291
292     } while (nbytes);
293
294     return requestCount;
295 }
296
297 int
298 rx_ReadProc(struct rx_call *call, char *buf, int nbytes)
299 {
300     int bytes;
301     int tcurlen;
302     int tnLeft;
303     char *tcurpos;
304     SPLVAR;
305
306     /*
307      * Free any packets from the last call to ReadvProc/WritevProc.
308      * We do not need the lock because the receiver threads only
309      * touch the iovq when the RX_CALL_IOVEC_WAIT flag is set, and the
310      * RX_CALL_IOVEC_WAIT is always cleared before returning from
311      * ReadvProc/WritevProc.
312      */
313     if (!queue_IsEmpty(&call->iovq)) {
314         rxi_FreePackets(0, &call->iovq);
315     }
316
317     /*
318      * Most common case, all of the data is in the current iovec.
319      * We do not need the lock because this is the only thread that
320      * updates the curlen, curpos, nLeft fields.
321      *
322      * We are relying on nLeft being zero unless the call is in receive mode.
323      */
324     tcurlen = call->curlen;
325     tnLeft = call->nLeft;
326     if (!call->error && tcurlen > nbytes && tnLeft > nbytes) {
327         tcurpos = call->curpos;
328         memcpy(buf, tcurpos, nbytes);
329         call->curpos = tcurpos + nbytes;
330         call->curlen = tcurlen - nbytes;
331         call->nLeft = tnLeft - nbytes;
332
333         if (!call->nLeft) {
334             /* out of packet.  Get another one. */
335             NETPRI;
336             MUTEX_ENTER(&call->lock);
337             rxi_FreePacket(call->currentPacket);
338             call->currentPacket = (struct rx_packet *)0;
339             MUTEX_EXIT(&call->lock);
340             USERPRI;
341         }
342         return nbytes;
343     }
344
345     NETPRI;
346     MUTEX_ENTER(&call->lock);
347     bytes = rxi_ReadProc(call, buf, nbytes);
348     MUTEX_EXIT(&call->lock);
349     USERPRI;
350     return bytes;
351 }
352
353 /* Optimization for unmarshalling 32 bit integers */
354 int
355 rx_ReadProc32(struct rx_call *call, afs_int32 * value)
356 {
357     int bytes;
358     int tcurlen;
359     int tnLeft;
360     char *tcurpos;
361     SPLVAR;
362
363     /*
364      * Free any packets from the last call to ReadvProc/WritevProc.
365      * We do not need the lock because the receiver threads only
366      * touch the iovq when the RX_CALL_IOVEC_WAIT flag is set, and the
367      * RX_CALL_IOVEC_WAIT is always cleared before returning from
368      * ReadvProc/WritevProc.
369      */
370     if (!queue_IsEmpty(&call->iovq)) {
371         rxi_FreePackets(0, &call->iovq);
372     }
373
374     /*
375      * Most common case, all of the data is in the current iovec.
376      * We do not need the lock because this is the only thread that
377      * updates the curlen, curpos, nLeft fields.
378      *
379      * We are relying on nLeft being zero unless the call is in receive mode.
380      */
381     tcurlen = call->curlen;
382     tnLeft = call->nLeft;
383     if (!call->error && tcurlen >= sizeof(afs_int32)
384         && tnLeft >= sizeof(afs_int32)) {
385         tcurpos = call->curpos;
386         memcpy((char *)value, tcurpos, sizeof(afs_int32));
387         call->curpos = tcurpos + sizeof(afs_int32);
388         call->curlen = (u_short)(tcurlen - sizeof(afs_int32));
389         call->nLeft = (u_short)(tnLeft - sizeof(afs_int32));
390         if (!call->nLeft) {
391             /* out of packet.  Get another one. */
392             NETPRI;
393             MUTEX_ENTER(&call->lock);
394             rxi_FreePacket(call->currentPacket);
395             call->currentPacket = (struct rx_packet *)0;
396             MUTEX_EXIT(&call->lock);
397             USERPRI;
398         }
399         return sizeof(afs_int32);
400     }
401
402     NETPRI;
403     MUTEX_ENTER(&call->lock);
404     bytes = rxi_ReadProc(call, (char *)value, sizeof(afs_int32));
405     MUTEX_EXIT(&call->lock);
406     USERPRI;
407     return bytes;
408 }
409
410 /* rxi_FillReadVec
411  *
412  * Uses packets in the receive queue to fill in as much of the
413  * current iovec as possible. Does not block if it runs out
414  * of packets to complete the iovec. Return true if an ack packet
415  * was sent, otherwise return false */
416 int
417 rxi_FillReadVec(struct rx_call *call, afs_uint32 serial)
418 {
419     int didConsume = 0;
420     int didHardAck = 0;
421     register unsigned int t;
422     struct rx_packet *rp;
423     struct rx_packet *curp;
424     struct iovec *call_iov;
425     struct iovec *cur_iov = NULL;
426
427     curp = call->currentPacket;
428     if (curp) {
429         cur_iov = &curp->wirevec[call->curvec];
430     }
431     call_iov = &call->iov[call->iovNext];
432
433     while (!call->error && call->iovNBytes && call->iovNext < call->iovMax) {
434         if (call->nLeft == 0) {
435             /* Get next packet */
436             if (queue_IsNotEmpty(&call->rq)) {
437                 /* Check that next packet available is next in sequence */
438                 rp = queue_First(&call->rq, rx_packet);
439                 if (rp->header.seq == call->rnext) {
440                     afs_int32 error;
441                     register struct rx_connection *conn = call->conn;
442                     queue_Remove(rp);
443                     rp->flags &= ~RX_PKTFLAG_RQ;
444
445                     /* RXS_CheckPacket called to undo RXS_PreparePacket's
446                      * work.  It may reduce the length of the packet by up
447                      * to conn->maxTrailerSize, to reflect the length of the
448                      * data + the header. */
449                     if ((error =
450                          RXS_CheckPacket(conn->securityObject, call, rp))) {
451                         /* Used to merely shut down the call, but now we 
452                          * shut down the whole connection since this may 
453                          * indicate an attempt to hijack it */
454
455                         MUTEX_EXIT(&call->lock);
456                         rxi_ConnectionError(conn, error);
457                         MUTEX_ENTER(&conn->conn_data_lock);
458                         rp = rxi_SendConnectionAbort(conn, rp, 0, 0);
459                         MUTEX_EXIT(&conn->conn_data_lock);
460                         rxi_FreePacket(rp);
461                         MUTEX_ENTER(&call->lock);
462
463                         return 1;
464                     }
465                     call->rnext++;
466                     curp = call->currentPacket = rp;
467                     call->currentPacket->flags |= RX_PKTFLAG_CP;
468                     call->curvec = 1;   /* 0th vec is always header */
469                     cur_iov = &curp->wirevec[1];
470                     /* begin at the beginning [ more or less ], continue 
471                      * on until the end, then stop. */
472                     call->curpos =
473                         (char *)curp->wirevec[1].iov_base +
474                         call->conn->securityHeaderSize;
475                     call->curlen =
476                         curp->wirevec[1].iov_len -
477                         call->conn->securityHeaderSize;
478
479                     /* Notice that this code works correctly if the data
480                      * size is 0 (which it may be--no reply arguments from
481                      * server, for example).  This relies heavily on the
482                      * fact that the code below immediately frees the packet
483                      * (no yields, etc.).  If it didn't, this would be a
484                      * problem because a value of zero for call->nLeft
485                      * normally means that there is no read packet */
486                     call->nLeft = curp->length;
487                     hadd32(call->bytesRcvd, curp->length);
488
489                     /* Send a hard ack for every rxi_HardAckRate+1 packets
490                      * consumed. Otherwise schedule an event to send
491                      * the hard ack later on.
492                      */
493                     call->nHardAcks++;
494                     didConsume = 1;
495                     continue;
496                 }
497             }
498             break;
499         }
500
501         /* It's possible for call->nLeft to be smaller than any particular
502          * iov_len.  Usually, recvmsg doesn't change the iov_len, since it
503          * reflects the size of the buffer.  We have to keep track of the
504          * number of bytes read in the length field of the packet struct.  On
505          * the final portion of a received packet, it's almost certain that
506          * call->nLeft will be smaller than the final buffer. */
507         while (call->iovNBytes && call->iovNext < call->iovMax && curp) {
508
509             t = MIN((int)call->curlen, call->iovNBytes);
510             t = MIN(t, (int)call->nLeft);
511             call_iov->iov_base = call->curpos;
512             call_iov->iov_len = t;
513             call_iov++;
514             call->iovNext++;
515             call->iovNBytes -= t;
516             call->curpos += t;
517             call->curlen -= t;
518             call->nLeft -= t;
519
520             if (!call->nLeft) {
521                 /* out of packet.  Get another one. */
522                 curp->flags &= ~RX_PKTFLAG_CP;
523                 curp->flags |= RX_PKTFLAG_IOVQ;
524                 queue_Append(&call->iovq, curp);
525                 curp = call->currentPacket = (struct rx_packet *)0;
526             } else if (!call->curlen) {
527                 /* need to get another struct iov */
528                 if (++call->curvec >= curp->niovecs) {
529                     /* current packet is exhausted, get ready for another */
530                     /* don't worry about curvec and stuff, they get set somewhere else */
531                     curp->flags &= ~RX_PKTFLAG_CP;
532                     curp->flags |= RX_PKTFLAG_IOVQ;
533                     queue_Append(&call->iovq, curp);
534                     curp = call->currentPacket = (struct rx_packet *)0;
535                     call->nLeft = 0;
536                 } else {
537                     cur_iov++;
538                     call->curpos = (char *)cur_iov->iov_base;
539                     call->curlen = cur_iov->iov_len;
540                 }
541             }
542         }
543     }
544
545     /* If we consumed any packets then check whether we need to
546      * send a hard ack. */
547     if (didConsume && (!(call->flags & RX_CALL_RECEIVE_DONE))) {
548         if (call->nHardAcks > (u_short) rxi_HardAckRate) {
549             rxevent_Cancel(call->delayedAckEvent, call,
550                            RX_CALL_REFCOUNT_DELAY);
551             rxi_SendAck(call, 0, serial, RX_ACK_DELAY, 0);
552             didHardAck = 1;
553         } else {
554             struct clock when, now;
555             clock_GetTime(&now);
556             when = now;
557             /* Delay to consolidate ack packets */
558             clock_Add(&when, &rx_hardAckDelay);
559             if (!call->delayedAckEvent
560                 || clock_Gt(&call->delayedAckEvent->eventTime, &when)) {
561                 rxevent_Cancel(call->delayedAckEvent, call,
562                                RX_CALL_REFCOUNT_DELAY);
563                 CALL_HOLD(call, RX_CALL_REFCOUNT_DELAY);
564                 call->delayedAckEvent =
565                     rxevent_PostNow(&when, &now, rxi_SendDelayedAck, call, 0);
566             }
567         }
568     }
569     return didHardAck;
570 }
571
572
573 /* rxi_ReadvProc -- internal version.
574  *
575  * Fills in an iovec with pointers to the packet buffers. All packets
576  * except the last packet (new current packet) are moved to the iovq
577  * while the application is processing the data.
578  *
579  * LOCKS USED -- called at netpri with rx global lock and call->lock held.
580  */
581 int
582 rxi_ReadvProc(struct rx_call *call, struct iovec *iov, int *nio, int maxio,
583               int nbytes)
584 {
585     int requestCount;
586     int nextio;
587
588     requestCount = nbytes;
589     nextio = 0;
590
591     /* Free any packets from the last call to ReadvProc/WritevProc */
592     if (queue_IsNotEmpty(&call->iovq)) {
593         rxi_FreePackets(0, &call->iovq);
594     }
595
596     if (call->mode == RX_MODE_SENDING) {
597         rxi_FlushWrite(call);
598     }
599
600     if (call->error) {
601         return 0;
602     }
603
604     /* Get whatever data is currently available in the receive queue.
605      * If rxi_FillReadVec sends an ack packet then it is possible
606      * that we will receive more data while we drop the call lock
607      * to send the packet. Set the RX_CALL_IOVEC_WAIT flag
608      * here to avoid a race with the receive thread if we send
609      * hard acks in rxi_FillReadVec. */
610     call->flags |= RX_CALL_IOVEC_WAIT;
611     call->iovNBytes = nbytes;
612     call->iovMax = maxio;
613     call->iovNext = 0;
614     call->iov = iov;
615     rxi_FillReadVec(call, 0);
616
617     /* if we need more data then sleep until the receive thread has
618      * filled in the rest. */
619     if (!call->error && call->iovNBytes && call->iovNext < call->iovMax
620         && !(call->flags & RX_CALL_RECEIVE_DONE)) {
621         call->flags |= RX_CALL_READER_WAIT;
622         clock_NewTime();
623         call->startWait = clock_Sec();
624         while (call->flags & RX_CALL_READER_WAIT) {
625 #ifdef  RX_ENABLE_LOCKS
626             CV_WAIT(&call->cv_rq, &call->lock);
627 #else
628             osi_rxSleep(&call->rq);
629 #endif
630         }
631         call->startWait = 0;
632     }
633     call->flags &= ~RX_CALL_IOVEC_WAIT;
634 #ifdef RX_ENABLE_LOCKS
635     if (call->error) {
636         return 0;
637     }
638 #endif /* RX_ENABLE_LOCKS */
639
640     call->iov = NULL;
641     *nio = call->iovNext;
642     return nbytes - call->iovNBytes;
643 }
644
645 int
646 rx_ReadvProc(struct rx_call *call, struct iovec *iov, int *nio, int maxio,
647              int nbytes)
648 {
649     int bytes;
650     SPLVAR;
651
652     NETPRI;
653     MUTEX_ENTER(&call->lock);
654     bytes = rxi_ReadvProc(call, iov, nio, maxio, nbytes);
655     MUTEX_EXIT(&call->lock);
656     USERPRI;
657     return bytes;
658 }
659
660 /* rxi_WriteProc -- internal version.
661  *
662  * LOCKS USED -- called at netpri with rx global lock and call->lock held. */
663
664 int
665 rxi_WriteProc(register struct rx_call *call, register char *buf,
666               register int nbytes)
667 {
668     struct rx_connection *conn = call->conn;
669     register struct rx_packet *cp = call->currentPacket;
670     register unsigned int t;
671     int requestCount = nbytes;
672
673     /* Free any packets from the last call to ReadvProc/WritevProc */
674     if (queue_IsNotEmpty(&call->iovq)) {
675         rxi_FreePackets(0, &call->iovq);
676     }
677
678     if (call->mode != RX_MODE_SENDING) {
679         if ((conn->type == RX_SERVER_CONNECTION)
680             && (call->mode == RX_MODE_RECEIVING)) {
681             call->mode = RX_MODE_SENDING;
682             if (cp) {
683                 cp->flags &= ~RX_PKTFLAG_CP;
684                 rxi_FreePacket(cp);
685                 cp = call->currentPacket = (struct rx_packet *)0;
686                 call->nLeft = 0;
687                 call->nFree = 0;
688             }
689         } else {
690             return 0;
691         }
692     }
693
694     /* Loop condition is checked at end, so that a write of 0 bytes
695      * will force a packet to be created--specially for the case where
696      * there are 0 bytes on the stream, but we must send a packet
697      * anyway. */
698     do {
699         if (call->nFree == 0) {
700             if (!call->error && cp) {
701 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
702                 /* Wait until TQ_BUSY is reset before adding any
703                  * packets to the transmit queue
704                  */
705                 while (call->flags & RX_CALL_TQ_BUSY) {
706                     call->flags |= RX_CALL_TQ_WAIT;
707 #ifdef RX_ENABLE_LOCKS
708                     CV_WAIT(&call->cv_tq, &call->lock);
709 #else /* RX_ENABLE_LOCKS */
710                     osi_rxSleep(&call->tq);
711 #endif /* RX_ENABLE_LOCKS */
712                 }
713 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
714                 clock_NewTime();        /* Bogus:  need new time package */
715                 /* The 0, below, specifies that it is not the last packet: 
716                  * there will be others. PrepareSendPacket may
717                  * alter the packet length by up to
718                  * conn->securityMaxTrailerSize */
719                 hadd32(call->bytesSent, cp->length);
720                 rxi_PrepareSendPacket(call, cp, 0);
721                 cp->flags &= ~RX_PKTFLAG_CP;
722                 cp->flags |= RX_PKTFLAG_TQ;
723                 queue_Append(&call->tq, cp);
724                 cp = call->currentPacket = (struct rx_packet *)0;
725                 if (!
726                     (call->
727                      flags & (RX_CALL_FAST_RECOVER |
728                               RX_CALL_FAST_RECOVER_WAIT))) {
729                     rxi_Start(0, call, 0, 0);
730                 }
731             } else else if (cp) {
732                 cp->flags &= ~RX_PKTFLAG_CP;
733                 rxi_FreePacket(cp);
734                 cp = call->currentPacket = (struct rx_packet *)0;
735             }
736             /* Wait for transmit window to open up */
737             while (!call->error
738                    && call->tnext + 1 > call->tfirst + (2 * call->twind)) {
739                 clock_NewTime();
740                 call->startWait = clock_Sec();
741
742 #ifdef  RX_ENABLE_LOCKS
743                 CV_WAIT(&call->cv_twind, &call->lock);
744 #else
745                 call->flags |= RX_CALL_WAIT_WINDOW_ALLOC;
746                 osi_rxSleep(&call->twind);
747 #endif
748
749                 call->startWait = 0;
750 #ifdef RX_ENABLE_LOCKS
751                 if (call->error) {
752                     return 0;
753                 }
754 #endif /* RX_ENABLE_LOCKS */
755             }
756             if ((cp = rxi_AllocSendPacket(call, nbytes))) {
757                 cp->flags |= RX_PKTFLAG_CP;
758                 call->currentPacket = cp;
759                 call->nFree = cp->length;
760                 call->curvec = 1;       /* 0th vec is always header */
761                 /* begin at the beginning [ more or less ], continue 
762                  * on until the end, then stop. */
763                 call->curpos =
764                     (char *)cp->wirevec[1].iov_base +
765                     call->conn->securityHeaderSize;
766                 call->curlen =
767                     cp->wirevec[1].iov_len - call->conn->securityHeaderSize;
768             }
769             if (call->error) {
770                 if (cp) {
771                     cp->flags &= ~RX_PKTFLAG_CP;
772                     rxi_FreePacket(cp);
773                     call->currentPacket = NULL;
774                 }
775                 return 0;
776             }
777         }
778
779         if (cp && (int)call->nFree < nbytes) {
780             /* Try to extend the current buffer */
781             register int len, mud;
782             len = cp->length;
783             mud = rx_MaxUserDataSize(call);
784             if (mud > len) {
785                 int want;
786                 want = MIN(nbytes - (int)call->nFree, mud - len);
787                 rxi_AllocDataBuf(cp, want, RX_PACKET_CLASS_SEND_CBUF);
788                 if (cp->length > (unsigned)mud)
789                     cp->length = mud;
790                 call->nFree += (cp->length - len);
791             }
792         }
793
794         /* If the remaining bytes fit in the buffer, then store them
795          * and return.  Don't ship a buffer that's full immediately to
796          * the peer--we don't know if it's the last buffer yet */
797
798         if (!cp) {
799             call->nFree = 0;
800         }
801
802         while (nbytes && call->nFree) {
803
804             t = MIN((int)call->curlen, nbytes);
805             t = MIN((int)call->nFree, t);
806             memcpy(call->curpos, buf, t);
807             buf += t;
808             nbytes -= t;
809             call->curpos += t;
810             call->curlen -= (u_short)t;
811             call->nFree -= (u_short)t;
812
813             if (!call->curlen) {
814                 /* need to get another struct iov */
815                 if (++call->curvec >= cp->niovecs) {
816                     /* current packet is full, extend or send it */
817                     call->nFree = 0;
818                 } else {
819                     call->curpos = (char *)cp->wirevec[call->curvec].iov_base;
820                     call->curlen = cp->wirevec[call->curvec].iov_len;
821                 }
822             }
823         }                       /* while bytes to send and room to send them */
824
825         /* might be out of space now */
826         if (!nbytes) {
827             return requestCount;
828         } else;                 /* more data to send, so get another packet and keep going */
829     } while (nbytes);
830
831     return requestCount - nbytes;
832 }
833
834 int
835 rx_WriteProc(struct rx_call *call, char *buf, int nbytes)
836 {
837     int bytes;
838     int tcurlen;
839     int tnFree;
840     char *tcurpos;
841     SPLVAR;
842
843     /*
844      * Free any packets from the last call to ReadvProc/WritevProc.
845      * We do not need the lock because the receiver threads only
846      * touch the iovq when the RX_CALL_IOVEC_WAIT flag is set, and the
847      * RX_CALL_IOVEC_WAIT is always cleared before returning from
848      * ReadvProc/WritevProc.
849      */
850     if (queue_IsNotEmpty(&call->iovq)) {
851         rxi_FreePackets(0, &call->iovq);
852     }
853
854     /*
855      * Most common case: all of the data fits in the current iovec.
856      * We do not need the lock because this is the only thread that
857      * updates the curlen, curpos, nFree fields.
858      *
859      * We are relying on nFree being zero unless the call is in send mode.
860      */
861     tcurlen = (int)call->curlen;
862     tnFree = (int)call->nFree;
863     if (!call->error && tcurlen >= nbytes && tnFree >= nbytes) {
864         tcurpos = call->curpos;
865         memcpy(tcurpos, buf, nbytes);
866         call->curpos = tcurpos + nbytes;
867         call->curlen = (u_short)(tcurlen - nbytes);
868         call->nFree = (u_short)(tnFree - nbytes);
869         return nbytes;
870     }
871
872     NETPRI;
873     MUTEX_ENTER(&call->lock);
874     bytes = rxi_WriteProc(call, buf, nbytes);
875     MUTEX_EXIT(&call->lock);
876     USERPRI;
877     return bytes;
878 }
879
880 /* Optimization for marshalling 32 bit arguments */
881 int
882 rx_WriteProc32(register struct rx_call *call, register afs_int32 * value)
883 {
884     int bytes;
885     int tcurlen;
886     int tnFree;
887     char *tcurpos;
888     SPLVAR;
889
890     /*
891      * Free any packets from the last call to ReadvProc/WritevProc.
892      * We do not need the lock because the receiver threads only
893      * touch the iovq when the RX_CALL_IOVEC_WAIT flag is set, and the
894      * RX_CALL_IOVEC_WAIT is always cleared before returning from
895      * ReadvProc/WritevProc.
896      */
897     if (queue_IsNotEmpty(&call->iovq)) {
898         rxi_FreePackets(0, &call->iovq);
899     }
900
901     /*
902      * Most common case: all of the data fits in the current iovec.
903      * We do not need the lock because this is the only thread that
904      * updates the curlen, curpos, nFree fields.
905      *
906      * We are relying on nFree being zero unless the call is in send mode.
907      */
908     tcurlen = call->curlen;
909     tnFree = call->nFree;
910     if (!call->error && tcurlen >= sizeof(afs_int32)
911         && tnFree >= sizeof(afs_int32)) {
912         tcurpos = call->curpos;
913         if (!((size_t)tcurpos & (sizeof(afs_int32) - 1))) {
914             *((afs_int32 *) (tcurpos)) = *value;
915         } else {
916             memcpy(tcurpos, (char *)value, sizeof(afs_int32));
917         }
918         call->curpos = tcurpos + sizeof(afs_int32);
919         call->curlen = (u_short)(tcurlen - sizeof(afs_int32));
920         call->nFree = (u_short)(tnFree - sizeof(afs_int32));
921         return sizeof(afs_int32);
922     }
923
924     NETPRI;
925     MUTEX_ENTER(&call->lock);
926     bytes = rxi_WriteProc(call, (char *)value, sizeof(afs_int32));
927     MUTEX_EXIT(&call->lock);
928     USERPRI;
929     return bytes;
930 }
931
932 /* rxi_WritevAlloc -- internal version.
933  *
934  * Fill in an iovec to point to data in packet buffers. The application
935  * calls rxi_WritevProc when the buffers are full.
936  *
937  * LOCKS USED -- called at netpri with rx global lock and call->lock held. */
938
939 int
940 rxi_WritevAlloc(struct rx_call *call, struct iovec *iov, int *nio, int maxio,
941                 int nbytes)
942 {
943     struct rx_connection *conn = call->conn;
944     struct rx_packet *cp = call->currentPacket;
945     int requestCount;
946     int nextio;
947     /* Temporary values, real work is done in rxi_WritevProc */
948     int tnFree;
949     int tcurvec;
950     char *tcurpos;
951     int tcurlen;
952
953     requestCount = nbytes;
954     nextio = 0;
955
956     /* Free any packets from the last call to ReadvProc/WritevProc */
957     if (queue_IsNotEmpty(&call->iovq)) {
958         rxi_FreePackets(0, &call->iovq);
959     }
960
961     if (call->mode != RX_MODE_SENDING) {
962         if ((conn->type == RX_SERVER_CONNECTION)
963             && (call->mode == RX_MODE_RECEIVING)) {
964             call->mode = RX_MODE_SENDING;
965             if (cp) {
966                 cp->flags &= ~RX_PKTFLAG_CP;
967                 rxi_FreePacket(cp);
968                 cp = call->currentPacket = (struct rx_packet *)0;
969                 call->nLeft = 0;
970                 call->nFree = 0;
971             }
972         } else {
973             return 0;
974         }
975     }
976
977     /* Set up the iovec to point to data in packet buffers. */
978     tnFree = call->nFree;
979     tcurvec = call->curvec;
980     tcurpos = call->curpos;
981     tcurlen = call->curlen;
982     do {
983         register unsigned int t;
984
985         if (tnFree == 0) {
986             /* current packet is full, allocate a new one */
987             cp = rxi_AllocSendPacket(call, nbytes);
988             if (cp == NULL) {
989                 /* out of space, return what we have */
990                 *nio = nextio;
991                 return requestCount - nbytes;
992             }
993             cp->flags |= RX_PKTFLAG_IOVQ;
994             queue_Append(&call->iovq, cp);
995             tnFree = cp->length;
996             tcurvec = 1;
997             tcurpos =
998                 (char *)cp->wirevec[1].iov_base +
999                 call->conn->securityHeaderSize;
1000             tcurlen = cp->wirevec[1].iov_len - call->conn->securityHeaderSize;
1001         }
1002
1003         if (tnFree < nbytes) {
1004             /* try to extend the current packet */
1005             register int len, mud;
1006             len = cp->length;
1007             mud = rx_MaxUserDataSize(call);
1008             if (mud > len) {
1009                 int want;
1010                 want = MIN(nbytes - tnFree, mud - len);
1011                 rxi_AllocDataBuf(cp, want, RX_PACKET_CLASS_SEND_CBUF);
1012                 if (cp->length > (unsigned)mud)
1013                     cp->length = mud;
1014                 tnFree += (cp->length - len);
1015                 if (cp == call->currentPacket) {
1016                     call->nFree += (cp->length - len);
1017                 }
1018             }
1019         }
1020
1021         /* fill in the next entry in the iovec */
1022         t = MIN(tcurlen, nbytes);
1023         t = MIN(tnFree, t);
1024         iov[nextio].iov_base = tcurpos;
1025         iov[nextio].iov_len = t;
1026         nbytes -= t;
1027         tcurpos += t;
1028         tcurlen -= t;
1029         tnFree -= t;
1030         nextio++;
1031
1032         if (!tcurlen) {
1033             /* need to get another struct iov */
1034             if (++tcurvec >= cp->niovecs) {
1035                 /* current packet is full, extend it or move on to next packet */
1036                 tnFree = 0;
1037             } else {
1038                 tcurpos = (char *)cp->wirevec[tcurvec].iov_base;
1039                 tcurlen = cp->wirevec[tcurvec].iov_len;
1040             }
1041         }
1042     } while (nbytes && nextio < maxio);
1043     *nio = nextio;
1044     return requestCount - nbytes;
1045 }
1046
1047 int
1048 rx_WritevAlloc(struct rx_call *call, struct iovec *iov, int *nio, int maxio,
1049                int nbytes)
1050 {
1051     int bytes;
1052     SPLVAR;
1053
1054     NETPRI;
1055     MUTEX_ENTER(&call->lock);
1056     bytes = rxi_WritevAlloc(call, iov, nio, maxio, nbytes);
1057     MUTEX_EXIT(&call->lock);
1058     USERPRI;
1059     return bytes;
1060 }
1061
1062 /* rxi_WritevProc -- internal version.
1063  *
1064  * Send buffers allocated in rxi_WritevAlloc.
1065  *
1066  * LOCKS USED -- called at netpri with rx global lock and call->lock held. */
1067
1068 int
1069 rxi_WritevProc(struct rx_call *call, struct iovec *iov, int nio, int nbytes)
1070 {
1071     struct rx_packet *cp = call->currentPacket;
1072     int nextio;
1073     int requestCount;
1074     struct rx_queue tmpq;
1075
1076     requestCount = nbytes;
1077     nextio = 0;
1078
1079     if (call->mode != RX_MODE_SENDING) {
1080         call->error = RX_PROTOCOL_ERROR;
1081     }
1082 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
1083     /* Wait until TQ_BUSY is reset before trying to move any
1084      * packets to the transmit queue.  */
1085     while (!call->error && call->flags & RX_CALL_TQ_BUSY) {
1086         call->flags |= RX_CALL_TQ_WAIT;
1087 #ifdef RX_ENABLE_LOCKS
1088         CV_WAIT(&call->cv_tq, &call->lock);
1089 #else /* RX_ENABLE_LOCKS */
1090         osi_rxSleep(&call->tq);
1091 #endif /* RX_ENABLE_LOCKS */
1092     }
1093 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
1094
1095     if (call->error) {
1096         if (cp) {
1097             cp->flags &= ~RX_PKTFLAG_CP;
1098             cp->flags |= RX_PKTFLAG_IOVQ;
1099             queue_Prepend(&call->iovq, cp);
1100             cp = call->currentPacket = (struct rx_packet *)0;
1101         }
1102         rxi_FreePackets(0, &call->iovq);
1103         return 0;
1104     }
1105
1106     /* Loop through the I/O vector adjusting packet pointers.
1107      * Place full packets back onto the iovq once they are ready
1108      * to send. Set RX_PROTOCOL_ERROR if any problems are found in
1109      * the iovec. We put the loop condition at the end to ensure that
1110      * a zero length write will push a short packet. */
1111     nextio = 0;
1112     queue_Init(&tmpq);
1113     do {
1114         if (call->nFree == 0 && cp) {
1115             clock_NewTime();    /* Bogus:  need new time package */
1116             /* The 0, below, specifies that it is not the last packet: 
1117              * there will be others. PrepareSendPacket may
1118              * alter the packet length by up to
1119              * conn->securityMaxTrailerSize */
1120             hadd32(call->bytesSent, cp->length);
1121             rxi_PrepareSendPacket(call, cp, 0);
1122             cp->flags |= RX_PKTFLAG_TQ;
1123             queue_Append(&tmpq, cp);
1124
1125             /* The head of the iovq is now the current packet */
1126             if (nbytes) {
1127                 if (queue_IsEmpty(&call->iovq)) {
1128                     call->error = RX_PROTOCOL_ERROR;
1129                     rxi_FreePackets(0, &tmpq);
1130                     return 0;
1131                 }
1132                 cp = queue_First(&call->iovq, rx_packet);
1133                 queue_Remove(cp);
1134                 cp->flags &= ~RX_PKTFLAG_IOVQ;
1135                 cp->flags |= RX_PKTFLAG_CP;
1136                 call->currentPacket = cp;
1137                 call->nFree = cp->length;
1138                 call->curvec = 1;
1139                 call->curpos =
1140                     (char *)cp->wirevec[1].iov_base +
1141                     call->conn->securityHeaderSize;
1142                 call->curlen =
1143                     cp->wirevec[1].iov_len - call->conn->securityHeaderSize;
1144             }
1145         }
1146
1147         if (nbytes) {
1148             /* The next iovec should point to the current position */
1149             if (iov[nextio].iov_base != call->curpos
1150                 || iov[nextio].iov_len > (int)call->curlen) {
1151                 call->error = RX_PROTOCOL_ERROR;
1152                 if (cp) {
1153                     cp->flags &= ~RX_PKTFLAG_CP;
1154                     queue_Prepend(&tmpq, cp);
1155                 }
1156                 rxi_FreePackets(0, &tmpq);
1157                 return 0;
1158             }
1159             nbytes -= iov[nextio].iov_len;
1160             call->curpos += iov[nextio].iov_len;
1161             call->curlen -= iov[nextio].iov_len;
1162             call->nFree -= iov[nextio].iov_len;
1163             nextio++;
1164             if (call->curlen == 0) {
1165                 if (++call->curvec > cp->niovecs) {
1166                     call->nFree = 0;
1167                 } else {
1168                     call->curpos = (char *)cp->wirevec[call->curvec].iov_base;
1169                     call->curlen = cp->wirevec[call->curvec].iov_len;
1170                 }
1171             }
1172         }
1173     } while (nbytes && nextio < nio);
1174
1175     /* Move the packets from the temporary queue onto the transmit queue.
1176      * We may end up with more than call->twind packets on the queue. */
1177     queue_SpliceAppend(&call->tq, &tmpq);
1178
1179     if (!(call->flags & (RX_CALL_FAST_RECOVER | RX_CALL_FAST_RECOVER_WAIT))) {
1180         rxi_Start(0, call, 0, 0);
1181     }
1182
1183     /* Wait for the length of the transmit queue to fall below call->twind */
1184     while (!call->error && call->tnext + 1 > call->tfirst + (2 * call->twind)) {
1185         clock_NewTime();
1186         call->startWait = clock_Sec();
1187 #ifdef  RX_ENABLE_LOCKS
1188         CV_WAIT(&call->cv_twind, &call->lock);
1189 #else
1190         call->flags |= RX_CALL_WAIT_WINDOW_ALLOC;
1191         osi_rxSleep(&call->twind);
1192 #endif
1193         call->startWait = 0;
1194     }
1195
1196     if (call->error) {
1197         if (cp) {
1198             cp->flags &= ~RX_PKTFLAG_CP;
1199             rxi_FreePacket(cp);
1200         }
1201         return 0;
1202     }
1203
1204     return requestCount - nbytes;
1205 }
1206
1207 int
1208 rx_WritevProc(struct rx_call *call, struct iovec *iov, int nio, int nbytes)
1209 {
1210     int bytes;
1211     SPLVAR;
1212
1213     NETPRI;
1214     MUTEX_ENTER(&call->lock);
1215     bytes = rxi_WritevProc(call, iov, nio, nbytes);
1216     MUTEX_EXIT(&call->lock);
1217     USERPRI;
1218     return bytes;
1219 }
1220
1221 /* Flush any buffered data to the stream, switch to read mode
1222  * (clients) or to EOF mode (servers) */
1223 void
1224 rxi_FlushWrite(register struct rx_call *call)
1225 {
1226     register struct rx_packet *cp = call->currentPacket;
1227
1228     /* Free any packets from the last call to ReadvProc/WritevProc */
1229     if (queue_IsNotEmpty(&call->iovq)) {
1230         rxi_FreePackets(0, &call->iovq);
1231     }
1232
1233     if (call->mode == RX_MODE_SENDING) {
1234
1235         call->mode =
1236             (call->conn->type ==
1237              RX_CLIENT_CONNECTION ? RX_MODE_RECEIVING : RX_MODE_EOF);
1238
1239 #ifdef RX_KERNEL_TRACE
1240         {
1241             int glockOwner = ISAFS_GLOCK();
1242             if (!glockOwner)
1243                 AFS_GLOCK();
1244             afs_Trace3(afs_iclSetp, CM_TRACE_WASHERE, ICL_TYPE_STRING,
1245                        __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER,
1246                        call);
1247             if (!glockOwner)
1248                 AFS_GUNLOCK();
1249         }
1250 #endif
1251
1252 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
1253         /* Wait until TQ_BUSY is reset before adding any
1254          * packets to the transmit queue
1255          */
1256         while (call->flags & RX_CALL_TQ_BUSY) {
1257             call->flags |= RX_CALL_TQ_WAIT;
1258 #ifdef RX_ENABLE_LOCKS
1259             CV_WAIT(&call->cv_tq, &call->lock);
1260 #else /* RX_ENABLE_LOCKS */
1261             osi_rxSleep(&call->tq);
1262 #endif /* RX_ENABLE_LOCKS */
1263         }
1264 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
1265
1266         if (cp) {
1267             /* cp->length is only supposed to be the user's data */
1268             /* cp->length was already set to (then-current) 
1269              * MaxUserDataSize or less. */
1270             cp->flags &= ~RX_PKTFLAG_CP;
1271             cp->length -= call->nFree;
1272             call->currentPacket = (struct rx_packet *)0;
1273             call->nFree = 0;
1274         } else {
1275             cp = rxi_AllocSendPacket(call, 0);
1276             if (!cp) {
1277                 /* Mode can no longer be MODE_SENDING */
1278                 return;
1279             }
1280             cp->length = 0;
1281             cp->niovecs = 2;    /* header + space for rxkad stuff */
1282             call->nFree = 0;
1283         }
1284
1285         /* The 1 specifies that this is the last packet */
1286         hadd32(call->bytesSent, cp->length);
1287         rxi_PrepareSendPacket(call, cp, 1);
1288         cp->flags |= RX_PKTFLAG_TQ;
1289         queue_Append(&call->tq, cp);
1290         if (!
1291             (call->
1292              flags & (RX_CALL_FAST_RECOVER | RX_CALL_FAST_RECOVER_WAIT))) {
1293             rxi_Start(0, call, 0, 0);
1294         }
1295     }
1296 }
1297
1298 /* Flush any buffered data to the stream, switch to read mode
1299  * (clients) or to EOF mode (servers) */
1300 void
1301 rx_FlushWrite(struct rx_call *call)
1302 {
1303     SPLVAR;
1304     NETPRI;
1305     MUTEX_ENTER(&call->lock);
1306     rxi_FlushWrite(call);
1307     MUTEX_EXIT(&call->lock);
1308     USERPRI;
1309 }