xref: /onnv-gate/usr/src/lib/libnsl/rpc/rpc_td.c (revision 132:e3f7eaf7dde4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*132Srobinson 
230Sstevel@tonic-gate /*
240Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include "mt.h"
310Sstevel@tonic-gate #include "rpc_mt.h"
320Sstevel@tonic-gate #include <stdio.h>
330Sstevel@tonic-gate #include <rpc/rpc.h>
340Sstevel@tonic-gate #include <errno.h>
350Sstevel@tonic-gate #include <tiuser.h>
360Sstevel@tonic-gate #include <string.h>
370Sstevel@tonic-gate #include <stropts.h>
380Sstevel@tonic-gate #include <netinet/tcp.h>
390Sstevel@tonic-gate #include <stdlib.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #define	MAXOPTSIZE 64
420Sstevel@tonic-gate 
430Sstevel@tonic-gate int
__td_setnodelay(int fd)44*132Srobinson __td_setnodelay(int fd)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate 	int rval = 0;
470Sstevel@tonic-gate 	static mutex_t td_opt_lock = DEFAULTMUTEX;
480Sstevel@tonic-gate 	static struct t_optmgmt t_optreq, t_optret;
490Sstevel@tonic-gate 	int state;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 	/* VARIABLES PROTECTED BY td_opt_lock: t_optreq, t_optret */
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	if ((state = t_getstate(fd)) == -1)
550Sstevel@tonic-gate 		return (-1);
560Sstevel@tonic-gate 
57*132Srobinson 	(void) mutex_lock(&td_opt_lock);
580Sstevel@tonic-gate 	if ((state == T_IDLE) && (t_optreq.flags != T_NEGOTIATE)) {
590Sstevel@tonic-gate 		int i = 1;
600Sstevel@tonic-gate 		struct opthdr *opt;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 		t_optreq.flags = T_NEGOTIATE;
630Sstevel@tonic-gate 		t_optreq.opt.maxlen = MAXOPTSIZE;
64*132Srobinson 		t_optreq.opt.buf = malloc(MAXOPTSIZE);
650Sstevel@tonic-gate 		if (t_optreq.opt.buf == NULL) {
66*132Srobinson 			(void) mutex_unlock(&td_opt_lock);
670Sstevel@tonic-gate 			t_errno = TSYSERR;
680Sstevel@tonic-gate 			return (-1);
690Sstevel@tonic-gate 		}
70*132Srobinson 		/* LINTED pointer cast */
710Sstevel@tonic-gate 		opt = (struct opthdr *)(t_optreq.opt.buf);
720Sstevel@tonic-gate 		opt->name = TCP_NODELAY;
730Sstevel@tonic-gate 		opt->len = 4;
740Sstevel@tonic-gate 		opt->level = IPPROTO_TCP;
750Sstevel@tonic-gate 		(void) memcpy((caddr_t)(t_optreq.opt.buf +
760Sstevel@tonic-gate 				sizeof (struct opthdr)), &i, sizeof (int));
770Sstevel@tonic-gate 		t_optreq.opt.len = (int)(sizeof (struct opthdr) +
780Sstevel@tonic-gate 						sizeof (int));
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 		t_optret.opt.maxlen = MAXOPTSIZE;
810Sstevel@tonic-gate 		t_optret.opt.len = 0;
82*132Srobinson 		t_optret.opt.buf = malloc(MAXOPTSIZE);
830Sstevel@tonic-gate 		if (t_optret.opt.buf == NULL) {
84*132Srobinson 			(void) mutex_unlock(&td_opt_lock);
850Sstevel@tonic-gate 			free(t_optreq.opt.buf);
860Sstevel@tonic-gate 			t_errno = TSYSERR;
870Sstevel@tonic-gate 			return (-1);
880Sstevel@tonic-gate 		}
890Sstevel@tonic-gate 	}
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	if (state == T_IDLE)
920Sstevel@tonic-gate 		rval = t_optmgmt(fd, &t_optreq, &t_optret);
930Sstevel@tonic-gate 
94*132Srobinson 	(void) mutex_unlock(&td_opt_lock);
950Sstevel@tonic-gate 	return (rval);
960Sstevel@tonic-gate }
97