4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 * t_rcvudata.c and t_rcvvudata.c are very similar and contain common code.
30 * Any changes to either of them should be reviewed to see whether they
31 * are applicable to the other file.
38 #include <sys/stream.h>
39 #define _SUN_TPI_VERSION 2
40 #include <sys/tihdr.h>
41 #include <sys/timod.h>
51 struct t_unitdata
*unitdata
,
53 unsigned int tiovcount
,
59 struct strbuf databuf
;
62 union T_primitives
*pptr
;
63 struct _ti_user
*tiptr
;
69 assert(api_semantics
== TX_XTI_XNS5_API
);
71 if (tiovcount
== 0 || tiovcount
> T_IOV_MAX
) {
76 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == NULL
)
78 sig_mutex_lock(&tiptr
->ti_lock
);
80 if (tiptr
->ti_servtype
!= T_CLTS
) {
81 t_errno
= TNOTSUPPORT
;
82 sig_mutex_unlock(&tiptr
->ti_lock
);
86 if (tiptr
->ti_state
!= T_IDLE
) {
88 sig_mutex_unlock(&tiptr
->ti_lock
);
93 * check if there is something in look buffer
95 if (tiptr
->ti_lookcnt
> 0) {
96 sig_mutex_unlock(&tiptr
->ti_lock
);
102 * Acquire ctlbuf for use in sending/receiving control part
105 if (_t_acquire_ctlbuf(tiptr
, &ctlbuf
, &didalloc
) < 0) {
107 sig_mutex_unlock(&tiptr
->ti_lock
);
114 nbytes
= _t_bytecount_upto_intmax(tiov
, tiovcount
);
116 if (nbytes
!= 0 && ((dataptr
= malloc(nbytes
)) == NULL
)) {
121 databuf
.maxlen
= nbytes
;
123 databuf
.buf
= dataptr
;
126 * This is a call that may block indefinitely so we drop the
127 * lock and allow signals in MT case here and reacquire it.
128 * Error case should roll back state changes done above
129 * (happens to be no state change here)
131 sig_mutex_unlock(&tiptr
->ti_lock
);
132 if ((retval
= getmsg(fd
, &ctlbuf
, &databuf
, &flg
)) < 0) {
138 sig_mutex_lock(&tiptr
->ti_lock
);
142 sig_mutex_lock(&tiptr
->ti_lock
);
145 * is there control piece with data?
147 if (ctlbuf
.len
> 0) {
148 if (ctlbuf
.len
< (int)sizeof (t_scalar_t
)) {
154 /* LINTED pointer cast */
155 pptr
= (union T_primitives
*)ctlbuf
.buf
;
157 switch (pptr
->type
) {
161 (int)sizeof (struct T_unitdata_ind
)) ||
162 (pptr
->unitdata_ind
.OPT_length
&&
163 (ctlbuf
.len
< (int)(pptr
->unitdata_ind
.OPT_length
164 + pptr
->unitdata_ind
.OPT_offset
)))) {
170 if (unitdata
->addr
.maxlen
> 0) {
171 if (TLEN_GT_NLEN(pptr
->unitdata_ind
.SRC_length
,
172 unitdata
->addr
.maxlen
)) {
176 (void) memcpy(unitdata
->addr
.buf
,
177 ctlbuf
.buf
+ pptr
->unitdata_ind
.SRC_offset
,
178 (size_t)pptr
->unitdata_ind
.SRC_length
);
180 pptr
->unitdata_ind
.SRC_length
;
182 if (unitdata
->opt
.maxlen
> 0) {
183 if (TLEN_GT_NLEN(pptr
->unitdata_ind
.OPT_length
,
184 unitdata
->opt
.maxlen
)) {
188 (void) memcpy(unitdata
->opt
.buf
, ctlbuf
.buf
+
189 pptr
->unitdata_ind
.OPT_offset
,
190 (size_t)pptr
->unitdata_ind
.OPT_length
);
192 pptr
->unitdata_ind
.OPT_length
;
194 if (retval
& MOREDATA
)
197 * No state changes happens on T_RCVUDATA
198 * event (NOOP). We do it only to log errors.
200 _T_TX_NEXTSTATE(T_RCVUDATA
, tiptr
,
201 "t_rcvvudata: invalid state event T_RCVUDATA");
206 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
207 _t_scatter(&databuf
, tiov
, tiovcount
);
209 sig_mutex_unlock(&tiptr
->ti_lock
);
210 return (databuf
.len
);
213 if (_t_register_lookevent(tiptr
, 0, 0, ctlbuf
.buf
,
230 } else { /* else part of "if (ctlbuf.len > 0)" */
231 unitdata
->addr
.len
= 0;
232 unitdata
->opt
.len
= 0;
234 * only data in message no control piece
236 if (retval
& MOREDATA
)
239 * No state transition occurs on
240 * event T_RCVUDATA. We do it only to
243 _T_TX_NEXTSTATE(T_RCVUDATA
, tiptr
,
244 "t_rcvvudata: invalid state event T_RCVUDATA");
248 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
249 _t_scatter(&databuf
, tiov
, tiovcount
);
251 sig_mutex_unlock(&tiptr
->ti_lock
);
252 return (databuf
.len
);
260 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
262 sig_mutex_unlock(&tiptr
->ti_lock
);