xref: /titanic_44/usr/src/lib/libnsl/nsl/t_sndreldata.c (revision 4496171313bed39e96f21bc2f9faf2868e267ae3)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 /*
31  * t_sndrel.c and t_sndreldata.c are very similar and contain common code.
32  * Any changes to either of them should be reviewed to see whether they
33  * are applicable to the other file.
34  */
35 #include "mt.h"
36 #include <errno.h>
37 #include <stropts.h>
38 #include <sys/stream.h>
39 #define	_SUN_TPI_VERSION 2
40 #include <sys/tihdr.h>
41 #include <sys/timod.h>
42 #include <xti.h>
43 #include <assert.h>
44 #include "tx.h"
45 
46 int
47 _tx_sndreldata(int fd, struct t_discon *discon, int api_semantics)
48 {
49 	struct T_ordrel_req orreq;
50 	struct strbuf ctlbuf;
51 	struct _ti_user *tiptr;
52 
53 	assert(api_semantics == TX_XTI_XNS5_API);
54 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
55 		return (-1);
56 	sig_mutex_lock(&tiptr->ti_lock);
57 
58 	if (tiptr->ti_servtype != T_COTS_ORD) {
59 		t_errno = TNOTSUPPORT;
60 		sig_mutex_unlock(&tiptr->ti_lock);
61 		return (-1);
62 	}
63 
64 	if (!(tiptr->ti_state == T_DATAXFER ||
65 	    tiptr->ti_state == T_INREL)) {
66 		t_errno = TOUTSTATE;
67 		sig_mutex_unlock(&tiptr->ti_lock);
68 		return (-1);
69 	}
70 
71 	if (_t_look_locked(fd, tiptr, 0,
72 	    api_semantics) == T_DISCONNECT) {
73 		t_errno = TLOOK;
74 		sig_mutex_unlock(&tiptr->ti_lock);
75 		return (-1);
76 	}
77 
78 	/*
79 	 * Someday there could be transport providers that support T_ORDRELDATA
80 	 * Until that happens, this function returns TBADDATA if user data
81 	 * was specified. If no user data is specified, this function
82 	 * behaves as t_sndrel()
83 	 * Note: Currently only mOSI ("minimal OSI") provider is specified
84 	 * to use T_ORDRELDATA so probability of needing it is minimal.
85 	 */
86 
87 	if (discon && discon->udata.len) {
88 		t_errno = TBADDATA;
89 		sig_mutex_unlock(&tiptr->ti_lock);
90 		return (-1);
91 	}
92 
93 	orreq.PRIM_type = T_ORDREL_REQ;
94 	ctlbuf.maxlen = (int)sizeof (struct T_ordrel_req);
95 	ctlbuf.len = (int)sizeof (struct T_ordrel_req);
96 	ctlbuf.buf = (caddr_t)&orreq;
97 
98 	/*
99 	 * Calls to send data (write or putmsg) can potentially
100 	 * block, for MT case, we drop the lock and enable signals here
101 	 * and acquire it back
102 	 */
103 	sig_mutex_unlock(&tiptr->ti_lock);
104 	if (putmsg(fd, &ctlbuf, NULL, 0) < 0) {
105 		if (errno == EAGAIN)
106 			t_errno = TFLOW;
107 		else
108 			t_errno = TSYSERR;
109 		return (-1);
110 	}
111 	sig_mutex_lock(&tiptr->ti_lock);
112 	_T_TX_NEXTSTATE(T_SNDREL, tiptr,
113 			"t_sndreldata: invalid state on event T_SNDREL");
114 	sig_mutex_unlock(&tiptr->ti_lock);
115 	return (0);
116 }
117