xref: /titanic_44/usr/src/lib/libnsl/nsl/t_rcvconnect.c (revision 09f67678c27dda8a89f87f1f408a87dd49ceb0e1)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 1993-2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.3 */
33 
34 #include "mt.h"
35 #include <stdlib.h>
36 #include <errno.h>
37 #include <stropts.h>
38 #include <rpc/trace.h>
39 #include <xti.h>
40 #include <sys/timod.h>
41 #include "tx.h"
42 
43 
44 /*
45  * t_rcvconnect() is documented to be only called with non-blocking
46  * endpoints for asynchronous connection establishment. However, the
47  * direction taken by XTI is to allow it to be called if t_connect()
48  * fails with TSYSERR/EINTR and state is T_OUTCON (i.e. T_CONN_REQ was
49  * sent down). This implies that an interrupted synchronous connection
50  * establishment which was interrupted after connection request was transmitted
51  * can now be completed by calling t_rcvconnect()
52  */
53 int
54 _tx_rcvconnect(int fd, struct t_call *call, int api_semantics)
55 {
56 	struct _ti_user *tiptr;
57 	int retval, sv_errno;
58 	struct strbuf ctlbuf;
59 	int didalloc;
60 
61 	trace2(TR_t_rcvconnect, 0, fd);
62 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL) {
63 		sv_errno = errno;
64 		trace2(TR_t_rcvconnect, 1, fd);
65 		errno = sv_errno;
66 		return (-1);
67 	}
68 
69 	sig_mutex_lock(&tiptr->ti_lock);
70 
71 	if (_T_IS_XTI(api_semantics)) {
72 		/*
73 		 * User level state verification only done for XTI
74 		 * because doing for TLI may break existing applications
75 		 */
76 		if (tiptr->ti_state != T_OUTCON) {
77 			t_errno = TOUTSTATE;
78 			sig_mutex_unlock(&tiptr->ti_lock);
79 			trace2(TR_t_rcvconnect, 1, fd);
80 			return (-1);
81 		}
82 	}
83 
84 	/*
85 	 * Acquire ctlbuf for use in sending/receiving control part
86 	 * of the message.
87 	 */
88 	if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
89 		sv_errno = errno;
90 		sig_mutex_unlock(&tiptr->ti_lock);
91 		trace2(TR_t_rcvconnect, 1, fd);
92 		errno = sv_errno;
93 		return (-1);
94 	}
95 
96 	retval = _t_rcv_conn_con(tiptr, call, &ctlbuf, api_semantics);
97 	if (retval == 0 || t_errno == TBUFOVFLW) {
98 		_T_TX_NEXTSTATE(T_RCVCONNECT, tiptr,
99 			"t_rcvconnect: Invalid state on event T_RCVCONNECT");
100 		/*
101 		 * Update attributes which may have been negotiated during
102 		 * connection establishment for protocols where we suspect
103 		 * such negotiation is likely (e.g. OSI). We do not do it for
104 		 * all endpoints for performance reasons. Also, this code is
105 		 * deliberately done after user level state changes so even
106 		 * the (unlikely) failure case reflects a connected endpoint.
107 		 */
108 		if (tiptr->ti_tsdusize != 0)
109 			if (_t_do_postconn_sync(fd, tiptr) < 0)
110 				retval = -1;
111 	}
112 	sv_errno = errno;
113 	if (didalloc)
114 		free(ctlbuf.buf);
115 	else
116 		tiptr->ti_ctlbuf = ctlbuf.buf;
117 	sig_mutex_unlock(&tiptr->ti_lock);
118 	trace2(TR_t_rcvconnect, 1, fd);
119 	errno = sv_errno;
120 	return (retval);
121 }
122