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.7 */
36 #include <sys/timod.h>
37 #define _SUN_TPI_VERSION 2
38 #include <sys/tihdr.h>
47 * If a system call fails with EINTR after T_CONN_REQ is sent out,
48 * we change state for caller to continue with t_rcvconnect(). This
49 * semantics is not documented for TLI but is the direction taken with
50 * XTI so we adopt it. With this the call establishment is completed
51 * by calling t_rcvconnect() even for synchronous endpoints.
56 const struct t_call
*sndcall
,
57 struct t_call
*rcvcall
,
62 struct _ti_user
*tiptr
;
68 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == NULL
)
71 sig_mutex_lock(&tiptr
->ti_lock
);
72 if (_T_IS_XTI(api_semantics
)) {
74 * User level state verification only done for XTI
75 * because doing for TLI may break existing applications
77 if (tiptr
->ti_state
!= T_IDLE
) {
79 sig_mutex_unlock(&tiptr
->ti_lock
);
85 * Acquire ctlbuf for use in sending/receiving control part
88 if (_t_acquire_ctlbuf(tiptr
, &ctlbuf
, &didalloc
) < 0) {
90 sig_mutex_unlock(&tiptr
->ti_lock
);
95 * Block all signals until T_CONN_REQ sent and
96 * acked with T_OK_ACK/ERROR_ACK
98 (void) thr_sigsetmask(SIG_SETMASK
, &fillset
, &mask
);
99 if (_t_snd_conn_req(tiptr
, sndcall
, &ctlbuf
) < 0) {
101 (void) thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
104 * At the TPI level, the error returned in a T_ERROR_ACK
105 * received in response to a T_CONN_REQ for an attempt to
106 * establish a duplicate conection has changed to a
107 * new t_errno code introduced with XTI (ADDRBUSY).
108 * We need to adjust TLI error code to be same as before.
110 if (_T_IS_TLI(api_semantics
) && t_errno
== TADDRBUSY
)
116 (void) thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
118 if ((fctlflg
= fcntl(fd
, F_GETFL
, 0)) < 0) {
123 if (fctlflg
& (O_NDELAY
| O_NONBLOCK
)) {
124 _T_TX_NEXTSTATE(T_CONNECT2
, tiptr
,
125 "t_connect: invalid state event T_CONNECT2");
131 * Note: The following call to _t_rcv_conn_con blocks awaiting
132 * T_CONN_CON from remote client. Therefore it drops the
133 * tiptr->lock during the call (and reacquires it)
135 if (_t_rcv_conn_con(tiptr
, rcvcall
, &ctlbuf
, api_semantics
) < 0) {
136 if ((t_errno
== TSYSERR
&& errno
== EINTR
) ||
138 _T_TX_NEXTSTATE(T_CONNECT2
, tiptr
,
139 "t_connect: invalid state event T_CONNECT2");
140 } else if (t_errno
== TBUFOVFLW
) {
141 _T_TX_NEXTSTATE(T_CONNECT1
, tiptr
,
142 "t_connect: invalid state event T_CONNECT1");
146 _T_TX_NEXTSTATE(T_CONNECT1
, tiptr
,
147 "t_connect: invalid state event T_CONNECT1");
149 * Update attributes which may have been negotiated during
150 * connection establishment for protocols where we suspect
151 * such negotiation is likely (e.g. OSI). We do not do it for
152 * all endpoints for performance reasons. Also, this code is
153 * deliberately done after user level state changes so even
154 * the (unlikely) failure case reflects a connected endpoint.
156 if (tiptr
->ti_tsdusize
!= 0) {
157 if (_t_do_postconn_sync(fd
, tiptr
) < 0)
165 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
166 sig_mutex_unlock(&tiptr
->ti_lock
);
174 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
175 sig_mutex_unlock(&tiptr
->ti_lock
);