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]
23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
24 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
34 * t_sndudata.c and t_sndvudata.c are very similar and contain common code.
35 * Any changes to either of them should be reviewed to see whether they
36 * are applicable to the other file.
42 #include <sys/stream.h>
43 #define _SUN_TPI_VERSION 2
44 #include <sys/tihdr.h>
45 #include <sys/timod.h>
51 _tx_sndudata(int fd
, const struct t_unitdata
*unitdata
, int api_semantics
)
53 struct T_unitdata_req
*udreq
;
56 struct _ti_user
*tiptr
;
60 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == NULL
)
62 sig_mutex_lock(&tiptr
->ti_lock
);
64 if (tiptr
->ti_servtype
!= T_CLTS
) {
65 t_errno
= TNOTSUPPORT
;
66 sig_mutex_unlock(&tiptr
->ti_lock
);
70 if (_T_IS_XTI(api_semantics
)) {
72 * User level state verification only done for XTI
73 * because doing for TLI may break existing applications
75 if (tiptr
->ti_state
!= T_IDLE
) {
77 sig_mutex_unlock(&tiptr
->ti_lock
);
82 if (((int)unitdata
->udata
.len
== 0) &&
83 !(tiptr
->ti_prov_flag
& (SENDZERO
|OLD_SENDZERO
))) {
85 sig_mutex_unlock(&tiptr
->ti_lock
);
89 if ((tiptr
->ti_maxpsz
> 0) &&
90 (unitdata
->udata
.len
> (uint32_t)tiptr
->ti_maxpsz
)) {
91 if (_T_IS_TLI(api_semantics
)) {
97 sig_mutex_unlock(&tiptr
->ti_lock
);
103 * Acquire ctlbuf for use in sending/receiving control part
106 if (_t_acquire_ctlbuf(tiptr
, &ctlbuf
, &didalloc
) < 0) {
108 sig_mutex_unlock(&tiptr
->ti_lock
);
113 /* LINTED pointer cast */
114 udreq
= (struct T_unitdata_req
*)ctlbuf
.buf
;
116 udreq
->PRIM_type
= T_UNITDATA_REQ
;
117 udreq
->DEST_length
= unitdata
->addr
.len
;
118 udreq
->DEST_offset
= 0;
119 udreq
->OPT_length
= unitdata
->opt
.len
;
120 udreq
->OPT_offset
= 0;
121 size
= (int)sizeof (struct T_unitdata_req
);
123 if (unitdata
->addr
.len
) {
124 if (_t_aligned_copy(&ctlbuf
, unitdata
->addr
.len
, size
,
125 unitdata
->addr
.buf
, &udreq
->DEST_offset
) < 0) {
127 * Aligned copy based will overflow buffer
128 * allocated based on maximum transport address
135 size
= udreq
->DEST_offset
+ udreq
->DEST_length
;
137 if (unitdata
->opt
.len
) {
138 if (_t_aligned_copy(&ctlbuf
, unitdata
->opt
.len
, size
,
139 unitdata
->opt
.buf
, &udreq
->OPT_offset
) < 0) {
141 * Aligned copy based will overflow buffer
142 * allocated based on maximum transport option
149 size
= udreq
->OPT_offset
+ udreq
->OPT_length
;
152 if (size
> (int)ctlbuf
.maxlen
) {
161 * Calls to send data (write or putmsg) can potentially
162 * block, for MT case, we drop the lock and enable signals here
163 * and acquire it back.
164 * At this point, we are sure SENDZERO is supported and the
165 * putmsg below may send a zero length message,
166 * (i.e with valid control part, but zero data part)
168 sig_mutex_unlock(&tiptr
->ti_lock
);
169 if (putmsg(fd
, &ctlbuf
, (struct strbuf
*)&unitdata
->udata
, 0) < 0) {
175 sig_mutex_lock(&tiptr
->ti_lock
);
179 sig_mutex_lock(&tiptr
->ti_lock
);
181 _T_TX_NEXTSTATE(T_SNDUDATA
, tiptr
,
182 "t_sndudata: invalid state event T_SNDUDATA");
186 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
187 sig_mutex_unlock(&tiptr
->ti_lock
);
194 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
195 sig_mutex_unlock(&tiptr
->ti_lock
);