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 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4.3.1 */
37 #include <sys/stream.h>
38 #define _SUN_TPI_VERSION 2
39 #include <sys/tihdr.h>
40 #include <sys/timod.h>
47 _tx_snddis(int fd
, const struct t_call
*call
, int api_semantics
)
49 struct T_discon_req dreq
;
51 struct strbuf databuf
;
52 struct _ti_user
*tiptr
;
56 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == NULL
)
58 sig_mutex_lock(&tiptr
->ti_lock
);
60 if (tiptr
->ti_servtype
== T_CLTS
) {
61 t_errno
= TNOTSUPPORT
;
62 sig_mutex_unlock(&tiptr
->ti_lock
);
66 if (_T_IS_XTI(api_semantics
)) {
68 * User level state verification only done for XTI
69 * because doing for TLI may break existing applications
70 * Note: This is documented in TLI man page but never
73 if (!(tiptr
->ti_state
== T_DATAXFER
||
74 tiptr
->ti_state
== T_OUTCON
||
75 tiptr
->ti_state
== T_OUTREL
||
76 tiptr
->ti_state
== T_INREL
||
77 (tiptr
->ti_state
== T_INCON
&& tiptr
->ti_ocnt
> 0))) {
79 sig_mutex_unlock(&tiptr
->ti_lock
);
84 * Following check only done for XTI as it may be a risk
85 * to existing buggy TLI applications.
89 if (call
!= NULL
&& call
->udata
.len
) {
90 if ((tiptr
->ti_ddatasize
== T_INVALID
/* -2 */) ||
91 ((tiptr
->ti_ddatasize
!= T_INFINITE
/* -1*/) &&
93 (uint32_t)tiptr
->ti_ddatasize
))) {
95 * user data not valid with disconnect or it
96 * exceeds the limits specified by the
100 sig_mutex_unlock(&tiptr
->ti_lock
);
106 * If disconnect is done on a listener, the 'call' parameter
109 if ((tiptr
->ti_state
== T_INCON
) &&
112 sig_mutex_unlock(&tiptr
->ti_lock
);
117 * look at look buffer to see if there is a discon there
120 if (_t_look_locked(fd
, tiptr
, 0, api_semantics
) == T_DISCONNECT
) {
122 sig_mutex_unlock(&tiptr
->ti_lock
);
126 if ((tiptr
->ti_lookcnt
> 0) && (call
== 0))
127 _t_flush_lookevents(tiptr
); /* flush but not on listener */
130 retval
= ioctl(fd
, I_FLUSH
, FLUSHW
);
131 } while (retval
< 0 && errno
== EINTR
);
135 sig_mutex_unlock(&tiptr
->ti_lock
);
140 ctlbuf
.len
= (int)sizeof (struct T_discon_req
);
141 ctlbuf
.maxlen
= (int)sizeof (struct T_discon_req
);
142 ctlbuf
.buf
= (char *)&dreq
;
144 dreq
.PRIM_type
= T_DISCON_REQ
;
145 dreq
.SEQ_number
= (call
? call
->sequence
: -1);
147 databuf
.maxlen
= (call
? call
->udata
.len
: 0);
148 databuf
.len
= (call
? call
->udata
.len
: 0);
149 databuf
.buf
= (call
? call
->udata
.buf
: NULL
);
152 * Calls to send data (write or putmsg) can potentially
153 * block, for MT case, we drop the lock and enable signals here
154 * and acquire it back
156 sig_mutex_unlock(&tiptr
->ti_lock
);
157 if (putmsg(fd
, &ctlbuf
, (databuf
.len
? &databuf
: NULL
), 0) < 0) {
161 sig_mutex_lock(&tiptr
->ti_lock
);
163 if (_t_is_ok(fd
, tiptr
, T_DISCON_REQ
) < 0) {
165 sig_mutex_unlock(&tiptr
->ti_lock
);
170 tiptr
->ti_flags
&= ~(MORE
|EXPEDITED
);
172 if (tiptr
->ti_ocnt
<= 1) {
173 if (tiptr
->ti_state
== T_INCON
) {
175 tiptr
->ti_flags
&= ~TX_TQFULL_NOTIFIED
;
177 _T_TX_NEXTSTATE(T_SNDDIS1
, tiptr
,
178 "t_snddis: invalid state event T_SNDDIS1");
180 if (tiptr
->ti_state
== T_INCON
) {
182 tiptr
->ti_flags
&= ~TX_TQFULL_NOTIFIED
;
184 _T_TX_NEXTSTATE(T_SNDDIS2
, tiptr
,
185 "t_snddis: invalid state event T_SNDDIS2");
188 sig_mutex_unlock(&tiptr
->ti_lock
);