xref: /onnv-gate/usr/src/lib/libnsl/nsl/t_rcv.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate  * Copyright 1993-2003 Sun Microsystems, Inc.  All rights reserved.
28*0Sstevel@tonic-gate  * Use is subject to license terms.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7 */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate /*
35*0Sstevel@tonic-gate  * t_rcv.c and t_rcvv.c are very similar and contain common code.
36*0Sstevel@tonic-gate  * Any changes to either of them should be reviewed to see whether they
37*0Sstevel@tonic-gate  * are applicable to the other file.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate #include "mt.h"
40*0Sstevel@tonic-gate #include <stdlib.h>
41*0Sstevel@tonic-gate #include <rpc/trace.h>
42*0Sstevel@tonic-gate #include <errno.h>
43*0Sstevel@tonic-gate #include <unistd.h>
44*0Sstevel@tonic-gate #include <stropts.h>
45*0Sstevel@tonic-gate #include <sys/stream.h>
46*0Sstevel@tonic-gate #define	_SUN_TPI_VERSION 2
47*0Sstevel@tonic-gate #include <sys/tihdr.h>
48*0Sstevel@tonic-gate #include <sys/timod.h>
49*0Sstevel@tonic-gate #include <xti.h>
50*0Sstevel@tonic-gate #include <syslog.h>
51*0Sstevel@tonic-gate #include <assert.h>
52*0Sstevel@tonic-gate #include "tx.h"
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate int
55*0Sstevel@tonic-gate _tx_rcv(int fd, char *buf, unsigned nbytes, int *flags, int api_semantics)
56*0Sstevel@tonic-gate {
57*0Sstevel@tonic-gate 	struct strbuf ctlbuf, databuf;
58*0Sstevel@tonic-gate 	int retval, flg = 0;
59*0Sstevel@tonic-gate 	int msglen;
60*0Sstevel@tonic-gate 	union T_primitives *pptr;
61*0Sstevel@tonic-gate 	struct _ti_user *tiptr;
62*0Sstevel@tonic-gate 	int sv_errno;
63*0Sstevel@tonic-gate 	int didalloc;
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate 	trace3(TR_t_rcv, 0, fd, nbytes);
66*0Sstevel@tonic-gate 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL) {
67*0Sstevel@tonic-gate 		sv_errno = errno;
68*0Sstevel@tonic-gate 		trace3(TR_t_rcv, 1, fd, nbytes);
69*0Sstevel@tonic-gate 		errno = sv_errno;
70*0Sstevel@tonic-gate 		return (-1);
71*0Sstevel@tonic-gate 	}
72*0Sstevel@tonic-gate 	sig_mutex_lock(&tiptr->ti_lock);
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	if (tiptr->ti_servtype == T_CLTS) {
75*0Sstevel@tonic-gate 		t_errno = TNOTSUPPORT;
76*0Sstevel@tonic-gate 		sig_mutex_unlock(&tiptr->ti_lock);
77*0Sstevel@tonic-gate 		trace3(TR_t_rcv, 1, fd, nbytes);
78*0Sstevel@tonic-gate 		return (-1);
79*0Sstevel@tonic-gate 	}
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 	if (_T_IS_XTI(api_semantics)) {
82*0Sstevel@tonic-gate 		/*
83*0Sstevel@tonic-gate 		 * User level state verification only done for XTI
84*0Sstevel@tonic-gate 		 * because doing for TLI may break existing applications
85*0Sstevel@tonic-gate 		 */
86*0Sstevel@tonic-gate 		if (! (tiptr->ti_state == T_DATAXFER ||
87*0Sstevel@tonic-gate 			tiptr->ti_state == T_OUTREL)) {
88*0Sstevel@tonic-gate 			t_errno = TOUTSTATE;
89*0Sstevel@tonic-gate 			sig_mutex_unlock(&tiptr->ti_lock);
90*0Sstevel@tonic-gate 			trace3(TR_t_rcv, 1, fd, nbytes);
91*0Sstevel@tonic-gate 			return (-1);
92*0Sstevel@tonic-gate 		}
93*0Sstevel@tonic-gate 	}
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate 	/*
96*0Sstevel@tonic-gate 	 * Check in lookbuf for stuff
97*0Sstevel@tonic-gate 	 */
98*0Sstevel@tonic-gate 	if (tiptr->ti_lookcnt > 0) {
99*0Sstevel@tonic-gate 		/*
100*0Sstevel@tonic-gate 		 * Implied preference rules give priority to
101*0Sstevel@tonic-gate 		 * T_DISCON_IND over T_ORDREL_IND. Also certain errors like
102*0Sstevel@tonic-gate 		 * data received after T_ORDREL_IND or a duplicate T_ORDREL_IND
103*0Sstevel@tonic-gate 		 * after a T_ORDRELING have priority over TLOOK.
104*0Sstevel@tonic-gate 		 * This manifests in following code behavior.
105*0Sstevel@tonic-gate 		 *
106*0Sstevel@tonic-gate 		 * (1)  If something in lookbuf then check
107*0Sstevel@tonic-gate 		 *	the stream head also. This may result
108*0Sstevel@tonic-gate 		 *	in retuning a TLOOK error but only if there are
109*0Sstevel@tonic-gate 		 *	  - message at stream head but look buffer
110*0Sstevel@tonic-gate 		 *	    has a T_DISCON_IND event.
111*0Sstevel@tonic-gate 		 *	  - no messages are on the stream head
112*0Sstevel@tonic-gate 		 *
113*0Sstevel@tonic-gate 		 * (2)  If there are messages on the stream head and
114*0Sstevel@tonic-gate 		 *	all of them are T_ORDREL_IND(i.e. no message in
115*0Sstevel@tonic-gate 		 *	look buffer is T_DISCON_IND), there
116*0Sstevel@tonic-gate 		 *	could be data on stream head to be picked up and
117*0Sstevel@tonic-gate 		 *	we work on the stream head and not return TLOOK.
118*0Sstevel@tonic-gate 		 *	We remove the event on the stream head and queue it.
119*0Sstevel@tonic-gate 		 *
120*0Sstevel@tonic-gate 		 */
121*0Sstevel@tonic-gate 		do {
122*0Sstevel@tonic-gate 			retval = _ioctl(fd, I_NREAD, &msglen);
123*0Sstevel@tonic-gate 		} while (retval < 0 && errno == EINTR);
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 		if (retval < 0) {
126*0Sstevel@tonic-gate 			sv_errno = errno;
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 			t_errno = TSYSERR;
129*0Sstevel@tonic-gate 			sig_mutex_unlock(&tiptr->ti_lock);
130*0Sstevel@tonic-gate 			trace3(TR_t_rcv, 1, fd, nbytes);
131*0Sstevel@tonic-gate 			errno = sv_errno;
132*0Sstevel@tonic-gate 			return (-1);
133*0Sstevel@tonic-gate 		}
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 		if (retval > 0) {
136*0Sstevel@tonic-gate 			/*
137*0Sstevel@tonic-gate 			 * If any T_DISCON_IND event in look buffer
138*0Sstevel@tonic-gate 			 * list then return TLOOK. Else continue
139*0Sstevel@tonic-gate 			 * processing as what could be on the stream
140*0Sstevel@tonic-gate 			 * head might be a possible T_DISCON_IND (which
141*0Sstevel@tonic-gate 			 * would have priority over the T_ORDREL_INDs
142*0Sstevel@tonic-gate 			 * on the look buffer.)
143*0Sstevel@tonic-gate 			 */
144*0Sstevel@tonic-gate 			struct _ti_lookbufs *tlbs;
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate 			tlbs = &tiptr->ti_lookbufs;
147*0Sstevel@tonic-gate 			do {
148*0Sstevel@tonic-gate 				if (*((t_scalar_t *)tlbs->tl_lookcbuf)
149*0Sstevel@tonic-gate 				    == T_DISCON_IND) {
150*0Sstevel@tonic-gate 					t_errno = TLOOK;
151*0Sstevel@tonic-gate 					sig_mutex_unlock(&tiptr->ti_lock);
152*0Sstevel@tonic-gate 					trace3(TR_t_rcv, 1, fd, nbytes);
153*0Sstevel@tonic-gate 					return (-1);
154*0Sstevel@tonic-gate 				}
155*0Sstevel@tonic-gate 			} while ((tlbs = tlbs->tl_next) != NULL);
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 		} else {	/* retval == 0 */
158*0Sstevel@tonic-gate 			/*
159*0Sstevel@tonic-gate 			 * Nothing on stream head so whatever in
160*0Sstevel@tonic-gate 			 * look buffer has nothing that might override
161*0Sstevel@tonic-gate 			 * it.
162*0Sstevel@tonic-gate 			 */
163*0Sstevel@tonic-gate 			t_errno = TLOOK;
164*0Sstevel@tonic-gate 			sig_mutex_unlock(&tiptr->ti_lock);
165*0Sstevel@tonic-gate 			trace3(TR_t_rcv, 1, fd, nbytes);
166*0Sstevel@tonic-gate 			return (-1);
167*0Sstevel@tonic-gate 		}
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	/*
171*0Sstevel@tonic-gate 	 * Acquire ctlbuf for use in sending/receiving control part
172*0Sstevel@tonic-gate 	 * of the message.
173*0Sstevel@tonic-gate 	 */
174*0Sstevel@tonic-gate 	if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
175*0Sstevel@tonic-gate 		sv_errno = errno;
176*0Sstevel@tonic-gate 		sig_mutex_unlock(&tiptr->ti_lock);
177*0Sstevel@tonic-gate 		trace3(TR_t_rcv, 1, fd, nbytes);
178*0Sstevel@tonic-gate 		errno = sv_errno;
179*0Sstevel@tonic-gate 		return (-1);
180*0Sstevel@tonic-gate 	}
181*0Sstevel@tonic-gate 
182*0Sstevel@tonic-gate 	databuf.maxlen = nbytes;
183*0Sstevel@tonic-gate 	databuf.len = 0;
184*0Sstevel@tonic-gate 	databuf.buf = buf;
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	*flags = 0;
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 	/*
189*0Sstevel@tonic-gate 	 * This is a call that may block indefinitely so we drop the
190*0Sstevel@tonic-gate 	 * lock and allow signals in MT case here and reacquire it.
191*0Sstevel@tonic-gate 	 * Error case should roll back state changes done above
192*0Sstevel@tonic-gate 	 * (happens to be no state change here)
193*0Sstevel@tonic-gate 	 */
194*0Sstevel@tonic-gate 	sig_mutex_unlock(&tiptr->ti_lock);
195*0Sstevel@tonic-gate 	if ((retval = getmsg(fd, &ctlbuf, &databuf, &flg)) < 0) {
196*0Sstevel@tonic-gate 		if (errno == EAGAIN)
197*0Sstevel@tonic-gate 			t_errno = TNODATA;
198*0Sstevel@tonic-gate 		else
199*0Sstevel@tonic-gate 			t_errno = TSYSERR;
200*0Sstevel@tonic-gate 		sv_errno = errno;
201*0Sstevel@tonic-gate 		sig_mutex_lock(&tiptr->ti_lock);
202*0Sstevel@tonic-gate 		errno = sv_errno;
203*0Sstevel@tonic-gate 		goto err_out;
204*0Sstevel@tonic-gate 	}
205*0Sstevel@tonic-gate 	sig_mutex_lock(&tiptr->ti_lock);
206*0Sstevel@tonic-gate 
207*0Sstevel@tonic-gate 	assert((retval & MORECTL) == 0); /* MORECTL should not be on */
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 	if (databuf.len == -1) databuf.len = 0;
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate 	if (ctlbuf.len > 0) {
212*0Sstevel@tonic-gate 		if (ctlbuf.len < (int)sizeof (t_scalar_t)) {
213*0Sstevel@tonic-gate 			t_errno = TSYSERR;
214*0Sstevel@tonic-gate 			errno = EPROTO;
215*0Sstevel@tonic-gate 			goto err_out;
216*0Sstevel@tonic-gate 		}
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate 		pptr = (union T_primitives *)ctlbuf.buf;
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 		switch (pptr->type) {
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 		case T_EXDATA_IND:
223*0Sstevel@tonic-gate 			*flags |= T_EXPEDITED;
224*0Sstevel@tonic-gate 			if (retval > 0)
225*0Sstevel@tonic-gate 				tiptr->ti_flags |= EXPEDITED;
226*0Sstevel@tonic-gate 			/* FALLTHROUGH */
227*0Sstevel@tonic-gate 		case T_DATA_IND:
228*0Sstevel@tonic-gate 			/*
229*0Sstevel@tonic-gate 			 * Uses the fact T_DATA_IND and T_EXDATA_IND
230*0Sstevel@tonic-gate 			 * are same in size
231*0Sstevel@tonic-gate 			 */
232*0Sstevel@tonic-gate 			if ((ctlbuf.len < (int)sizeof (struct T_data_ind)) ||
233*0Sstevel@tonic-gate 			    (tiptr->ti_lookcnt > 0)) {
234*0Sstevel@tonic-gate 				/*
235*0Sstevel@tonic-gate 				 * ti_lookcnt > 0 implies data
236*0Sstevel@tonic-gate 				 * received after T_DISCON_IND or
237*0Sstevel@tonic-gate 				 * T_ORDREL_IND hence error
238*0Sstevel@tonic-gate 				 */
239*0Sstevel@tonic-gate 				t_errno = TSYSERR;
240*0Sstevel@tonic-gate 				errno = EPROTO;
241*0Sstevel@tonic-gate 				goto err_out;
242*0Sstevel@tonic-gate 			}
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate 			if ((pptr->data_ind.MORE_flag) || retval)
245*0Sstevel@tonic-gate 				*flags |= T_MORE;
246*0Sstevel@tonic-gate 			if ((pptr->data_ind.MORE_flag) && retval)
247*0Sstevel@tonic-gate 				tiptr->ti_flags |= MORE;
248*0Sstevel@tonic-gate 			/*
249*0Sstevel@tonic-gate 			 * No real state change on T_RCV event (noop)
250*0Sstevel@tonic-gate 			 *
251*0Sstevel@tonic-gate 			 * We invoke the macro only for error logging
252*0Sstevel@tonic-gate 			 * part of its capabilities when in a bad state.
253*0Sstevel@tonic-gate 			 */
254*0Sstevel@tonic-gate 			_T_TX_NEXTSTATE(T_RCV, tiptr,
255*0Sstevel@tonic-gate 					"t_rcv: invalid state event T_RCV");
256*0Sstevel@tonic-gate 			if (didalloc)
257*0Sstevel@tonic-gate 				free(ctlbuf.buf);
258*0Sstevel@tonic-gate 			else
259*0Sstevel@tonic-gate 				tiptr->ti_ctlbuf = ctlbuf.buf;
260*0Sstevel@tonic-gate 			sig_mutex_unlock(&tiptr->ti_lock);
261*0Sstevel@tonic-gate 			trace3(TR_t_rcv, 1, fd, nbytes);
262*0Sstevel@tonic-gate 			return (databuf.len);
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 		case T_ORDREL_IND:
265*0Sstevel@tonic-gate 			if (tiptr->ti_lookcnt > 0) {
266*0Sstevel@tonic-gate 				/*
267*0Sstevel@tonic-gate 				 * ti_lookcnt > 0 implies T_ORDREL_IND
268*0Sstevel@tonic-gate 				 * received after T_DISCON_IND or
269*0Sstevel@tonic-gate 				 * another T_ORDREL_IND hence error.
270*0Sstevel@tonic-gate 				 */
271*0Sstevel@tonic-gate 				t_errno = TSYSERR;
272*0Sstevel@tonic-gate 				errno = EPROTO;
273*0Sstevel@tonic-gate 				goto err_out;
274*0Sstevel@tonic-gate 			}
275*0Sstevel@tonic-gate 			/* FALLTHROUGH */
276*0Sstevel@tonic-gate 		case T_DISCON_IND:
277*0Sstevel@tonic-gate 			/*
278*0Sstevel@tonic-gate 			 * Post event (T_ORDREL_IND/T_DISCON_IND) to
279*0Sstevel@tonic-gate 			 * the lookbuffer list.
280*0Sstevel@tonic-gate 			 */
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate 			if (_t_register_lookevent(tiptr, databuf.buf,
283*0Sstevel@tonic-gate 					databuf.len,
284*0Sstevel@tonic-gate 					ctlbuf.buf, ctlbuf.len) < 0) {
285*0Sstevel@tonic-gate 				t_errno = TSYSERR;
286*0Sstevel@tonic-gate 				errno = ENOMEM;
287*0Sstevel@tonic-gate 				goto err_out;
288*0Sstevel@tonic-gate 			}
289*0Sstevel@tonic-gate 			/*
290*0Sstevel@tonic-gate 			 * We know that T_DISCON_IND is stored in
291*0Sstevel@tonic-gate 			 * last look buffer. If there is more data
292*0Sstevel@tonic-gate 			 * that follows, we try to append it to
293*0Sstevel@tonic-gate 			 * the same look buffer
294*0Sstevel@tonic-gate 			 */
295*0Sstevel@tonic-gate 			if (retval & MOREDATA) {
296*0Sstevel@tonic-gate 				ctlbuf.maxlen = 0; /* XXX why ? */
297*0Sstevel@tonic-gate 				ctlbuf.len = 0;
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate 				/*
300*0Sstevel@tonic-gate 				 * XXX Will break (-ve maxlen) for
301*0Sstevel@tonic-gate 				 * transport provider with unbounded
302*0Sstevel@tonic-gate 				 * T_DISCON_IND data part (-1).
303*0Sstevel@tonic-gate 				 */
304*0Sstevel@tonic-gate 				databuf.maxlen =
305*0Sstevel@tonic-gate 					tiptr->ti_rcvsize - databuf.len;
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate 				databuf.len = 0;
308*0Sstevel@tonic-gate 				databuf.buf =
309*0Sstevel@tonic-gate 					tiptr->ti_lookbufs.tl_lookdbuf +
310*0Sstevel@tonic-gate 					tiptr->ti_lookbufs.tl_lookdlen;
311*0Sstevel@tonic-gate 				*flags = 0;
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate 				/*
314*0Sstevel@tonic-gate 				 * Since MOREDATA was set, we assume
315*0Sstevel@tonic-gate 				 * that this getmsg will not block
316*0Sstevel@tonic-gate 				 * indefinitely
317*0Sstevel@tonic-gate 				 */
318*0Sstevel@tonic-gate 				do {
319*0Sstevel@tonic-gate 					retval = getmsg(fd, &ctlbuf,
320*0Sstevel@tonic-gate 							&databuf, &flg);
321*0Sstevel@tonic-gate 				} while (retval < 0 && errno == EINTR);
322*0Sstevel@tonic-gate 
323*0Sstevel@tonic-gate 				if (retval < 0) {
324*0Sstevel@tonic-gate 					t_errno = TSYSERR;
325*0Sstevel@tonic-gate 					goto err_out;
326*0Sstevel@tonic-gate 				}
327*0Sstevel@tonic-gate 				if (databuf.len == -1) databuf.len = 0;
328*0Sstevel@tonic-gate 				if (retval > 0) {
329*0Sstevel@tonic-gate 					/* MORECTL should not be on */
330*0Sstevel@tonic-gate 					assert((retval & MORECTL) == 0);
331*0Sstevel@tonic-gate 					/*
332*0Sstevel@tonic-gate 					 * XXX - Why ?
333*0Sstevel@tonic-gate 					 * No support for unbounded data
334*0Sstevel@tonic-gate 					 * on T_DISCON_IND ?
335*0Sstevel@tonic-gate 					 */
336*0Sstevel@tonic-gate 					t_errno = TSYSERR;
337*0Sstevel@tonic-gate 					errno = EPROTO;
338*0Sstevel@tonic-gate 					goto err_out;
339*0Sstevel@tonic-gate 				}
340*0Sstevel@tonic-gate 				tiptr->ti_lookbufs.tl_lookdlen +=
341*0Sstevel@tonic-gate 					databuf.len;
342*0Sstevel@tonic-gate 			}
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 			t_errno = TLOOK;
345*0Sstevel@tonic-gate 			goto err_out;
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate 		default:
348*0Sstevel@tonic-gate 			break;
349*0Sstevel@tonic-gate 		}
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 		t_errno = TSYSERR;
352*0Sstevel@tonic-gate 		errno = EPROTO;
353*0Sstevel@tonic-gate 		goto err_out;
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 	} else {		/* else for "if (ctlbuf.len > 0)" */
356*0Sstevel@tonic-gate 		if (!retval && (tiptr->ti_flags & MORE)) {
357*0Sstevel@tonic-gate 			*flags |= T_MORE;
358*0Sstevel@tonic-gate 			tiptr->ti_flags &= ~MORE;
359*0Sstevel@tonic-gate 		}
360*0Sstevel@tonic-gate 		if (retval & MOREDATA)
361*0Sstevel@tonic-gate 			*flags |= T_MORE;
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate 		/*
364*0Sstevel@tonic-gate 		 * If inside an ETSDU, set expedited flag and turn
365*0Sstevel@tonic-gate 		 * of internal version when reach end of "ETIDU".
366*0Sstevel@tonic-gate 		 */
367*0Sstevel@tonic-gate 		if (tiptr->ti_flags & EXPEDITED) {
368*0Sstevel@tonic-gate 			*flags |= T_EXPEDITED;
369*0Sstevel@tonic-gate 			if (!retval)
370*0Sstevel@tonic-gate 				tiptr->ti_flags &= ~EXPEDITED;
371*0Sstevel@tonic-gate 		}
372*0Sstevel@tonic-gate 
373*0Sstevel@tonic-gate 		/*
374*0Sstevel@tonic-gate 		 * No real state change on T_RCV events (It is a NOOP)
375*0Sstevel@tonic-gate 		 *
376*0Sstevel@tonic-gate 		 * We invoke the macro only for error logging
377*0Sstevel@tonic-gate 		 * part of its capabilities when in a bad state.
378*0Sstevel@tonic-gate 		 */
379*0Sstevel@tonic-gate 		_T_TX_NEXTSTATE(T_RCV, tiptr,
380*0Sstevel@tonic-gate 			"t_rcv: state invalid T_RCV event");
381*0Sstevel@tonic-gate 		if (didalloc)
382*0Sstevel@tonic-gate 			free(ctlbuf.buf);
383*0Sstevel@tonic-gate 		else
384*0Sstevel@tonic-gate 			tiptr->ti_ctlbuf = ctlbuf.buf;
385*0Sstevel@tonic-gate 		sig_mutex_unlock(&tiptr->ti_lock);
386*0Sstevel@tonic-gate 		trace3(TR_t_rcv, 1, fd, nbytes);
387*0Sstevel@tonic-gate 		return (databuf.len);
388*0Sstevel@tonic-gate 	}
389*0Sstevel@tonic-gate 	/* NOTREACHED */
390*0Sstevel@tonic-gate 
391*0Sstevel@tonic-gate err_out:
392*0Sstevel@tonic-gate 	sv_errno = errno;
393*0Sstevel@tonic-gate 	if (didalloc)
394*0Sstevel@tonic-gate 		free(ctlbuf.buf);
395*0Sstevel@tonic-gate 	else
396*0Sstevel@tonic-gate 		tiptr->ti_ctlbuf = ctlbuf.buf;
397*0Sstevel@tonic-gate 	sig_mutex_unlock(&tiptr->ti_lock);
398*0Sstevel@tonic-gate 
399*0Sstevel@tonic-gate 	trace3(TR_t_rcv, 1, fd, nbytes);
400*0Sstevel@tonic-gate 	errno = sv_errno;
401*0Sstevel@tonic-gate 	return (-1);
402*0Sstevel@tonic-gate }
403