xref: /titanic_52/usr/src/lib/libnsl/nsl/t_sndrel.c (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
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 
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
24 /*	  All Rights Reserved  	*/
25 
26 /*
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.4 */
32 
33 /*
34  * t_sndrel.c and t_sndreldata.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.
37  */
38 #include "mt.h"
39 #include <errno.h>
40 #include <stropts.h>
41 #include <sys/stream.h>
42 #define	_SUN_TPI_VERSION 2
43 #include <sys/tihdr.h>
44 #include <sys/timod.h>
45 #include <xti.h>
46 #include "tx.h"
47 
48 int
49 _tx_sndrel(int fd, int api_semantics)
50 {
51 	struct T_ordrel_req orreq;
52 	struct strbuf ctlbuf;
53 	struct _ti_user *tiptr;
54 
55 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
56 		return (-1);
57 	sig_mutex_lock(&tiptr->ti_lock);
58 
59 	if (tiptr->ti_servtype != T_COTS_ORD) {
60 		t_errno = TNOTSUPPORT;
61 		sig_mutex_unlock(&tiptr->ti_lock);
62 		return (-1);
63 	}
64 
65 	if (_T_IS_XTI(api_semantics)) {
66 		/*
67 		 * User level state verification only done for XTI
68 		 * because doing for TLI may break existing applications
69 		 */
70 		if (!(tiptr->ti_state == T_DATAXFER ||
71 		    tiptr->ti_state == T_INREL)) {
72 			t_errno = TOUTSTATE;
73 			sig_mutex_unlock(&tiptr->ti_lock);
74 			return (-1);
75 		}
76 
77 		if (_t_look_locked(fd, tiptr, 0,
78 		    api_semantics) == T_DISCONNECT) {
79 			t_errno = TLOOK;
80 			sig_mutex_unlock(&tiptr->ti_lock);
81 			return (-1);
82 		}
83 
84 	}
85 
86 	orreq.PRIM_type = T_ORDREL_REQ;
87 	ctlbuf.maxlen = (int)sizeof (struct T_ordrel_req);
88 	ctlbuf.len = (int)sizeof (struct T_ordrel_req);
89 	ctlbuf.buf = (caddr_t)&orreq;
90 
91 	/*
92 	 * Calls to send data (write or putmsg) can potentially
93 	 * block, for MT case, we drop the lock and enable signals here
94 	 * and acquire it back
95 	 */
96 	sig_mutex_unlock(&tiptr->ti_lock);
97 	if (putmsg(fd, &ctlbuf, NULL, 0) < 0) {
98 		if (errno == EAGAIN)
99 			t_errno = TFLOW;
100 		else
101 			t_errno = TSYSERR;
102 		return (-1);
103 	}
104 	sig_mutex_lock(&tiptr->ti_lock);
105 	_T_TX_NEXTSTATE(T_SNDREL, tiptr,
106 				"t_sndrel: invalid state on event T_SNDREL");
107 	sig_mutex_unlock(&tiptr->ti_lock);
108 	return (0);
109 }
110