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.7.3.1 */
34 * t_rcvrel.c and t_rcvreldata.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>
52 _tx_rcvrel(int fd
, int api_semantics
)
55 struct strbuf databuf
;
57 union T_primitives
*pptr
;
58 struct _ti_user
*tiptr
;
60 int didalloc
, didralloc
;
64 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == 0)
66 sig_mutex_lock(&tiptr
->ti_lock
);
68 if (tiptr
->ti_servtype
!= T_COTS_ORD
) {
69 t_errno
= TNOTSUPPORT
;
70 sig_mutex_unlock(&tiptr
->ti_lock
);
74 if (_T_IS_XTI(api_semantics
)) {
76 * User level state verification only done for XTI
77 * because doing for TLI may break existing applications
79 if (!(tiptr
->ti_state
== T_DATAXFER
||
80 tiptr
->ti_state
== T_OUTREL
)) {
82 sig_mutex_unlock(&tiptr
->ti_lock
);
87 if ((retval
= _t_look_locked(fd
, tiptr
, 0, api_semantics
)) < 0) {
89 sig_mutex_unlock(&tiptr
->ti_lock
);
94 if (retval
== T_DISCONNECT
) {
96 * This ensures preference to T_DISCON_IND which is
97 * the design model for TPI
100 sig_mutex_unlock(&tiptr
->ti_lock
);
104 if ((tiptr
->ti_lookcnt
> 0) &&
105 /* LINTED pointer cast */
106 (*((t_scalar_t
*)tiptr
->ti_lookbufs
.tl_lookcbuf
) == T_ORDREL_IND
)) {
108 * Current look buffer event is T_ORDREL_IND.
109 * Remove it from look buffer event list.
111 _t_free_looklist_head(tiptr
);
112 _T_TX_NEXTSTATE(T_RCVREL
, tiptr
,
113 "t_rcv: invalid state event T_RCVREL");
114 sig_mutex_unlock(&tiptr
->ti_lock
);
117 if (retval
!= T_ORDREL
) {
119 sig_mutex_unlock(&tiptr
->ti_lock
);
125 * get ordrel off read queue.
126 * use ctl and rcv buffers
128 * Acquire ctlbuf for use in sending/receiving control part
131 if (_t_acquire_ctlbuf(tiptr
, &ctlbuf
, &didalloc
) < 0) {
133 sig_mutex_unlock(&tiptr
->ti_lock
);
139 * Acquire databuf for use in sending/receiving data part
141 if (_t_acquire_databuf(tiptr
, &databuf
, &didralloc
) < 0) {
146 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
147 sig_mutex_unlock(&tiptr
->ti_lock
);
153 * Since we have verified above that an orderly release event
154 * is pending on this endpoint, we assume that this getmsg()
155 * cannot block forever.
158 retval
= getmsg(fd
, &ctlbuf
, &databuf
, &flg
);
159 } while (retval
< 0 && errno
== EINTR
);
167 * did I get entire message?
174 /* LINTED pointer cast */
175 pptr
= (union T_primitives
*)ctlbuf
.buf
;
177 if (ctlbuf
.len
< (int)sizeof (struct T_ordrel_ind
)) {
182 if (pptr
->type
!= T_ORDREL_IND
) {
183 if (pptr
->type
== T_DISCON_IND
) {
185 * T_DISCON_IND gets priority following
186 * TPI design philosphy.
188 * Add it to the events in the "look buffer"
189 * list of events. This routine may defer signals.
191 if (_t_register_lookevent(tiptr
, databuf
.buf
,
192 databuf
.len
, ctlbuf
.buf
,
207 _T_TX_NEXTSTATE(T_RCVREL
, tiptr
,
208 "t_rcvrel: invalid state event T_RCVREL");
213 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
217 tiptr
->ti_rcvbuf
= databuf
.buf
;
218 sig_mutex_unlock(&tiptr
->ti_lock
);
227 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
231 tiptr
->ti_rcvbuf
= databuf
.buf
;
232 sig_mutex_unlock(&tiptr
->ti_lock
);