2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1992, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include "mt.h"
2N/A#include "rpc_mt.h"
2N/A#include <stdio.h>
2N/A#include <rpc/rpc.h>
2N/A#include <errno.h>
2N/A#include <tiuser.h>
2N/A#include <string.h>
2N/A#include <stropts.h>
2N/A#include <netinet/tcp.h>
2N/A#include <stdlib.h>
2N/A
2N/A#define MAXOPTSIZE 64
2N/A
2N/Aint
2N/A__td_setnodelay(int fd)
2N/A{
2N/A int rval = 0;
2N/A static mutex_t td_opt_lock = DEFAULTMUTEX;
2N/A static struct t_optmgmt t_optreq, t_optret;
2N/A int state;
2N/A
2N/A
2N/A /* VARIABLES PROTECTED BY td_opt_lock: t_optreq, t_optret */
2N/A
2N/A if ((state = t_getstate(fd)) == -1)
2N/A return (-1);
2N/A
2N/A (void) mutex_lock(&td_opt_lock);
2N/A if ((state == T_IDLE) && (t_optreq.flags != T_NEGOTIATE)) {
2N/A int i = 1;
2N/A struct opthdr *opt;
2N/A
2N/A t_optreq.flags = T_NEGOTIATE;
2N/A t_optreq.opt.maxlen = MAXOPTSIZE;
2N/A t_optreq.opt.buf = malloc(MAXOPTSIZE);
2N/A if (t_optreq.opt.buf == NULL) {
2N/A (void) mutex_unlock(&td_opt_lock);
2N/A t_errno = TSYSERR;
2N/A return (-1);
2N/A }
2N/A opt = (struct opthdr *)(t_optreq.opt.buf);
2N/A opt->name = TCP_NODELAY;
2N/A opt->len = 4;
2N/A opt->level = IPPROTO_TCP;
2N/A (void) memcpy((caddr_t)t_optreq.opt.buf +
2N/A sizeof (struct opthdr), &i, sizeof (int));
2N/A t_optreq.opt.len = (int)(sizeof (struct opthdr) +
2N/A sizeof (int));
2N/A
2N/A t_optret.opt.maxlen = MAXOPTSIZE;
2N/A t_optret.opt.len = 0;
2N/A t_optret.opt.buf = malloc(MAXOPTSIZE);
2N/A if (t_optret.opt.buf == NULL) {
2N/A (void) mutex_unlock(&td_opt_lock);
2N/A free(t_optreq.opt.buf);
2N/A t_errno = TSYSERR;
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A if (state == T_IDLE)
2N/A rval = t_optmgmt(fd, &t_optreq, &t_optret);
2N/A
2N/A (void) mutex_unlock(&td_opt_lock);
2N/A return (rval);
2N/A}