#include "mt.h"
#include "rpc_mt.h"
#include <stdio.h>
#include <rpc/rpc.h>
#include <errno.h>
#include <tiuser.h>
#include <string.h>
#include <stropts.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#define MAXOPTSIZE 64
int
__td_setnodelay(int fd)
{
int rval = 0;
static mutex_t td_opt_lock = DEFAULTMUTEX;
static struct t_optmgmt t_optreq, t_optret;
int state;
if ((state = t_getstate(fd)) == -1)
return (-1);
(void) mutex_lock(&td_opt_lock);
if ((state == T_IDLE) && (t_optreq.flags != T_NEGOTIATE)) {
int i = 1;
struct opthdr *opt;
t_optreq.flags = T_NEGOTIATE;
t_optreq.opt.maxlen = MAXOPTSIZE;
t_optreq.opt.buf = malloc(MAXOPTSIZE);
if (t_optreq.opt.buf == NULL) {
(void) mutex_unlock(&td_opt_lock);
t_errno = TSYSERR;
return (-1);
}
opt = (struct opthdr *)(t_optreq.opt.buf);
opt->name = TCP_NODELAY;
opt->len = 4;
opt->level = IPPROTO_TCP;
(void) memcpy((caddr_t)(t_optreq.opt.buf +
sizeof (struct opthdr)), &i, sizeof (int));
t_optreq.opt.len = (int)(sizeof (struct opthdr) +
sizeof (int));
t_optret.opt.maxlen = MAXOPTSIZE;
t_optret.opt.len = 0;
t_optret.opt.buf = malloc(MAXOPTSIZE);
if (t_optret.opt.buf == NULL) {
(void) mutex_unlock(&td_opt_lock);
free(t_optreq.opt.buf);
t_errno = TSYSERR;
return (-1);
}
}
if (state == T_IDLE)
rval = t_optmgmt(fd, &t_optreq, &t_optret);
(void) mutex_unlock(&td_opt_lock);
return (rval);
}