]> sjero.net Git - iperf/blobdiff - src/Server.cpp
DCCP support for iperf
[iperf] / src / Server.cpp
index da7ef146fadca67c222dccf10879d4e2b1069f41..d7cd52ac730a78a71422511eb0717557995cf17d 100644 (file)
@@ -92,13 +92,13 @@ void Server::Sig_Int( int inSigno ) {
 }
 
 /* ------------------------------------------------------------------- 
- * Receieve data from the (connected) TCP/UDP socket. 
+ * Receive data from the (connected) socket.
  * Sends termination flag several times at the end. 
  * Does not close the socket. 
  * ------------------------------------------------------------------- */ 
 void Server::Run( void ) {
     long currLen; 
-    struct UDP_datagram* mBuf_UDP  = (struct UDP_datagram*) mBuf; 
+    struct dgram_record* dgram_rec  = (struct dgram_record*) mBuf;
 
     ReportStruct *reportstruct = NULL;
 
@@ -110,11 +110,11 @@ void Server::Run( void ) {
             // perform read 
             currLen = recv( mSettings->mSock, mBuf, mSettings->mBufLen, 0 ); 
         
-            if ( isUDP( mSettings ) ) {
+            if ( isPacketOriented( mSettings ) ) {
                 // read the datagram ID and sentTime out of the buffer 
-                reportstruct->packetID = ntohl( mBuf_UDP->id ); 
-                reportstruct->sentTime.tv_sec = ntohl( mBuf_UDP->tv_sec  );
-                reportstruct->sentTime.tv_usec = ntohl( mBuf_UDP->tv_usec ); 
+                reportstruct->packetID = ntohl( dgram_rec->id );
+                reportstruct->sentTime.tv_sec = ntohl( dgram_rec->tv_sec  );
+                reportstruct->sentTime.tv_usec = ntohl( dgram_rec->tv_usec );
             }
         
             reportstruct->packetLen = currLen;
@@ -124,6 +124,9 @@ void Server::Run( void ) {
             // the datagram ID should be correct, just negated 
             if ( reportstruct->packetID < 0 ) {
                 reportstruct->packetID = -reportstruct->packetID;
+                // Don't count the FIN message in connection-oriented protocols.
+                if (!isConnectionLess(mSettings))
+                   break;
                 currLen = -1; 
             }
             ReportPacket( mSettings->reporthdr, reportstruct );
@@ -133,11 +136,10 @@ void Server::Run( void ) {
         gettimeofday( &(reportstruct->packetTime), NULL );
         CloseReport( mSettings->reporthdr, reportstruct );
         
+        // send back an acknowledgement of the terminating datagram
         // send a acknowledgement back only if we're NOT receiving multicast 
-        if ( isUDP( mSettings ) && !isMulticast( mSettings ) ) {
-            // send back an acknowledgement of the terminating datagram 
-            write_UDP_AckFIN( ); 
-        }
+        if ( isPacketOriented( mSettings ) && !isMulticast( mSettings ) )
+            write_dgram_AckFin( );
     } else {
         FAIL(1, "Out of memory! Closing server thread\n", mSettings);
     }
@@ -158,7 +160,7 @@ void Server::Run( void ) {
  * termination datagrams, so re-transmit our AckFIN. 
  * ------------------------------------------------------------------- */ 
 
-void Server::write_UDP_AckFIN( ) {
+void Server::write_dgram_AckFin( ) {
 
     int rc; 
 
@@ -171,15 +173,15 @@ void Server::write_UDP_AckFIN( ) {
     while ( count < 10 ) {
         count++; 
 
-        UDP_datagram *UDP_Hdr;
+        dgram_record *dgram_rec;
         server_hdr *hdr;
 
-        UDP_Hdr = (UDP_datagram*) mBuf;
+        dgram_rec = (dgram_record*) mBuf;
 
-        if ( mSettings->mBufLen > (int) ( sizeof( UDP_datagram )
+        if ( mSettings->mBufLen > (int) ( sizeof( dgram_record )
                                           + sizeof( server_hdr ) ) ) {
             Transfer_Info *stats = GetReport( mSettings->reporthdr );
-            hdr = (server_hdr*) (UDP_Hdr+1);
+            hdr = (server_hdr*) (dgram_rec+1);
 
             hdr->flags        = htonl( HEADER_VERSION1 );
             hdr->total_len1   = htonl( (long) (stats->TotalLen >> 32) );
@@ -224,5 +226,3 @@ void Server::write_UDP_AckFIN( ) {
 
     fprintf( stderr, warn_ack_failed, mSettings->mSock, count ); 
 } 
-// end write_UDP_AckFIN 
-