xref: /illumos-gate/usr/src/lib/libnsl/nsl/t_sndrel.c (revision 86d949f9497332fe19be6b5d711d265eb957439f)
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 /*
32  * t_sndrel.c and t_sndreldata.c are very similar and contain common code.
33  * Any changes to either of them should be reviewed to see whether they
34  * are applicable to the other file.
35  */
36 #include "mt.h"
37 #include <errno.h>
38 #include <stropts.h>
39 #include <sys/stream.h>
40 #define	_SUN_TPI_VERSION 2
41 #include <sys/tihdr.h>
42 #include <sys/timod.h>
43 #include <xti.h>
44 #include "tx.h"
45 
46 int
47 _tx_sndrel(int fd, int api_semantics)
48 {
49 	struct T_ordrel_req orreq;
50 	struct strbuf ctlbuf;
51 	struct _ti_user *tiptr;
52 
53 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
54 		return (-1);
55 	sig_mutex_lock(&tiptr->ti_lock);
56 
57 	if (tiptr->ti_servtype != T_COTS_ORD) {
58 		t_errno = TNOTSUPPORT;
59 		sig_mutex_unlock(&tiptr->ti_lock);
60 		return (-1);
61 	}
62 
63 	if (_T_IS_XTI(api_semantics)) {
64 		/*
65 		 * User level state verification only done for XTI
66 		 * because doing for TLI may break existing applications
67 		 */
68 		if (!(tiptr->ti_state == T_DATAXFER ||
69 		    tiptr->ti_state == T_INREL)) {
70 			t_errno = TOUTSTATE;
71 			sig_mutex_unlock(&tiptr->ti_lock);
72 			return (-1);
73 		}
74 
75 		if (_t_look_locked(fd, tiptr, 0,
76 		    api_semantics) == T_DISCONNECT) {
77 			t_errno = TLOOK;
78 			sig_mutex_unlock(&tiptr->ti_lock);
79 			return (-1);
80 		}
81 
82 	}
83 
84 	orreq.PRIM_type = T_ORDREL_REQ;
85 	ctlbuf.maxlen = (int)sizeof (struct T_ordrel_req);
86 	ctlbuf.len = (int)sizeof (struct T_ordrel_req);
87 	ctlbuf.buf = (caddr_t)&orreq;
88 
89 	/*
90 	 * Calls to send data (write or putmsg) can potentially
91 	 * block, for MT case, we drop the lock and enable signals here
92 	 * and acquire it back
93 	 */
94 	sig_mutex_unlock(&tiptr->ti_lock);
95 	if (putmsg(fd, &ctlbuf, NULL, 0) < 0) {
96 		if (errno == EAGAIN)
97 			t_errno = TFLOW;
98 		else
99 			t_errno = TSYSERR;
100 		return (-1);
101 	}
102 	sig_mutex_lock(&tiptr->ti_lock);
103 	_T_TX_NEXTSTATE(T_SNDREL, tiptr,
104 				"t_sndrel: invalid state on event T_SNDREL");
105 	sig_mutex_unlock(&tiptr->ti_lock);
106 	return (0);
107 }
108