1 /*
2 * Copyright 1993 Network Computing Devices, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name Network Computing Devices, Inc. not be
9 * used in advertising or publicity pertaining to distribution of this
10 * software without specific, written prior permission.
11 *
12 * THIS SOFTWARE IS PROVIDED 'AS-IS'. NETWORK COMPUTING DEVICES, INC.,
13 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
14 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK
16 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
17 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
18 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
19 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 *
22 * $NCDId: @(#)WriteEl.c,v 1.5 1994/04/07 20:34:11 greg Exp $
23 */
24
25 #include "Alibint.h"
26
27 void
_AuWriteElement(AuServer * aud,AuFlowID flow,int element_num,int state,AuUint32 num_bytes,AuPointer data,AuStatus * ret_status)28 _AuWriteElement(
29 AuServer *aud,
30 AuFlowID flow,
31 int element_num,
32 int state,
33 AuUint32 num_bytes,
34 AuPointer data,
35 AuStatus *ret_status
36 )
37 {
38 auWriteElementReq *req;
39
40 _AuLockServer();
41 _AuGetReq(WriteElement, req, aud);
42
43 #undef xfer
44 #define xfer(x) req->x = x
45
46 xfer(flow);
47 xfer(element_num);
48 xfer(num_bytes);
49 xfer(state);
50
51 req->length += PAD4(num_bytes) >> 2;
52
53 _AuData(aud, data, num_bytes);
54
55 (void) _AuIfRoundTrip(aud, ret_status);
56 _AuUnlockServer();
57 _AuSyncHandle(aud);
58 }
59
60 void
AuWriteElement(AuServer * aud,AuFlowID flow,int element_num,AuUint32 num_bytes,AuPointer data,AuBool end_of_data,AuStatus * ret_status)61 AuWriteElement(
62 AuServer *aud,
63 AuFlowID flow,
64 int element_num,
65 AuUint32 num_bytes,
66 AuPointer data,
67 AuBool end_of_data,
68 AuStatus *ret_status
69 )
70 {
71 AuUint32 maxBytes,
72 bytes,
73 finalState;
74 AuStatus status = AuSuccess,
75 *pstatus;
76
77 if (ret_status)
78 {
79 *ret_status = AuSuccess;
80 pstatus = ret_status;
81 }
82 else
83 pstatus = &status;
84
85 finalState = end_of_data ? AuTransferStateEnd : AuTransferStateReady;
86 maxBytes = (aud->max_request_size) - SIZEOF(auWriteElementReq);
87
88 do
89 {
90 bytes = num_bytes > maxBytes ? maxBytes : num_bytes;
91 num_bytes -= bytes;
92 _AuWriteElement(aud, flow, element_num,
93 num_bytes ? AuTransferStatePending : finalState,
94 bytes, data,
95 ret_status);
96 data = (AuPointer) ((unsigned char *) data + bytes);
97 } while (*pstatus == AuSuccess && num_bytes);
98 }
99