--- ./lib/util.h	2002/10/29 17:36:33	1.1
+++ ./lib/util.h	2002/11/06 12:53:59
@@ -77,8 +77,13 @@
  * set/getsockopt wrappers for SO_RCVBUF and SO_SNDBUF; TCP_MAXSEG
  * socket.c
  * ------------------------------------------------------------------- */
-int setsock_tcp_windowsize( int inSock, int inTCPWin );
-int getsock_tcp_windowsize( int inSock );
+typedef enum ServerMode {
+    kMode_Server,
+    kMode_Client,
+    kMode_Unknown
+} role_t;
+int sethalfsock_tcp_buffersize( int inSock, int inTCPWin, role_t dir);
+int gethalfsock_tcp_buffersize( int inSock, role_t dir);
 
 void setsock_tcp_mss( int inSock, int inTCPWin );
 int  getsock_tcp_mss( int inSock );
--- ./lib/tcp_window_size.c	2002/10/29 17:36:33	1.1
+++ ./lib/tcp_window_size.c	2002/11/06 18:00:38
@@ -70,8 +70,9 @@
  * returns -1 on error, 0 on no error.
  * ------------------------------------------------------------------- */
 
-int setsock_tcp_windowsize( int inSock, int inTCPWin ) {
+int sethalfsock_tcp_buffersize( int inSock, int inTCPWin, role_t dir ) {
 #ifdef SO_SNDBUF
+    int so_direction = (dir == kMode_Client ? SO_SNDBUF : SO_RCVBUF);
     int rc;
     int newTCPWin;
 
@@ -117,21 +118,11 @@
         }
 #endif /* TCP_RFC1323 */
 
-        /* receive buffer -- set
+        /* send or receive buffer -- set
          * note: results are verified after connect() or listen(),
          * since some OS's don't show the corrected value until then. */
         newTCPWin = inTCPWin;
-        rc = setsockopt( inSock, SOL_SOCKET, SO_RCVBUF,
-                         (char*) &newTCPWin, sizeof( newTCPWin ));
-        if ( rc < 0 ) {
-            return rc;
-        }
-
-        /* send buffer -- set
-         * note: results are verified after connect() or listen(),
-         * since some OS's don't show the corrected value until then. */
-        newTCPWin = inTCPWin;
-        rc = setsockopt( inSock, SOL_SOCKET, SO_SNDBUF,
+        rc = setsockopt( inSock, SOL_SOCKET, so_direction,
                          (char*) &newTCPWin, sizeof( newTCPWin ));
         if ( rc < 0 ) {
             return rc;
@@ -140,17 +131,19 @@
 #endif /* SO_SNDBUF */
 
     return 0;
-} /* end setsock_tcp_windowsize */
+} /* end sethalfsock_tcp_buffersize */
 
 /* -------------------------------------------------------------------
  * returns the TCP window size (on the sending buffer, SO_SNDBUF),
  * or -1 on error.
  * ------------------------------------------------------------------- */
 
-int getsock_tcp_windowsize( int inSock ) {
+int gethalfsock_tcp_buffersize( int inSock, role_t dir ) {
     int theTCPWin = 0;
 
 #ifdef SO_SNDBUF
+    int so_direction = (dir == kMode_Client ? SO_SNDBUF : SO_RCVBUF);
+
     int rc;
     Socklen_t len;
     int mySock = inSock;
@@ -163,9 +156,9 @@
 
     assert( mySock >= 0 );
 
-    /* send buffer -- query for buffer size */
+    /* send or receive buffer -- query for buffer size */
     len = sizeof( theTCPWin );
-    rc = getsockopt( mySock, SOL_SOCKET, SO_SNDBUF,
+    rc = getsockopt( mySock, SOL_SOCKET, so_direction,
                      (char*) &theTCPWin, &len );
     if ( rc < 0 ) {
         return rc;
@@ -175,10 +168,10 @@
         /* we allocated our own socket, so deallocate it */
         close( mySock );
     }
-#endif
 
     return theTCPWin;
-} /* end getsock_tcp_windowsize */
+#endif
+} /* end gethalfsock_tcp_buffersize */
 
 #ifdef __cplusplus
 } /* end extern "C" */
--- ./src/PerfSocket.cpp	2002/10/29 17:36:33	1.1
+++ ./src/PerfSocket.cpp	2002/11/06 18:03:55
@@ -406,7 +406,7 @@
 void PerfSocket::ReportWindowSize( void ) {
     // sReporting already locked from ReportClient/ServerSettings
 
-    int win = getsock_tcp_windowsize( mSock );
+    int win = gethalfsock_tcp_buffersize( mSock, gSettings->GetServerMode());
     int win_requested = gSettings->GetTCPWindowSize();
 
     char window[ 32 ];
@@ -512,6 +512,14 @@
  * ------------------------------------------------------------------- */
 
 void PerfSocket::SetSocketOptions( void ) {
+  // set the TCP window size (socket buffer sizes)
+  // also the UDP buffer size
+  // must occur before call to accept() for large window sizes
+#ifdef SO_SNDBUF
+  sethalfsock_tcp_buffersize( mSock, gSettings->GetTCPWindowSize(),
+			      gSettings->GetServerMode());
+#endif
+
 #ifndef WIN32
 #ifdef IP_TOS
 
--- ./src/PerfSocket_TCP.cpp	2002/10/29 17:36:33	1.1
+++ ./src/PerfSocket_TCP.cpp	2002/10/30 14:30:36
@@ -241,7 +241,7 @@
     InitTransfer();
     double fract = 0.0;
     mStartTime.setnow();
-    long  endSize =getsock_tcp_windowsize(mSock), startSize=endSize, loopLen =0, prevLen =0;
+    long  endSize =gethalfsock_tcp_buffersize(mSock, kMode_Client), startSize=endSize, loopLen =0, prevLen =0;
     Timestamp prevTime;
     prevTime.setnow();
 
@@ -312,10 +312,10 @@
             mSock = -1;
             Connect(gSettings->GetHost(),gSettings->GetLocalhost());
             mBuf[0] = 'a';
-            if ( setsock_tcp_windowsize(mSock,endSize) == -1 ) {
+            if ( sethalfsock_tcp_buffersize(mSock,endSize, kMode_Client) == -1 ) {
                 printf(unable_to_change_win);
             }
-            if ( getsock_tcp_windowsize(mSock) != endSize ) {
+            if ( gethalfsock_tcp_buffersize(mSock, kMode_Client) != endSize ) {
                 printf(unable_to_change_win);
             }
             write( mSock, mBuf, mBufLen );
@@ -333,9 +333,9 @@
     printf( seperator_line);
     printf( opt_estimate);
     if ( loopLen > prevLen )
-        setsock_tcp_windowsize(mSock,endSize);
+        sethalfsock_tcp_buffersize(mSock,endSize, kMode_Client);
     else
-        setsock_tcp_windowsize(mSock,startSize);
+        sethalfsock_tcp_buffersize(mSock,startSize, kMode_Client);
 
     ReportWindowSize();
     printf( seperator_line );
--- ./src/Settings.hpp	2002/10/30 14:07:44	1.1
+++ ./src/Settings.hpp	2002/10/30 14:15:49
@@ -67,12 +67,14 @@
  * constants
  * ------------------------------------------------------------------- */
 
+#if 0 // transfered to util.h, because it's useful for everyone
 // server/client mode
 enum ServerMode {
     kMode_Server,
     kMode_Client,
     kMode_Unknown
 };
+#endif
 
 // protocol mode
 const bool kMode_UDP    = false;
