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