2009-10-19 22:35:18 +00:00
|
|
|
/*---------------------------------------------------------------
|
|
|
|
* Copyright (c) 1999,2000,2001,2002,2003
|
|
|
|
* The Board of Trustees of the University of Illinois
|
|
|
|
* All Rights Reserved.
|
|
|
|
*---------------------------------------------------------------
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software (Iperf) and associated
|
|
|
|
* documentation files (the "Software"), to deal in the Software
|
|
|
|
* without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute,
|
|
|
|
* sublicense, and/or sell copies of the Software, and to permit
|
2009-02-24 06:22:58 +00:00
|
|
|
* persons to whom the Software is furnished to do
|
2009-10-19 22:35:18 +00:00
|
|
|
* so, subject to the following conditions:
|
2009-02-24 06:22:58 +00:00
|
|
|
*
|
|
|
|
*
|
2009-10-19 22:35:18 +00:00
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and
|
|
|
|
* the following disclaimers.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimers in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Neither the names of the University of Illinois, NCSA,
|
|
|
|
* nor the names of its contributors may be used to endorse
|
2009-02-24 06:22:58 +00:00
|
|
|
* or promote products derived from this Software without
|
2009-10-19 22:35:18 +00:00
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
2009-02-24 06:22:58 +00:00
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
2009-10-19 22:35:18 +00:00
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-02-24 06:22:58 +00:00
|
|
|
* ________________________________________________________________
|
2009-10-19 22:35:18 +00:00
|
|
|
* National Laboratory for Applied Network Research
|
|
|
|
* National Center for Supercomputing Applications
|
|
|
|
* University of Illinois at Urbana-Champaign
|
2009-02-24 06:22:58 +00:00
|
|
|
* http://www.ncsa.uiuc.edu
|
2009-10-19 22:35:18 +00:00
|
|
|
* ________________________________________________________________
|
2009-02-24 06:22:58 +00:00
|
|
|
*
|
|
|
|
* tcp_window_size.c
|
|
|
|
* by Mark Gates <mgates@nlanr.net>
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
* set/getsockopt
|
|
|
|
* ------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* imported into iperfjd branch: 3 Feb 2009 jdugan
|
|
|
|
*
|
|
|
|
* made variable names more sane
|
|
|
|
* removed some cruft
|
|
|
|
*/
|
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
#include <stdio.h>
|
2009-02-24 06:22:58 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
* If bufsize > 0, set the TCP window size (via the socket buffer
|
|
|
|
* sizes) for sock. Otherwise leave it as the system default.
|
|
|
|
*
|
|
|
|
* This must be called prior to calling listen() or connect() on
|
|
|
|
* the socket, for TCP window sizes > 64 KB to be effective.
|
|
|
|
*
|
|
|
|
* This now works on UNICOS also, by setting TCP_WINSHIFT.
|
|
|
|
* This now works on AIX, by enabling RFC1323.
|
|
|
|
* returns -1 on error, 0 on no error.
|
2009-10-20 16:56:02 +00:00
|
|
|
* -------------------------------------------------------------------
|
|
|
|
*/
|
2009-02-24 06:22:58 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
int
|
|
|
|
set_tcp_windowsize(int sock, int bufsize, int dir)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int newbufsize;
|
2009-10-19 22:35:18 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
assert(sock >= 0);
|
2009-10-19 22:35:18 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
if (bufsize > 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* note: results are verified after connect() or listen(), since
|
|
|
|
* some OS's don't show the corrected value until then.
|
|
|
|
*/
|
2010-07-23 20:46:58 +00:00
|
|
|
// printf("Setting TCP buffer to size: %d\n", bufsize);
|
2009-10-20 16:56:02 +00:00
|
|
|
newbufsize = bufsize;
|
2013-11-06 19:05:46 +00:00
|
|
|
rc = setsockopt(sock, SOL_SOCKET, dir, (char *) &newbufsize, sizeof(newbufsize));
|
2009-10-20 16:56:02 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
} else {
|
2010-07-23 20:46:58 +00:00
|
|
|
// printf(" Using default TCP buffer size and assuming OS will do autotuning\n");
|
2009-02-24 06:22:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-24 06:22:58 +00:00
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
* returns the TCP window size (on the sending buffer, SO_SNDBUF),
|
|
|
|
* or -1 on error.
|
|
|
|
* ------------------------------------------------------------------- */
|
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
int
|
|
|
|
get_tcp_windowsize(int sock, int dir)
|
|
|
|
{
|
|
|
|
int bufsize = 0;
|
2009-02-24 06:22:58 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
int rc;
|
|
|
|
socklen_t len;
|
2009-02-24 06:22:58 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
/* send buffer -- query for buffer size */
|
|
|
|
len = sizeof bufsize;
|
|
|
|
rc = getsockopt(sock, SOL_SOCKET, dir, (char *) &bufsize, &len);
|
2009-02-24 06:22:58 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
2009-02-24 06:22:58 +00:00
|
|
|
|
2009-10-20 16:56:02 +00:00
|
|
|
return bufsize;
|
|
|
|
}
|