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