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 #include "mt.h" 29 #include "rpc_mt.h" 30 #include <stdio.h> 31 #include <rpc/rpc.h> 32 #include <errno.h> 33 #include <tiuser.h> 34 #include <string.h> 35 #include <stropts.h> 36 #include <netinet/tcp.h> 37 #include <stdlib.h> 38 39 #define MAXOPTSIZE 64 40 41 int 42 __td_setnodelay(int fd) 43 { 44 int rval = 0; 45 static mutex_t td_opt_lock = DEFAULTMUTEX; 46 static struct t_optmgmt t_optreq, t_optret; 47 int state; 48 49 50 /* VARIABLES PROTECTED BY td_opt_lock: t_optreq, t_optret */ 51 52 if ((state = t_getstate(fd)) == -1) 53 return (-1); 54 55 (void) mutex_lock(&td_opt_lock); 56 if ((state == T_IDLE) && (t_optreq.flags != T_NEGOTIATE)) { 57 int i = 1; 58 struct opthdr *opt; 59 60 t_optreq.flags = T_NEGOTIATE; 61 t_optreq.opt.maxlen = MAXOPTSIZE; 62 t_optreq.opt.buf = malloc(MAXOPTSIZE); 63 if (t_optreq.opt.buf == NULL) { 64 (void) mutex_unlock(&td_opt_lock); 65 t_errno = TSYSERR; 66 return (-1); 67 } 68 /* LINTED pointer cast */ 69 opt = (struct opthdr *)(t_optreq.opt.buf); 70 opt->name = TCP_NODELAY; 71 opt->len = 4; 72 opt->level = IPPROTO_TCP; 73 (void) memcpy((caddr_t)(t_optreq.opt.buf + 74 sizeof (struct opthdr)), &i, sizeof (int)); 75 t_optreq.opt.len = (int)(sizeof (struct opthdr) + 76 sizeof (int)); 77 78 t_optret.opt.maxlen = MAXOPTSIZE; 79 t_optret.opt.len = 0; 80 t_optret.opt.buf = malloc(MAXOPTSIZE); 81 if (t_optret.opt.buf == NULL) { 82 (void) mutex_unlock(&td_opt_lock); 83 free(t_optreq.opt.buf); 84 t_errno = TSYSERR; 85 return (-1); 86 } 87 } 88 89 if (state == T_IDLE) 90 rval = t_optmgmt(fd, &t_optreq, &t_optret); 91 92 (void) mutex_unlock(&td_opt_lock); 93 return (rval); 94 } 95