#include "mt.h"
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stropts.h>
#include <sys/stream.h>
#define _SUN_TPI_VERSION 2
#include <sys/tihdr.h>
#include <sys/timod.h>
#include <xti.h>
#include <signal.h>
#include <syslog.h>
#include "tx.h"
int
_tx_unbind(int fd, int api_semantics)
{
struct _ti_user *tiptr;
sigset_t mask;
int sv_errno, retval, didalloc;
struct strbuf ctlbuf;
if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == NULL)
return (-1);
if (_T_IS_XTI(api_semantics)) {
if (tiptr->ti_state != T_IDLE) {
t_errno = TOUTSTATE;
return (-1);
}
}
(void) thr_sigsetmask(SIG_SETMASK, &fillset, &mask);
sig_mutex_lock(&tiptr->ti_lock);
if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
sv_errno = errno;
sig_mutex_unlock(&tiptr->ti_lock);
(void) thr_sigsetmask(SIG_SETMASK, &mask, NULL);
errno = sv_errno;
return (-1);
}
retval = _tx_unbind_locked(fd, tiptr, &ctlbuf);
sv_errno = errno;
if (didalloc)
free(ctlbuf.buf);
else
tiptr->ti_ctlbuf = ctlbuf.buf;
sig_mutex_unlock(&tiptr->ti_lock);
(void) thr_sigsetmask(SIG_SETMASK, &mask, NULL);
errno = sv_errno;
return (retval);
}
int
_tx_unbind_locked(int fd, struct _ti_user *tiptr, struct strbuf *ctlbufp)
{
struct T_unbind_req *unbind_reqp;
int retlen;
if (_t_is_event(fd, tiptr) < 0)
return (-1);
unbind_reqp = (struct T_unbind_req *)ctlbufp->buf;
unbind_reqp->PRIM_type = T_UNBIND_REQ;
if (_t_do_ioctl(fd, (char *)unbind_reqp,
(int)sizeof (struct T_unbind_req), TI_UNBIND, &retlen) < 0) {
goto err_out;
}
if (ioctl(fd, I_FLUSH, FLUSHRW) < 0) {
t_errno = TSYSERR;
goto err_out;
}
tiptr->ti_flags &= ~(MORE|EXPEDITED);
_T_TX_NEXTSTATE(T_UNBIND, tiptr,
"t_unbind: invalid state event T_UNBIND");
return (0);
err_out:
return (-1);
}